【问题标题】:Gstreamer HSL Stream cannot be read无法读取 Gstreamer HSL 流
【发布时间】:2021-05-30 03:55:21
【问题描述】:

我正在尝试在 Linux (Ubuntu 20.10) 中使用 OpenCV 和 Gstreamer 创建 HLS 流。 OpenCv 已成功安装并支持 GStreamer。 在这两个教程的帮助下,我创建了一个简单的应用程序: http://4youngpadawans.com/stream-live-video-to-browser-using-gstreamer/

How to use Opencv VideoWriter with GStreamer?

代码如下:

#include <string>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio/videoio_c.h>

using namespace std;
using namespace cv;
int main()
{
    VideoCapture cap;
    if(!cap.open(0, CAP_V4L2))
        return 0;

 VideoWriter writer(
 "appsrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! x264enc ! mpegtsmux ! hlssink playlist-root=http://192.168.1.42:8080 location=/home/sem/hls/segment_%05d.ts target-duration=5 max-files=5 playlist-location=/home/sem/hls/playlist.m3u8 ",
  0,
  20,
  Size(800, 600),
  true);

    if (!writer.isOpened()) {
        std::cout <<"VideoWriter not opened"<<endl;
        exit(-1);
    }
    for(;;)
    {
          Mat frame;
          cap >> frame;
          

          if( frame.empty() ) break; // end of video stream


          writer.write(frame);

          imshow("this is you, smile! :)", frame);
          if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC 
    }
}

HTTP 服务是使用 python 命令启动的

python3 -m http.server 8080

乍一看,一切都很好。 Streamer 创建所有需要的文件(播放列表和 xxx.ts 文件) Folder with the HTTP Server content

Server Response on requests

但如果我尝试播放流,它就不起作用:

Open Stream in browser

使用 VLC-Player 播放也不行(绿屏)

谁能给我一个提示,我做错了什么? 提前致谢!

【问题讨论】:

    标签: c++ opencv gstreamer http-live-streaming


    【解决方案1】:

    检查创建的流格式。检查您推送到管道中的颜色格式。如果它的 RGB 机会是您创建的非 4:2:0 流,它对解码器的支持非常有限。

    【讨论】:

      【解决方案2】:

      感谢弗洛里安, 我尝试更改格式,但这不是问题。 首先,应该执行的是从捕获设备获取真实帧率

       int fps = cap.get(CV_CAP_PROP_FPS);
      
       VideoWriter writer(
       "appsrc ! videoconvert ! videoscale ! video/x-raw, width=640, height=480 ! x264enc !  mpegtsmux ! hlssink playlist-root=http://192.168.1.42:8080 location=/home/sem/hls/segment_%05d.ts target-duration=5 max-files=5 playlist-location=/home/sem/hls/playlist.m3u8 ",
        0,
        fps,
        Size(640, 480),
        true);
      

      其次,帧大小在所有提到的地方都应该相同。 捕获的帧也应调整大小:

        resize(frame, frame, Size(640,480));
        writer.write(frame);
      

      在此更改后,由 gstreamer 生成的块可以在本地播放器中打开并且视频可以正常播放。不幸的是,远程访问仍然失败。 :(

      【讨论】:

        猜你喜欢
        • 2020-03-05
        • 2013-10-18
        • 1970-01-01
        • 2022-12-20
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        • 1970-01-01
        • 2019-12-27
        相关资源
        最近更新 更多