最近因為工作需要,要進行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 "