2012-11-23 112 views
2

我想端口下面的GStreamer命令進入python程序:通過RTMP的GStreamer和Python

gst-launch-0.10 -v -m v4l2src ! queue ! ffmpegcolorspace ! queue ! x264enc pass=pass1 threads=0 bitrate=1536 tune=zerolatency ! queue ! flvmux name=mux pulsesrc ! queue max-size-bytes=134217728 max-size-time=20000000000 max-size-buffers=1000 ! audioconvert ! lame ! audio/mpeg ! queue ! mux. mux. ! queue ! rtmpsink location='rtmp://x.x.x.x/live/myStream' 

使用此命令,可以錄製和觀看實況流流傳輸到wowza服務器時。但我有一些麻煩將此命令移植到python。尤其是RTMP片似乎導致麻煩(因爲它與文件接收工作):

self.pipeline = gst.Pipeline("diepipeline") 

    self.src = gst.parse_launch("v4l2src") 
    self.pipeline.add(self.src) 

    self.videoenc = make_bin("(name=videoenc queue ! ffmpegcolorspace ! queue ! x264enc pass=pass1 threads=0 bitrate=1536 tune=zerolatency ! queue)") 
    self.pipeline.add(self.videoenc) 

    self.audio2src = gst.parse_launch("pulsesrc") 
    self.pipeline.add(self.audio2src) 

    self.audio2 = make_bin("(name=audio2 queue max-size-bytes=134217728 max-size-time=20000000000 max-size-buffers=1000 ! audioconvert ! lame ! audio/mpeg ! queue)") 
    self.pipeline.add(self.audio2) 
    self.audio2src.link(self.audio2) 

    self.flvmux = gst.parse_launch("flvmux name=flvmux") 
    self.pipeline.add(self.flvmux) 
    self.videoenc.link(self.flvmux) 
    self.audio2.link(self.flvmux) 

    self.queue1 = gst.parse_launch("queue") 
    self.rtmpsink = gst.parse_launch("rtmpsink location='rtmp://192.168.1.11/live/myStream'") 
    self.pipeline.add(self.queue1, self.rtmpsink) 
    gst.element_link_many(self.flvmux, self.queue1, self.rtmpsink) 

    self.pipeline.set_state(gst.STATE_PLAYING) 

這裏是輸出:

PAUSED: /GstPipeline:diepipeline/GstQueue:queue5 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstFlvMux:flvmux (__main__.GstFlvMux) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2/GstQueue:queue4 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2/GstCapsFilter:capsfilter0 (__main__.GstCapsFilter) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2/GstLame:lame0 (__main__.GstLame) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2/GstAudioConvert:audioconvert0 (__main__.GstAudioConvert) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2/GstQueue:queue3 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstBin:audio2 (gst.Bin) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc/GstQueue:queue2 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc/GstX264Enc:x264enc0 (__main__.GstX264Enc) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc/GstQueue:queue1 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc/GstFFMpegCsp:ffmpegcsp0 (__main__.GstFFMpegCsp) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc/GstQueue:queue0 (__main__.GstQueue) 
PAUSED: /GstPipeline:diepipeline/GstBin:videoenc (gst.Bin) 
PAUSED: /GstPipeline:diepipeline/GstPulseSrc:pulsesrc0 (__main__.GstPulseSrc) 
PAUSED: /GstPipeline:diepipeline/GstDecklinkSrc:src (__main__.GstDecklinkSrc) 
PAUSED: /GstPipeline:diepipeline (gst.Pipeline) 
PAUSED: /GstPipeline:diepipeline/GstFileSink:filesink0 (__main__.GstFileSink) 

任何想法可能會導致這個問題?謝謝!

回答

5

好吧,經過幾個小時的嘗試不同的事情,我發現我的代碼中的缺陷。

不得不刪除我的RTMP-URL中的單引號:從

self.rtmpsink = gst.parse_launch("rtmpsink location='rtmp://x.x.x.x/live/myStream'") 

self.rtmpsink = gst.parse_launch("rtmpsink location=rtmp://x.x.x.x/live/myStream") 

有時候最簡單的事情是花費你的時間最多的人。 ..