ffmpeg 4.2 安装(链接x264 和x265)

时间:2020-04-28
本文章向大家介绍ffmpeg 4.2 安装(链接x264 和x265),主要包括ffmpeg 4.2 安装(链接x264 和x265)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

最近因为工作需要,要进行265 10bit编码,于是从ffmpeg官网下载了最新版的32位的ffmpeg可执行程序,使用如下命令进行编码:

ffmpeg.exe -i input.ts -vcodec libx265 -pix_fmt yuv420p10le -acodec copy output.ts

得到了一个很蒙蔽的结果:

注意看黄色这一行,说的是ffmpeg不支持yuv420p10le像素格式,自动切换为yuv420p进行编码,但是yuv420p编出来位深度只有8bit,我去,难道最新版本的ffmpeg不支持10bit编码?

于是不死心啊,然后各种百度谷歌,最后从国外的一个问答网址上看到有个国外友人说那是因为你用的ffmpeg自带的x265编码器不支持10bit编码,恍然大悟,从上面x265编码器输出的信息中也能看出来是只支持8bit编码的,那么解决办法就是自己编译一个支持10bit的x265库,然后再集成到ffmepg里面去,等于说要自己重新编译ffmpeg哦,编译过的同学应该都知道这是极其痛苦的事情,但是为了革命,没办法啊,那么就来吧,这里介绍linux下面的操作:

1. 编译支持10bit的x265库:

从官网下载源码包:https://bitbucket.org/multicoreware/x265/wiki/Home

要让x265支持10bit编码,只需要修改CMake的一个编译选项即可:

tar -zxvf x265_2.3.tar.gz
cd x265_2.3/source
vim CMakeLists.txt

 把option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" OFF)修改为option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" ON)即可;

最后执行CMake编译即可:

cd x265_2.3/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local/x265_10bit -DENABLE_SHARED=ON ../../source make -j4 make install

检验是否是真的支持10bit:

cd /usr/local/x265_10bit/bin
./x265 --help

输出信息如下:

x265 [info]: HEVC encoder version 2.3
x265 [info]: build info [Linux][GCC 4.4.7][64 bit] 10bit

说明支持10bit编码了。

2. 把新编译的支持10bit编码的x265库集成到ffmpeg中:

这就是自己编译ffmpeg的过程,可以参考网上的例子,这里重点是介绍编译支持10bit编码的x265,就不再说明了。

注意事项:

1. 在修改x265的CMakeList时,发现了这么一行说明:

# NOTE: We only officially support high-bit-depth compiles of x265
# on 64bit architectures. Main10 plus large resolution plus slow
# preset plus 32bit address space usually means malloc failure. You
# can disable this if(X64) check if you desparately need a 32bit
# build with 10bit/12bit support, but this violates the "shrink wrap
# license" so to speak. If it breaks you get to keep both halves.
# You will need to disable assembly manually.
说明要使用x265进行10bit编码需要在64位的机子上运行,32位的不行哦;

x264 编译

cd x264-snapshot-20170801-2245
./configure --enable-shared --disable-asm
make
make install


ffmpeg 的编译命令(需要安装GPU驱动和cuda)
--enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/work/lvyunxiang/lajitong/ffmpeg_install_dir --enable-version3 --enable-postproc --enable-pthreads --enable-avisynth --disable-yasm --enable-libx265 --enable-libx264 --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree--extra-cflags='-I/data/x264dir/include -I/data/x265dir/include -I/usr/local/cuda-8.0/include -I/usr/local/include/ffnvcodec -I/data/my_nvenc_parse' --extra-ldflags='-L/data/x264dir/lib -L/data/x265dir/lib -L/usr/local/cuda-8.0/lib64 -L/data/my_nvenc_parse -lhdr


ERROR: x265 not found using pkg-config (x265需要为动态库,静态库会报这个错误)

编译命令(只有x264 和 x265)

./configure --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/ffmpeg_install_dir --enable-version3  --enable-postproc --enable-pthreads --enable-avisynth --disable-yasm --enable-libx265 --enable-libx264 --enable-nonfree --extra-cflags="-I/usr/local/include -I/usr/local/x265_10bit/include" --extra-ldflags="-L/usr/local/lib -L/usr/local/x265_10bit/lib"




原文地址:https://www.cnblogs.com/lvyunxiang/p/12794715.html