我正在尝试在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?
代码如下:
#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播放也不起作用(绿屏)
有人能给我点提示吗,我哪里做错了?提前感谢!
发布于 2021-03-02 06:15:56
检查创建了什么流格式。检查您推送到管道中的颜色格式。如果它是RGB,那么您创建的是非4:2:0流,它对解码器的支持非常有限。
发布于 2021-03-06 17:23:48
谢谢Florian,我试着改变了格式,但这不是问题。首先,应执行的是从捕获设备获取实际帧率
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生成的块可以在本地播放器中打开,视频就可以工作了。不幸的是,远程访问仍然失败。:(
https://stackoverflow.com/questions/66408336
复制相似问题