Trying to use gst / omx in python

TDAS talldarkandstrange at me.com
Mon Apr 7 10:39:12 PDT 2014


Still a bit new to this, so hope I’m not being daft here ;) Trying to play an h.264 mp4 file in Python on a Raspberry Pi. And failing miserably ;) I’ve installed all the requirements (I believe) and I’m using the below script, which I adapted from somewhere. Now the command line works as follows:

gst-launch-1.0 filesrc location=/home/user/test.mp4 ! qtdemux ! queue max-size-bytes=10000000 ! h264parse ! omxh264dec ! queue max-size-buffers=4 ! eglglessink

…but I can’t figure out how to include the arguments in that command line to the functions in Python below! Any pointers anyone? 

import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst

class GTK_Main:
	
	def __init__(self):
		window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		window.set_title("Video-Player")
		window.set_default_size(500, 400)
		window.connect("destroy", gtk.main_quit, "WM destroy")
		vbox = gtk.VBox()
		window.add(vbox)
		hbox = gtk.HBox()
		vbox.pack_start(hbox, False)
		self.movie_window = gtk.DrawingArea()
		vbox.add(self.movie_window)
		window.show_all()
		
		self.player = gst.element_factory_make("playbin2", "player")
		bus = self.player.get_bus()
		bus.add_signal_watch()
		bus.enable_sync_message_emission()
		bus.connect("message", self.on_message)
		bus.connect("sync-message::element", self.on_sync_message)
	
	def startme():
		filepath = "/home/user/test.mp4"
		self.player.set_property("uri", "file://" + filepath)
		self.player.set_state(gst.STATE_PLAYING)
	

								
	def on_message(self, bus, message):
		t = message.type
		if t == gst.MESSAGE_EOS:
			self.player.set_state(gst.STATE_NULL)
			#self.button.set_label("Start")
		elif t == gst.MESSAGE_ERROR:
			self.player.set_state(gst.STATE_NULL)
			#err, debug = message.parse_error()
			print "Error: %s" % err, debug
			self.button.set_label("Start")
	
	def on_sync_message(self, bus, message):
		if message.structure is None:
			return
		message_name = message.structure.get_name()
		if message_name == "prepare-xwindow-id":
			imagesink = message.src
			imagesink.set_property("force-aspect-ratio", True)
			gtk.gdk.threads_enter()
			imagesink.set_xwindow_id(self.movie_window.window.xid)
			gtk.gdk.threads_leave()
			
GTK_Main()
gtk.gdk.threads_init()
startme(self)
gtk.main()






More information about the gstreamer-openmax mailing list