开发者

python GTK container for mjpeg stream

开发者 https://www.devze.com 2022-12-13 04:44 出处:网络
I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk.

I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk. The stream is a string of bytes from the driver. What widget would be best for displaying this and would I need to do some intermediate conversion before putting it in the widget? Sho开发者_运维百科uld I write my own widget to do this?


GTK+ does not contain a native widget capable of decoding and rendering video.

You should probably look into GStreamer, which is a streaming-media toolkit built on the same GObject framework as GTK+.

It has the GstXvImageSink that is capable of rendering video using X11, and you should be able to configure it to render on top of a GTK+ widget.


This example helped me getting started with gstreamer, it shows how one grabbs the webcam stream and displays it in an widget.

http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html


It is possible to use an Image widget to show the MJPEG stream.

Start a background thread, and have it read the stream and update the Image using gtk.gdk.PixbufLoader and image_widget.set_from_pixbuf

For example:

for frame in self.get_raw_frame():
    loader = gtk.gdk.PixbufLoader('jpeg')
    loader.write(frame)
    loader.close()
    pixbuf = loader.get_pixbuf()
    # Schedule image update to happen in main thread
    gobject.idle_add(self.widget.set_from_pixbuf, pixbuf)

Full working example is here: https://gist.github.com/mic159/fa2181a69f9119871b87

0

精彩评论

暂无评论...
验证码 换一张
取 消