2

我正在尝试将以下 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)

知道什么可能导致这个问题吗?谢谢!

4

1 回答 1

6

好的,经过数小时尝试不同的事情后,我发现了我的代码中的缺陷。

必须删除我的 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")

有时最简单的事情是花费你最多时间的事情......

于 2012-11-23T15:26:29.753 回答