如何发送opencv视频到ffmpeg [英] How to send opencv video's to ffmpeg
问题描述
我试图将处理后的opencv Mat作为视频发送到ffmpeg。我编码框架并将其写入std输出,然后将其管道到ffmpeg。这是我的代码。
I m trying to send the processed opencv Mat as video to ffmpeg. I m encoding the frame and writing it to std output and then piping it to ffmpeg. Here is my code.
C ++:
if(!cap.isOpened()) {
cout << "Video not accessible" << endl;
return -1;
} else {
cout << "Video is accessible" << endl;
}
while (true) {
cap >> frame;
//some processing
cv::imencode(".jpg", frame, buff);
for (i = buff.begin(); i != buff.end(); ++i)
std::cout << *i ;
}
我的输入视频分辨率为640x418。我不改变视频大小
My input video resolution is 640x418. I do not alter the video size
建立后,我使用以下命令执行。
After building, I use following command to execute.
./ a.out | ffmpeg -f rawvideo -pix_fmt bgr24 -s 640x418 -r 30 -i - -an -f mpegts udp://0.0.0.0:8182
还有这个
./ a.out | ffmpeg -i pipe:0 -f rawvideo -pix_fmt bgr24 -s 640x418 -r 30 -i - -an -f mpegts udp://0.0.0.0:8182
然而,这似乎都不行。
请帮助。
推荐答案
相同的问题...同样的答案...
我希望这个答案可以帮助你。
Same question ... same answer... I hope this answer will help you.
在这个程序我以20 fps制作屏幕复制(RGB数据),并将图像发送到ffmpeg。我不使用管道,但插座。我使用这个命令行:
In this program I make a screen copy(RGB data) at 20 fps and send image to ffmpeg. i don't use pipe but socket. I use this command line :
ffmpeg -f rawvideo -pixel_format rgb24 -video_size 640x480 -i "tcp://127.0.0.1:2345" -codec:v libx264 -pix_fmt yuv420p Video.mp4
运行ffmpeg,然后将数据发送到端口2345使用套接字
to run ffmpeg and then send data to port 2345 using socket
sock->Write(b.GetData(), nb);
我不编码框架是原始数据
I don't encode frame it is raw data
这篇关于如何发送opencv视频到ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!