I have a c++ program that reads rendered images from shared-memory and writes them into a pipe(mkfifo), so that I can capture them with ffmpeg and stream them as live-video over ffserver. For my stream to work I have to start the program and the ffmpeg-command seperately. I asked myself if there isn't a possibility to include the ffmpeg into the program and avoid the pipe.
My ffmpeg command:
ffmpeg -re -f -rawvideo -s 800x600 -pix_fmt rgb24 -i myfifo http://localhost:8090/feed1.ffm
My question is:
What would be the best way to include the ffmpeg-command into the c++-program? Is there some other idea to improve this solution?
Any help is greatly appreciated. Thanks in advance.
There are two ways:
The easier is to use system(), assuming you are in Linux, and launch the ffmpeg command.
if(system("ffmpeg -re -f -rawvideo -s 800x600 -pix_fmt rgb24 -i myfifo http://localhost:8090/feed1.ffm") != 0)
{
cout << "ffmpeg failed..." << endl;
}
The difficult is to include the library in your project, and use it internally: Can FFmpeg be used as a library, instead of a standalone program?.
To start check out https://trac.ffmpeg.org/wiki/Using%20libav*, where it describes how to use libav (internal library used by ffmpeg), and I would recommend to follow the tutorial http://dranger.com/ffmpeg/tutorial01.html