【发布时间】: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
但如果我尝试播放流,它就不起作用:
使用 VLC-Player 播放也不行(绿屏)
谁能给我一个提示,我做错了什么? 提前致谢!
【问题讨论】:
标签: c++ opencv gstreamer http-live-streaming