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 ;
}
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
and also this
./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
However none of this seems to work.
Kindly help.
解决方案
Same question ... same answer...
I hope this answer will help you.
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
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