在GStreamer中获取rtmp流,创建镶嵌并发送生成的rtmp

时间:2018-09-26 12:13:13

标签: gstreamer rtmp

我运行以下代码

     gst-launch-1.0 -e \
    videomixer name=mix \
            sink_0::xpos=0   sink_0::ypos=0  sink_0::alpha=0\
            sink_1::xpos=0   sink_1::ypos=0 \
            sink_2::xpos=200 sink_2::ypos=0 \
            sink_3::xpos=0   sink_3::ypos=100 \
            sink_4::xpos=200 sink_4::ypos=100 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147924'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_1 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147925'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_2 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147926'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_3 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147927'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_4 \
        mix. ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://streaming.example.com:1935/test'

谢谢。我们解决了镶嵌问题。这是工作版本。

1 个答案:

答案 0 :(得分:0)

有两个问题。

1)主要问题是“ videomixer”只有一个src键盘。您正在将其连接到两个打击垫。  -

gst-launch-1.0 -e \

    videomixer name=mix \
            sink_0::xpos=0   sink_0::ypos=0  sink_0::alpha=0\
            sink_1::xpos=0   sink_1::ypos=0 \
            sink_2::xpos=200 sink_2::ypos=0 \
            sink_3::xpos=0   sink_3::ypos=100 \
            sink_4::xpos=200 sink_4::ypos=100 \
        ! xvimagesink 

通过此操作,您正在将混音器src_pad连接到sixvimagesink的水槽垫

最后,您尝试使用队列和其他元素将videomixer src_连接到rtmpsink。

所以您必须删除其中一个连接。

如果您不想连接到xvimagesink,只需删除“!xvimagesink”

如果您不想连接到rtmpsink,请删除“ mix!queue!videoconvert ...”部分。

2)如果您要保留连接到队列,则存在以下问题。 您正在将mix.sink_4连接到mix.src。

... ! mix.sink_4 \
        ! mix. ! queue ! videoconvert ! ...

删除第一个“!”和“。”在最后一行。

... ! mix.sink_4 \
         mix ! queue ! videoconvert ! ...

然后它不应给出语法错误。

编辑1

我又想你错了。您正在将mix的src连接到mix.sink_0。我已经纠正了。

gst-launch-1.0 -e \
    videomixer name=mix \
            sink_0::xpos=0   sink_0::ypos=0  sink_0::alpha=0\
            sink_1::xpos=0   sink_1::ypos=0 \
            sink_2::xpos=200 sink_2::ypos=0 \
            sink_3::xpos=0   sink_3::ypos=100 \
            sink_4::xpos=200 sink_4::ypos=100 \
      \    /* You should not add "! .mix.sink_0" here. */
    rtmpsrc location='rtmp://streaming.example.com:1935/209147924'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_1 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147925'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_2 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147926'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_3 \
    rtmpsrc location='rtmp://streaming.example.com:1935/209147927'\
        ! decodebin ! videoconvert ! videoscale \
        ! video/x-raw,width=200,height=100 \
        ! mix.sink_4 \
        mix ! queue ! videoconvert ! x264enc ! flvmux streamable=true ! queue ! rtmpsink location='rtmp://streaming.example.com:1935/test'

让我在这里提供一些有关“ name =“用法的信息。 您可以在gstreamer管道中命名一个元素,然后使用它来构造管道。它在复杂的管道中最有用。让我通过简单的管道展示其用法。

假设以下是必需的管道:

 srcelem ! elem1 ! elem2 ! elem3 ! sinkelem

可以这样写。

elem2 name=named_elem \    /* Naming elem2 */
named_elem ! elem3 ! sinkelem \     /* Connecting elem2 to downstream pipeline part. Note that there is no "!" before "named_elem" */
srcelem ! elem1 ! named_elem /* Connecting elem2 to upstream pipeline part. Note that there is no "!" after "named_elem" */

如果仔细阅读,它会构建与前面提到的管道相同的管道。