The system needs to use ffmpeg that supports h264 and h265. In order to compile it once, execute it everywhere, and do not need to recompile ffmpeg every time you run docker, simply compile the entire ffmpeg into a package and test it into the basic image. , the whole process is recorded here.
(1) Download X264: git clone http://git.videolan.org/git/x264.git
(2) Download x265 : wget https://bitbucket.org/multicoreware/x265/downloads/x265_2.7.tar.gz
(3) 安装 cmake, yum or apt-get
(4) Install X264:
cd x264
sudo ./configure --enable-shared --disable-asm
sudo make
sudo make install
(5) ldconfig
(6) Install x265
cd x265
cmake -G "Unix Makefiles"
make
make install
(7) Move h265 library files
cp x265.pc /usr/local/lib
cp libx265.so.151 /usr/lib/ # 按操作系统,可能需要其他库文件,提示确实,拷贝即可
apt-get install pkg-config
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/ #不设置会找不到报错ERROR: x265 not found using pkg-config
pkg-config --list-all | grep x265 # 查看 是否已经添加x265到库中
(8) Compile ffmpeg
sudo ./configure --prefix=/usr/local/ --enable-shared --enable-libx264 --enable-gpl --enable-pthreads --disable-x86asm --enable-libx265
sudo make
sudo make install
After a long wait, there is only one last step before the big job is done.
(9) vi /etc/ld.so.conf added: /usr/local/ffmpeg/lib execute ldconfig
(10) View dependencies: ldd /usr/local/bin/ffmpeg, type all so and binary files into tar packages
(11) Copy files and write dockerfile
COPY ./ffmpeg.tar.gz /data/ffmpeg.tar.gz
RUN cd /data && tar -xvf ffmpeg.tar.gz && cd ffmpeg && cp -f ffmpeg /usr/local/bin/ffmpeg && cp -f lib64/* /lib/x86_64-linux-gnu/
You're done, as long as the operating system is the same, whether it is the real operating system or docker, it can be copied and used.