ffmpeg docker镜像编译和安装

记录重新构件ffmpeg docker镜像,包含h264 h265 支持,使用二段编译减少最后生成包的大小。

整个Dockerfile如下:

 # 设置基础镜像
 FROM centos:7 as Builder 
 # 修改yum源
 RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' -i.bak /etc/yum.repos.d/CentOS-*.repo
 # 安装编译工具
 RUN yum install -y make gcc gcc-c++ curl wget cmake git 
 RUN mkdir /deployment
 WORKDIR /deployment/
 # 下载nasm编译安装,用于支持汇编
 RUN wget --no-check-certificate https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz && tar xvf nasm-2.15.05.tar.gz && cd nasm-2.15.05 && ./configure && make -j8 && make install
 # 获取lib264代码,编译安装
 RUN git clone https://github.com/mirror/x264.git && cd x264/ && git checkout stable && ./configure --enable-shared --enable-static && make -j8 && make install 
 
 # 获取lib265代码,编译安装
 RUN cd /deployment/ && git clone https://github.com/videolan/x265.git && cd x265 && git checkout stable && cd build && cmake ../source && make -j8 && make install 
 
 # 安装 autoconf automake libtool
 RUN yum install -y autoconf automake libtool
 
 #获取fdk-aac 并编译安装
 RUN cd /deployment/ && git clone https://github.com/mstorsjo/fdk-aac.git 
 RUN cd /deployment/fdk-aac/ && ./autogen.sh && ./configure && make -j8 && make install 
 RUN cd /deployment/ && git clone https://github.91chi.fun//https://github.com/FFmpeg/FFmpeg.git
 
 # 设置pkconfig路径,用于编译ffmpg
 ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
 
 # 获取ffmpg代码,编译安装
 RUN cd /deployment/FFmpeg && git checkout release/5.0 && ./configure --enable-static --enable-shared --enable-libx264 --enable-libx265 --enable-gpl --enable-libfdk-aac --enable-nonfree && make -j8 && make install

 # 第二阶段将编译结果复制过来 并设置相关的链接
 FROM centos:7 
 COPY --from=Builder /usr/local/bin/ffmpeg /usr/local/bin/ffmpeg
 COPY --from=Builder /usr/local/bin/ffprobe /usr/local/bin/ffprobe
 COPY --from=Builder /usr/local/bin/x265 /usr/local/bin/x265
 COPY --from=Builder /usr/local/bin/x264 /usr/local/bin/x264
 COPY --from=Builder /usr/local/lib/*.a /usr/local/lib/*.a 
 COPY --from=Builder /usr/local/lib/libavcodec.so.59.18.100 /usr/local/lib/libavcodec.so.59.18.100 
 COPY --from=Builder /usr/local/lib/libavdevice.so.59.4.100 /usr/local/lib/libavdevice.so.59.4.100
 COPY --from=Builder /usr/local/lib/libavfilter.so.8.24.100 /usr/local/lib/libavfilter.so.8.24.100
 COPY --from=Builder /usr/local/lib/libavformat.so.59.16.100 /usr/local/lib/libavformat.so.59.16.100
 COPY --from=Builder /usr/local/lib/libavutil.so.57.17.100 /usr/local/lib/libavutil.so.57.17.100
 COPY --from=Builder /usr/local/lib/libfdk-aac.so.2.0.2 /usr/local/lib/libfdk-aac.so.2.0.2
 COPY --from=Builder /usr/local/lib/libpostproc.so.56.3.100 /usr/local/lib/libpostproc.so.56.3.100 
 COPY --from=Builder /usr/local/lib/libswresample.so.4.3.100 /usr/local/lib/libswresample.so.4.3.100
 COPY --from=Builder /usr/local/lib/libswscale.so.6.4.100 /usr/local/lib/libswscale.so.6.4.100
 COPY --from=Builder /usr/local/lib/libx264.so.163 /usr/local/lib/libx264.so.163 
 COPY --from=Builder /usr/local/lib/libx265.so.198 /usr/local/lib/libx265.so.198

 RUN ln -s /usr/local/lib/libavcodec.so.59.18.100 /usr/local/lib/libavcodec.so.59 
 RUN ln -s /usr/local/lib/libavcodec.so.59.18.100 /usr/local/lib/libavcodec.so

 RUN ln -s /usr/local/lib/libavdevice.so.59.4.100 /usr/local/lib/libavdevice.so.59
 RUN ln -s /usr/local/lib/libavdevice.so.59.4.100 /usr/local/lib/libavdevice.so

 RUN ln -s /usr/local/lib/libavfilter.so.8.24.100 /usr/local/lib/libavfilter.so.8
 RUN ln -s /usr/local/lib/libavfilter.so.8.24.100 /usr/local/lib/libavfilter.so

 RUN ln -s /usr/local/lib/libavformat.so.59.16.100 /usr/local/lib/libavformat.so.59
 RUN ln -s /usr/local/lib/libavformat.so.59.16.100 /usr/local/lib/libavformat.so

 RUN ln -s /usr/local/lib/libavutil.so.57.17.100 /usr/local/lib/libavutil.so.57
 RUN ln -s /usr/local/lib/libavutil.so.57.17.100 /usr/local/lib/libavutil.so

 RUN ln -s /usr/local/lib/libfdk-aac.so.2.0.2 libfdk-aac.so.2 
 RUN ln -s /usr/local/lib/libfdk-aac.so.2.0.2 libfdk-aac.so

 RUN ln -s /usr/local/lib/libpostproc.so.56.3.100 /usr/local/lib/libpostproc.so.56
 RUN ln -s /usr/local/lib/libpostproc.so.56.3.100 /usr/local/lib/libpostproc.so

 RUN ln -s /usr/local/lib/libswresample.so.4.3.100 /usr/local/lib/libswresample.so.4
 RUN ln -s /usr/local/lib/libswresample.so.4.3.100 /usr/local/lib/libswresample.so

 RUN ln -s /usr/local/lib/libswscale.so.6.4.100 /usr/local/lib/libswscale.so.6
 RUN ln -s /usr/local/lib/libswscale.so.6.4.100 /usr/local/lib/libswscale.so

 RUN ln -s /usr/local/lib/libx264.so.163 /usr/local/lib/libx264.so
 RUN ln -s /usr/local/lib/libx265.so.198 /usr/local/lib/libx265.so

 COPY --from=Builder /usr/local/lib/pkgconfig /usr/local/lib/pkgconfig

 RUN echo "/usr/local/lib/" > /etc/ld.so.conf.d/ffmpeg.conf && ldconfig

Lokie博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论
  • 本博客使用免费开源的 laravel-bjyblog v5.5.1.1 搭建 © 2014-2018 lokie.wang 版权所有 ICP证:沪ICP备18016993号
  • 联系邮箱:kitche1985@hotmail.com