OpenCV的(编程,C ++),标准输出管道输送到FFmpeg的(在bashscript)? [英] OpenCV(programmed in C++) stdout piped to ffmpeg(in bashscript)?

查看:1376
本文介绍了OpenCV的(编程,C ++),标准输出管道输送到FFmpeg的(在bashscript)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的bash脚本管道的OpenCV的输出这是一个out.avi文件中使用tail命令和管道输出到FFmpeg的那个文件转换为标准输出

I am using the following bash script to pipe the output of OpenCV which is an out.avi file converting that file to a stdout using the tail command and piping the output to ffmpeg

./OpenCV & \
tail -n +0 -f out.avi  | ffmpeg -i pipe:0  -hls_time 1 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename '%03d.ts' stream.m3u8 

这工作,但导致延迟的问题。

This works but causes latency issues.

我试图改变C ++ code,使画面得到使用 COUT&LT写入标准输出;<架; 这里是一些code的

I have tried to change the C++ code so that the frame gets written to a stdout using cout << frame; here is some of the code.

imshow( window_name, frame );//show frame
video.write(frame);//rec to avi
cout << frame;

从上面的code我得到的窗口中显示处理后的图像,帧保存在AVI格式,并从最后一行我得到打印到命令行的帧的像素值。

From the above code I get the window to display the processed image, the frame is saved in avi format and from the last line i get printed to the command line the pixel values of the frames.

现在我曾尝试以下的Bash脚本来管这个标准输出没有成功到FFmpeg的。

Now I have tried the following Bash script to pipe this stdout to ffmpeg with no success.

./OpenCV | ffmpeg -i pipe:0  -hls_time 1 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename '%03d.ts' stream.m3u8 

我也试过

./的OpenCV | ffmpeg的-i管:0 -f rawvideo -pix_fmt bgr24 -s小480x320 -hls_time 1 -hls_list_size 0 -hls_wrap 10 -hls_segment_filename'%03d.ts'stream.m3u8

任何人有什么想法?

推荐答案

的问题是, COUT&LT;&LT;架; 通过OpenCV中定义的结构的印刷像素值。你有什么需要的是,你可以检索使用帧 imen code 的实际二进制数据
例如:

the issue is that cout<< frame; is printing pixel values of the Mat structure defined by openCV. What do you need is the actual binary data of the frame which you can retrieve using imencode for example

std::vector<uchar> buff;    
cv::imencode(".jpg", frame, buff);
for (auto i = buff.begin(); i != buff.end(); ++i)
    std::cout << *i ;

如果你想测试它,你可以把缓冲区里的文件,并看到像这样的输出

if you want to test it, you can write the buffer to a file and see the output like this

std::vector<uchar> buff;
cv::imencode(".jpg", frame, buff);
std::ofstream myfile;
myfile.open("example.jpg", std::ios::binary);
for (auto i = buff.begin(); i != buff.end(); ++i)
{
    //std::cout << *i;
    myfile << *i;
}
myfile.close();

这篇关于OpenCV的(编程,C ++),标准输出管道输送到FFmpeg的(在bashscript)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆