首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法读取Gstreamer HSL流

无法读取Gstreamer HSL流
EN

Stack Overflow用户
提问于 2021-02-28 19:02:58
回答 2查看 75关注 0票数 0

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

How to use Opencv VideoWriter with GStreamer?

代码如下:

代码语言:javascript
复制
#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命令启动的

代码语言:javascript
复制
python3 -m http.server 8080

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

Server Response on requests

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

Open Stream in browser

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

有人能给我点提示吗,我哪里做错了?提前感谢!

EN

回答 2

Stack Overflow用户

发布于 2021-03-02 06:15:56

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

票数 0
EN

Stack Overflow用户

发布于 2021-03-06 17:23:48

谢谢Florian,我试着改变了格式,但这不是问题。首先,应执行的是从捕获设备获取实际帧率

代码语言:javascript
复制
 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);

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

代码语言:javascript
复制
  resize(frame, frame, Size(640,480));
  writer.write(frame);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66408336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档