I don’t want to sound ungrateful for all the fine work you guys did on DeepStream 4.
But some python examples would be nice if possible.
CPP is just no fun and in the end isn’t that what its all about?
You can install the python bindings for gstreamer and your code will look nearly identical to the C version. Put it this way: gstreamer’s python bindings are not very pythonic and you might as well use C or C++. It’s callback hell in any language, sorry. You might as well make it as fast as it can go.
I am considering porting some of the C example code to python for quicker prototyping.
As I am a complete gstreamer beginner: Do you guys know if the python API is complete, e.g. a full port would likely be possible?
It’s feature complete from what I understand, but the best examples still look like C. If you want a really good example of extremely well written GStreamer python, check this out:
https://coral.googlesource.com/edgetpuvision/
It’s for Coral, but you could easily swap out Nvidia’s elements. It’s Apache license. The problem is things like this:
def on_bus_message(bus, message, pipeline, loop):
if message.type == Gst.MessageType.EOS:
seek_element = get_seek_element(pipeline)
if loop and seek_element:
flags = Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT
if not seek_element.seek_simple(Gst.Format.TIME, flags, 0):
Gtk.main_quit()
else:
Gtk.main_quit()
elif message.type == Gst.MessageType.WARNING:
err, debug = message.parse_warning()
sys.stderr.write('Warning: %s: %s\n' % (err, debug))
elif message.type == Gst.MessageType.ERROR:
err, debug = message.parse_error()
sys.stderr.write('Error: %s: %s\n' % (err, debug))
Gtk.main_quit()
That isn’t very pythonic. It looks like C, and it takes just as long to write, which is the area where Python is supposed to excel. Here is a C example from Gstreamer’s Bus documentation:
static gboolean
my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
{
g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:{
GError *err;
gchar *debug;
gst_message_parse_error (message, &err, &debug);
g_print ("Error: %s\n", err->message);
g_error_free (err);
g_free (debug);
g_main_loop_quit (loop);
break;
}
case GST_MESSAGE_EOS:
/* end-of-stream */
g_main_loop_quit (loop);
break;
default:
/* unhandled message */
break;
}
/* we want to be notified again the next time there is a message
* on the bus, so returning TRUE (FALSE means we want to stop watching
* for messages on the bus and our callback should not be called again)
*/
return TRUE;
}
Looks pretty similar no? It handles messages from the bus and quits the main loop. All the code in every language is on_this(), on_that(), on_something_or_other(), and so on. It’s not a big deal if they aren’t called frequently, but in GStreamer they often need to be (for example, on every buffer) are and that’s slow in Python.
Python’s advantage is that memory management is handled for you, but if you follow the GStreamer tutorials you’re shown how to do that yourself. It doesn’t matter if you don’t know C. Retype enough tutorial examples (they’re really good), read the docs or ask here when you get stuck, and you will learn.