在Ubuntu下安装完FFmpeg后(安装方法可以参考https://blog.csdn.net/hz951290428/article/details/79715996,感谢这位博主的教程),我们可以在Ubuntu中通过调用FFmpeg的API编写程序了。
测试程序(main.cpp)的代码如下:
#include <iostream>
extern "C" {
#include <libavcodec/avcodec.h>
}
using namespace std;
int main()
{
printf("Test FFmpeg\n");
#ifdef _WIN64
cout << "Windows X64" << endl;
#endif
#ifdef WIN32
cout << "Windows X86" << endl;
#endif
#ifdef _WIN32
cout << "Windows" << endl;
#endif
cout << avcodec_configuration() << endl;
getchar();
}
上述代码在win10,vs2015下编译,运行的效果如下:
下面我们将上述代码放到Ubuntu下编译运行。博主是在VMWare中安装的Ubuntu(VMWare版本是VMWare12,Ubuntu版本是Ubuntu14.04,64位)。将上述代码(main.cpp)通过共享文件夹(或其它方式)拷贝到虚拟机的Ubuntu中。在Ubuntu中执行命令:
g++ main.cpp -o main -I /usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswresample -lswscale
其中-I参数指定头文件的路径,-L参数指定库文件的路径。由于博主的FFmpeg安装在/usr/local下,所以执行上述命令
执行完后,在Ubuntu中会生成可执行文件main,如下图所示:
扫描二维码关注公众号,回复:
9328429 查看本文章
运行可执行程序main,效果如下图所示: