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


./configure --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/usr/local --enable-version3  --enable-postproc --enable-pthreads --enable-avisynth --enable-libx265 --enable-libx264 --enable-nvenc --enable-cuda --enable-cuvid --enable-nonfree --extra-cflags="-I/usr/local/include -I/usr/local/cuda/include/ -I/usr/local/include/ffnvcodec" --extra-ldflags="-L/usr/local/lib -L/usr/local/cuda/lib64"


报错
    [nvenc_hevc @ 0x3f928c0] Driver does not support the required nvenc API version. Required: 10.0 Found: 9.1
    [nvenc_hevc @ 0x3f928c0] The minimum required Nvidia driver for nvenc is 390.25 or newer

猜测原因可能是nv-codec-headers的版本是10.0,但是Nvidia driver版本只支持9.1。查看nv-codec-headers的所有tag,checkout到9.1版本,重新编译ffmpeg成功。
————————————————
版权声明:本文为CSDN博主「su@coding」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/A199222/java/article/details/103233935

切换到9.1编译成功了



ERROR: x265 not found using pkg-config (x265需要为动态库,静态库会报这个错误)
export PKG_CONFIG_PATH=/usr/local/x265_10bit/lib/pkgconfig:$PKG_CONFIG_PATH

编译命令(只有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"

make

make install

对于ffmpeg 有其他依赖度(如依赖opencv)需要制定LD_LIBRARY_PATH
[root@node0 ffmpeg-4.2.2]# echo $LD_LIBRARY_PATH
:/root/opencv-4.2.0/install/lib64/:/home/lib_object_detect/

 

ffmpeg 集成opencv 编译命令
./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 -I/home/lib_object_detect/" --extra-ldflags="-L/usr/local/lib -L/usr/local/x265_10bit/lib -L/home/lib_object_detect -L/root/opencv-4.2.0/install/lib64/ -lopencv_highgui -lopencv_imgcodecs -lopencv_core -lopencv_video -lopencv_imgproc -lopencv_imgcodecs -lopencv_objdetect -lopencv_ml -lopencv_calib3d -lopencv_dnn -lopencv_features2d -lopencv_flann -lopencv_videoio -lopencv_photo  -lm -ldl -lpthread -lrt -lssl -lcrypt -lcrypto -lz -lstdc++  -lcurl  -L/home/lib_object_detect/ -lobject_detect "

 





 

posted @ 2020-04-28 15:42  虾兵  阅读(4197)  评论(0编辑  收藏  举报