简体   繁体   English

OpenCV和Gstreamer流式直播视频

[英]OpenCV and Gstreamer streaming live video

My aim to get video stream from capture card (Blackmagic decklink) to OpenCV and live stream to red5 or any other rtmp server. 我的目标是将视频流从捕获卡(Blackmagic decklink)传输到OpenCV,并将实时流传输到red5或任何其他rtmp服务器。

So, I tried done with two branch at gstreamer with command is at below is working properly. 因此,我尝试在gstreamer的两个分支上完成以下命令,该命令在下面正常工作。 But, when using with OpenCV just stream black frames to rtmp server, by the way opencv works well. 但是,当与OpenCV一起使用时,只需将黑帧流式传输到rtmp服务器即可,opencv可以很好地工作。

Gstreamer Command : Gstreamer命令:

gst-launch-1.0 -v autovideosrc ! gst-launch-1.0 -v autovideosrc! tee name=t t. 三通名称= t t。 ! videoconvert ! 视频转换! videoscale ! 视频规模! queue ! 排队! x264enc pass=pass1 threads=4 bitrate=5000 tune=zerolatency ! x264enc pass = pass1线程= 4 bitrate = 5000 tune = zerolatency! queue ! 排队! flvmux streamable=true ! flvmux streamable = true! rtmpsink location="rtmp://127.0.0.1/live/stb live=1" max-lateness=100 t. rtmpsink location =“ rtmp://127.0.0.1/live/stb live = 1” max-lateness = 100 t。 ! video/x-raw,width=1280,height=720 ! video / x-raw,width = 1280,height = 720! appsink 应用程式

OpenCV code : OpenCV代码:

String gstSentence = "gst-launch-1.0 -v autovideosrc ! tee name=t " +
                "t. ! videoconvert ! videoscale ! queue ! x264enc pass=pass1 threads=4 bitrate=5000 tune=zerolatency  " +
                "! queue ! flvmux streamable=true ! rtmpsink location=\"rtmp://127.0.0.1/live/stb live=1\" max-lateness=100 " +
                "t. ! video/x-raw,width=1280,height=720 ! appsink";

        System.out.println(gstSentence);
        videoCapture = new VideoCapture(gstSentence);

My environment : 我的环境:

  • Ubuntu 16.04 Ubuntu 16.04
  • OpenCV 3.1 - Java Wrapper OpenCV 3.1-Java包装器
  • Gstreamer 1.8.1 Gstreamer 1.8.1

How can I deal with it? 我该如何处理?

Thanks in advance. 提前致谢。

The problem is that you left gst-launch-1.0 there which of course wouldnt work. 问题是您将gst-launch-1.0留在那里,这当然是行不通的。

This is a proper way: 这是一种正确的方法:

String gst = "autovideosrc ! tee name=t " + 
             "t. ! videoconvert ! videoscale ! queue ! x264enc pass=pass1 threads=4 bitrate=5000 tune=zerolatency  " +
             "! queue ! flvmux streamable=true ! rtmpsink location=\"rtmp://127.0.0.1/live/stb live=1\" max-lateness=100 " +
             "t. ! video/x-raw,width=1280,height=720 ! appsink";

videoCapture = new VideoCapture(gstSentence);

Inspired by this question.. 灵感来自这个问题..

And be aware that there are problems using x264enc along with tee.. because sometimes the x264enc want to preroll lot of frames which may flood the other branch of tee.. 并且请注意,将x264enc与tee一起使用会出现问题。因为有时x264enc会预卷很多帧,这可能会淹没tee的其他分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM