ges: Output otio formatter loading issues in debug logs

Instead of spamming the terminal with a python traceback

Fixes https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/issues/107

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/173>
This commit is contained in:
Thibault Saunier 2020-05-04 10:35:25 -04:00 committed by GStreamer Merge Bot
parent 5c05b4942e
commit 154816365f
2 changed files with 42 additions and 28 deletions

View file

@ -617,7 +617,26 @@ load_python_formatters (void)
Py_XDECREF (code); Py_XDECREF (code);
Py_XDECREF (res); Py_XDECREF (res);
if (PyErr_Occurred ()) { if (PyErr_Occurred ()) {
PyErr_Print (); PyObject *exception_backtrace;
PyObject *exception_type;
PyObject *exception_value, *exception_value_repr, *exception_value_str;
PyErr_Fetch (&exception_type, &exception_value, &exception_backtrace);
PyErr_NormalizeException (&exception_type, &exception_value,
&exception_backtrace);
exception_value_repr = PyObject_Repr (exception_value);
exception_value_str =
PyUnicode_AsEncodedString (exception_value_repr, "utf-8", "Error ~");
GST_INFO ("Could not load OpenTimelineIO formatter: %s",
PyBytes_AS_STRING (exception_value_str));
Py_XDECREF (exception_type);
Py_XDECREF (exception_value);
Py_XDECREF (exception_backtrace);
Py_XDECREF (exception_value_repr);
Py_XDECREF (exception_value_str);
PyErr_Clear (); PyErr_Clear ();
} }

View file

@ -21,12 +21,8 @@ from gi.repository import GES
from gi.repository import GLib from gi.repository import GLib
from collections import OrderedDict from collections import OrderedDict
try: import opentimelineio as otio
import opentimelineio as otio otio.adapters.from_name('xges')
otio.adapters.from_name('xges')
except Exception as e:
Gst.info("Could not load OpenTimelineIO: %s" % e)
otio = None
class GESOtioFormatter(GES.Formatter): class GESOtioFormatter(GES.Formatter):
def do_save_to_uri(self, timeline, uri, overwrite): def do_save_to_uri(self, timeline, uri, overwrite):
@ -81,27 +77,26 @@ class GESOtioFormatter(GES.Formatter):
timeline.get_asset().add_formatter(formatter) timeline.get_asset().add_formatter(formatter)
return formatter.load_from_uri(timeline, "file://" + tmpxges.name) return formatter.load_from_uri(timeline, "file://" + tmpxges.name)
if otio is not None: GObject.type_register(GESOtioFormatter)
GObject.type_register(GESOtioFormatter) known_extensions_mimetype_map = [
known_extensions_mimetype_map = [ ("otio", "xml", "fcpxml"),
("otio", "xml", "fcpxml"), ("application/vnd.pixar.opentimelineio+json", "application/vnd.apple-xmeml+xml", "application/vnd.apple-fcp+xml")
("application/vnd.pixar.opentimelineio+json", "application/vnd.apple-xmeml+xml", "application/vnd.apple-fcp+xml") ]
]
extensions = [] extensions = []
for adapter in otio.plugins.ActiveManifest().adapters: for adapter in otio.plugins.ActiveManifest().adapters:
if adapter.name != 'xges': if adapter.name != 'xges':
extensions.extend(adapter.suffixes) extensions.extend(adapter.suffixes)
extensions_mimetype_map = [[], []] extensions_mimetype_map = [[], []]
for i, ext in enumerate(known_extensions_mimetype_map[0]): for i, ext in enumerate(known_extensions_mimetype_map[0]):
if ext in extensions: if ext in extensions:
extensions_mimetype_map[0].append(ext) extensions_mimetype_map[0].append(ext)
extensions_mimetype_map[1].append(known_extensions_mimetype_map[1][i]) extensions_mimetype_map[1].append(known_extensions_mimetype_map[1][i])
extensions.remove(ext) extensions.remove(ext)
extensions_mimetype_map[0].extend(extensions) extensions_mimetype_map[0].extend(extensions)
GES.FormatterClass.register_metas(GESOtioFormatter, "otioformatter", GES.FormatterClass.register_metas(GESOtioFormatter, "otioformatter",
"GES Formatter using OpenTimelineIO", "GES Formatter using OpenTimelineIO",
','.join(extensions_mimetype_map[0]), ','.join(extensions_mimetype_map[0]),
';'.join(extensions_mimetype_map[1]), 0.1, Gst.Rank.SECONDARY) ';'.join(extensions_mimetype_map[1]), 0.1, Gst.Rank.SECONDARY)