I try to process logs from Gstreamer using Python.
I created file test_logging.py
import gi
gi.require_version("Gst", "1.0")
from gi.repository import GLib, Gst
def _process_message(
category: Gst.DebugCategory,
level: Gst.DebugLevel,
filename: str,
function: str,
line: int,
object,
message: Gst.DebugMessage,
user_data,
):
msg_str = message.get()
msg_str = f"{filename} {msg_str}"
print(msg_str)
Gst.init(None)
Gst.debug_remove_log_function()
pipeline = Gst.parse_launch(
"uridecodebin name=decoder uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.mp4 ! autovideoconvert ! autovideosink"
)
Gst.debug_add_log_function(_process_message, user_data=pipeline)
loop = GLib.MainLoop()
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except KeyboardInterrupt:
pass
except Exception as e:
pass
pipeline.set_state(Gst.State.NULL)
loop.quit()
I attached handler using Gst.debug_add_log_function.
And everything seems to work fine in regular scenarios. python3 test_logging.py works fine, but I miss most of my logs, so when I bump log level with flag GST_DEBUG=3 I get Segfault:
$ GST_DEBUG=3 python3 ./test_log.py
xvcontext.c MIT-SHM extension check failed at XShmAttach. Not using shared memory.
gstbasesrc.c pad not activated yet
gstbasesrc.c pad not activated yet
qtdemux_types.c unknown QuickTime node type sgpd
qtdemux_types.c unknown QuickTime node type sbgp
....More irrelevant logs
gstv4l2object.c Unable to try format: Unknown error -1
gstv4l2object.c Could not probe maximum capture size for pixelformat H264
gstv4l2object.c Unable to try format: Unknown error -1
gstv4l2object.c Could not probe minimum capture size for pixelformat NM12
gstv4l2object.c Unable to try format: Unknown error -1
gstv4l2object.c Could not probe maximum capture size for pixelformat NM12
sys:1: Warning: g_object_is_floating: assertion 'G_IS_OBJECT (object)' failed
sys:1: Warning: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
Segmentation fault (core dumped)
Do you know how to fix this problem?
In the docs I found:
Be sure to use G_GNUC_NO_INSTRUMENT (not introspectable) on that function, it is needed.
But I don't know how to use it in Python.