前言
此处照着网上教程坑略多,务必看完再动手。
1 安装
下载好ffmpeg源码后命令行进入目录下执行
sudo ./configure --enable-shared --prefix=/usr/local/ffmpeg
如果提示yasm版本太旧则安装一下
sudo apt-get install yasm
然后再次执行上面的命令即可
ps:这里仅简单安装,./configure 可以查看即将安装项目,需要什么自己配吧
2 使用
进入安装目录下 /usr/local/ffmpeg,由于没有配置ffmpeg环境变量,此时执行./ffmpeg会提示各种so链接库找不到。
sudo gedit /etc/ld.so.conf
添加到文件尾行
/usr/local/ffmpeg/lib
执行 sudo ldconfig
然后就能正常使用了
3 图片转视频
./ffmpeg -f image2 -i /xxxx/frames/%05d.jpg -vcodec libx264 -r 10 /xxxxx/test.mp4 -y
我用opencv在frames目录下生成了一堆图片,00000-10000,这里注意%05d.jpg,根据我的图片编号决定的。如果不匹配可能会报错,比如一开始我写的%d.jpg:
Could find no file with path ‘xxx/frames/%d.jpg’ and index in the range 0-4
继续运行:
ERROR1: Unknown encoder ‘libx264’
3-1 编译安装x264
这是编译时没有把这个编码库编码进来。
参考 https://www.cnblogs.com/blackhumour2018/p/9400415.html
sudo ./configure --enable-shared --prefix=./install --e
nable-gpl --enable-libx264
重新编译ffmpeg新增x264配置,发现libx264 not found,这时候需要安装。
下载后进入x264目录
./configure --enable-static --enable-shared
ERROR2 提示 :Found no assembler Minimum version is nasm-2.13
安装一下 sudo apt-get install nasm
然后重新configure, make, make install
3-2 重新编译ffmpeg
sudo ./configure --enable-shared --prefix=./install --enable-gpl --enable-libx264
重新configure后应当在enabled encoders中发现libx264
Enabled encoders:
a64multi jpegls png
a64multi5 libx264 ppm
aac libx264rgb prores
ac3 ljpeg prores_aw
ac3_fixed magicyuv prores_ks
adpcm_adx mjpeg qtrle
...
make -j8 ,在编译x264时发生错误,提示添加 -fPIC
ERROR3 /usr/local/lib/libx264.a(base.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5’ can not be used when making a shared object; recompile with -fPIC
也就是需要在编译x264的时候 with -fPIC
囧,重新编译x264, ./configure --help可以看到有个选项可以直接打开PIC
./configure --enable-static --enable-shared --enable-pic
依然三件套,configure, make,install
ERROR4 error while loading shared libraries: libx264.so.157: cannot open shared object file: No such file or directory
这个我倒是知道,因为安装x264的时候so被装到了/usr/local/lib下,囧。这个位置是没有被搜索的
sudo gedit /etc/ld.so.conf
添加到文件尾行
/usr/local/lib
执行 sudo ldconfig
整个过程结束
小结
不同功能可能遇到的问题不一样,仅供参考