在 C++ 程序中包含 ffmpeg-command

include ffmpeg-command in c++ program

我有一个 c++ 程序,它从共享内存中读取渲染图像并将它们写入管道 (mkfifo),这样我就可以使用 ffmpeg 捕获它们并将它们作为实时视频流式传输到 ffserver 上。为了让我的流工作,我必须分别启动程序和 ffmpeg-command。 我问自己是否有可能将 ffmpeg 包含到程序中并避免使用管道。

我的 ffmpeg 命令:

ffmpeg -re -f -rawvideo -s 800x600 -pix_fmt rgb24 -i myfifo http://localhost:8090/feed1.ffm

我的问题是:

将 ffmpeg 命令包含到 C++ 程序中的最佳方法是什么?是否有其他改进此解决方案的想法?

非常感谢任何帮助。提前致谢。

有两种方法:

更简单的方法是使用 system(),假设您在 Linux 中,然后启动 ffmpeg 命令。

if(system("ffmpeg -re -f -rawvideo -s 800x600 -pix_fmt rgb24 -i myfifo http://localhost:8090/feed1.ffm") != 0)
{
    cout << "ffmpeg failed..." << endl;
}

困难在于将库包含在您的项目中,并在内部使用它:Can FFmpeg be used as a library, instead of a standalone program?

开始检查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