我一直在寻找使用 avidemux、管道和 python 来显示单个 avi 视频文件中的视频和音频的方法。我可以使用 gst-launch 来做到这一点,但我想在代码中实现它。现在它说所有元素都已创建,但它不会从 avidemux 或解码器访问任何动态分配的焊盘。
python的完整代码如下。
谢谢,
#!/usr/bin/env python
import gobject, pygst
pygst.require("0.10")
import gst
def allocate_muxer_pad(dbin, pad, islast):
print "allocate prog entered"
if pad.get_caps()[0].to_string().startswith("a"):
pad.link(audioqueue.get_pad("sink"))
print 'audio Mux connected'
elif pad.get_caps()[0].to_string().startswith("v"):
pad.link(videoqueue.get_pad("sink"))
print 'Video Mux connected'
def new_Adecode_pad(dbin, pad, islast):
pad.link(audioconvert.get_pad("sink"))
print 'audio decode connected'
def new_Vdecode_pad(dbin, pad, islast):
pad.link(videoconvert.get_pad("sink"))
print 'video decode connected'
pipeline = gst.Pipeline("PIPELINE")
Bin = gst.Bin("pipeline")
src = gst.element_factory_make("filesrc", "source")
src.set_property("location", "testav.avi")
demux = gst.element_factory_make("avidemux","avi-demuxer")
audioqueue = gst.element_factory_make('queue', 'Audioqueue')
videoqueue = gst.element_factory_make('queue','videoqueue')
audiodecoder = gst.element_factory_make("decodebin2","Adecoder")
videodecoder = gst.element_factory_make("decodebin2","Vdecoder")
audioconverter = gst.element_factory_make("audioconvert","Audio_Converter")
videoconverter = gst.element_factory_make("ffmpegcolorspace","Video_Converter")
audioSink = gst.element_factory_make("autoaudiosink","Sink_Audio")
videoSink = gst.element_factory_make("ximagesink","Sink_Video")
Bin.add(src)
Bin.add_many(demux,audioqueue,videoqueue,audiodecoder,audioconverter,videodecoder,videoconverter,audioSink,videoSink)
src.link(demux)
gst.element_link_many(audioqueue,audiodecoder)
gst.element_link_many(audioconverter,audioSink)
gst.element_link_many(videoqueue,videodecoder)
gst.element_link_many(videoconverter,videoSink)
if (not(src) or not(demux) or not(audioqueue) or not(videoqueue) or not(videodecoder) or not(audiodecoder) or not(audioconverter) or not(videoconverter) or not(audioSink) or not(videoSink) ):
print "Elements not Created"
else:
print "Elements Created"
demux.connect("pad-added", allocate_muxer_pad)
demux.connect("pad-added", allocate_muxer_pad)
audiodecoder.connect("new-decoded-pad", new_Adecode_pad)
videodecoder.connect("new-decoded-pad", new_Vdecode_pad)
pipeline.set_state(gst.STATE_PLAYING)
print "Pipeline Playing"
# enter into a mainloop
loop = gobject.MainLoop()
loop.run()