2012-05-29 52 views
0

我試圖寫一個python應用程序,並讓gstreamer播放我錄製的視頻文件(並在稍後的視頻中添加了一些字幕textoverlay)。python和gstreamer,試圖播放視頻(後來添加textoverlay)

但看起來我仍然有一些基本問題,理解如何墊工作..我似乎無法正確地獲得鏈接。

我在上面構建的基本示例是一個簡單的應用程序,它顯示來自攝像頭的視頻。所以我知道代碼的作品,只是我的管道搞亂了事情。

另外,如果我跑執行下面的終端管道,它的工作原理:

gst-launch-0.10 filesrc location=GOPR0042.MP4 ! decodebin2 ! ffmpegcolorspace ! videoflip method=2 ! xvimagesink 

現在,我試圖重新此管道Python應用程序,因爲這樣的:

#!/usr/bin/env python 

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("Webcam-Viewer") 
    window.set_default_size(500, 400) 
    window.connect("destroy", gtk.main_quit, "WM destroy") 
    vbox = gtk.VBox() 
    window.add(vbox) 
    self.movie_window = gtk.DrawingArea() 
    vbox.add(self.movie_window) 
    hbox = gtk.HBox() 
    vbox.pack_start(hbox, False) 
    hbox.set_border_width(10) 
    hbox.pack_start(gtk.Label()) 
    self.button = gtk.Button("Start") 
    self.button.connect("clicked", self.start_stop) 
    hbox.pack_start(self.button, False) 
    self.button2 = gtk.Button("Quit") 
    self.button2.connect("clicked", self.exit) 
    hbox.pack_start(self.button2, False) 
    hbox.add(gtk.Label()) 
    window.show_all() 

    # Set up the gstreamer pipeline 
    self.pipeline = gst.Pipeline("player") 
    self.filesource = gst.element_factory_make("filesrc","filesource") 
      self.filesource.set_property("location","""/home/jlumme/video/GOPR0042.MP4""") 
    self.pipeline.add(self.filesource) 


    self.decoder = gst.element_factory_make("decodebin2","decoder") 
     self.pipeline.add(self.decoder) 

    self.colorspace = gst.element_factory_make("ffmpegcolorspace","colorspace") 
    self.pipeline.add(self.colorspace) 

    self.videosink = gst.element_factory_make("xvimagesink","videosink") 
    self.pipeline.add(self.videosink) 


    self.filesource.link(self.decoder) 
    self.decoder.link(self.colorspace) #This fails 
    self.colorspace.link(self.videosink) 

    bus = self.pipeline.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 start_stop(self, w): 
    if self.button.get_label() == "Start": 
     self.button.set_label("Stop") 
     self.pipeline.set_state(gst.STATE_PLAYING) 
    else: 
     self.pipeline.set_state(gst.STATE_NULL) 
     self.pipeline.set_label("Start") 

def exit(self, widget, data=None): 
    gtk.main_quit() 

def on_message(self, bus, message): 
    t = message.type 
    if t == gst.MESSAGE_EOS: 
     self.pipeline.set_state(gst.STATE_NULL) 
     self.button.set_label("Start") 
    elif t == gst.MESSAGE_ERROR: 
     err, debug = message.parse_error() 
     print "Error: %s" % err, debug 
     self.pipeline.set_state(gst.STATE_NULL) 
     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": 
     # Assign the viewport 
     imagesink = message.src 
     imagesink.set_property("force-aspect-ratio", True) 
     imagesink.set_xwindow_id(self.movie_window.window.xid) 

GTK_Main() 
gtk.gdk.threads_init() 
gtk.main() 

現在我有看到有人使用動態打印機將解碼器連接到一些音頻內容,但我不太明白它是如何工作的... 因此,我想我無法直接連接decoderbin2和ffmpegcolorspace? 有人可以解釋我爲什麼?

另外,您是否在我的下一步中遇到了問題,我想將textoverlay元素添加到管道中以顯示字幕?

回答

1

在最近回答我自己的問題的習慣,我會做的是,這裏還有:)

所以,多一點讀書和黑客攻擊後,我確實知道,我是不是真的得到動態墊以及他們如何才需要連接只有當有東西進來

所以基本上我解決了上述問題與2隊列,音頻和視頻。那些隊列被連接到解碼器,並且它們需要被放置在動態連接的分路器&之後。 解碼器和接收器似乎需要一個動態連接的墊。

在這個論壇得很清楚解釋了這一進程的一個問題是這樣的一個: gstreamer code for playing avi file is hanging