找回密码
 立即注册
查看: 1809|回复: 1

CentOS7下编译和安装ffmpeg以及相关依赖库的脚本

[复制链接]

43

主题

30

回帖

251

积分

管理员

积分
251
发表于 2024-4-8 09:19:59 | 显示全部楼层 |阅读模式
、准备工作 在编译安装ffmpeg以及相关依赖包之前,需要确保安装下列编译工具:
  1. yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
复制代码

一键式Shell编译脚本build_ffmpeg_all.sh 编译脚本如下:
  1. # install required software package
  2. #yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel

  3. mkdir ~/ffmpeg_sources

  4. INSTALL_PATH=/usr/local

  5. # build and install nasm
  6. # An assembler used by some libraries. Highly recommended or your resulting build may be very slow.
  7. cd ~/ffmpeg_sources
  8. curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
  9. tar xjvf nasm-2.14.02.tar.bz2
  10. cd nasm-2.14.02
  11. ./autogen.sh
  12. ./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin"
  13. make
  14. make install

  15. # build and install Yasm
  16. # An assembler used by some libraries. Highly recommended or your resulting build may be very slow.
  17. cd ~/ffmpeg_sources
  18. curl -O -L https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
  19. tar xzvf yasm-1.3.0.tar.gz
  20. cd yasm-1.3.0
  21. ./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin"
  22. make
  23. make install


  24. # build and install libx264
  25. # H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.
  26. # Requires ffmpeg to be configured with --enable-gpl --enable-libx264.
  27. cd ~/ffmpeg_sources
  28. git clone --depth 1 https://code.videolan.org/videolan/x264.git
  29. curl -O -L http://anduin.linuxfromscratch.org/BLFS/x264/x264-20200819.tar.xz
  30. xz -d x264-20200819.tar.xz
  31. tar -xvf x264-20200819.tar
  32. mv x264-20200819 x264
  33. cd x264
  34. PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" ./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin" --enable-static
  35. make
  36. make install

  37. # build and install libx265
  38. # H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.
  39. # Requires ffmpeg to be configured with --enable-gpl --enable-libx265.
  40. cd ~/ffmpeg_sources
  41. # hg clone https://bitbucket.org/multicoreware/x265
  42. curl -O -L http://anduin.linuxfromscratch.org/BLFS/x265/x265_3.4.tar.gz
  43. tar -xzvf x265_3.4.tar.gz
  44. mv x265_3.4 x265
  45. cd ~/ffmpeg_sources/x265/build/linux
  46. cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" -DENABLE_SHARED:bool=off ../../source
  47. make
  48. make install


  49. # build and install libfdk_aac
  50. # AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
  51. # Requires ffmpeg to be configured with --enable-libfdk_aac (and --enable-nonfree if you also included --enable-gpl).
  52. cd ~/ffmpeg_sources
  53. git clone --depth 1 https://github.com/mstorsjo/fdk-aac
  54. cd fdk-aac
  55. autoreconf -fiv
  56. ./configure --prefix="$INSTALL_PATH" --disable-shared
  57. make
  58. make install

  59. # build and install libmp3lame
  60. # MP3 audio encoder.
  61. # Requires ffmpeg to be configured with --enable-libmp3lame.
  62. cd ~/ffmpeg_sources
  63. curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
  64. tar xzvf lame-3.100.tar.gz
  65. cd lame-3.100
  66. ./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin" --disable-shared --enable-nasm
  67. make
  68. make install

  69. # build and install libopus
  70. # Opus audio decoder and encoder.
  71. # Requires ffmpeg to be configured with --enable-libopus.
  72. cd ~/ffmpeg_sources
  73. curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
  74. tar xzvf opus-1.3.1.tar.gz
  75. cd opus-1.3.1
  76. ./configure --prefix="$INSTALL_PATH" --disable-shared
  77. make
  78. make install

  79. # libvpx
  80. # VP8/VP9 video encoder and decoder. See the VP9 Video Encoding Guide for more information and usage examples.
  81. # Requires ffmpeg to be configured with --enable-libvpx.
  82. cd ~/ffmpeg_sources
  83. # git clone --depth 1 https://github.com/webmproject/libvpx.git
  84. curl -O -L https://github.com/webmproject/libvpx/archive/v1.9.0/libvpx-1.9.0.tar.gz
  85. tar xzvf libvpx-1.9.0.tar.gz
  86. cd libvpx-1.9.0
  87. ./configure --prefix="$INSTALL_PATH" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
  88. make
  89. make install

  90. # build and install FFmpeg
  91. cd ~/ffmpeg_sources
  92. curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
  93. tar xjvf ffmpeg-snapshot.tar.bz2
  94. cd ffmpeg
  95. PATH="$INSTALL_PATH/bin:$PATH" PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" ./configure \
  96.   --prefix="$INSTALL_PATH" \
  97.   --pkg-config-flags="--static" \
  98.   --extra-cflags="-I$INSTALL_PATH/include" \
  99.   --extra-ldflags="-L$INSTALL_PATH/lib" \
  100.   --extra-libs=-lpthread \
  101.   --extra-libs=-lm \
  102.   --bindir="$INSTALL_PATH/bin" \
  103.   --enable-gpl \
  104.   --enable-libfdk_aac \
  105.   --enable-libfreetype \
  106.   --enable-libmp3lame \
  107.   --enable-libopus \
  108.   --enable-libvpx \
  109.   --enable-libx264 \
  110.   --enable-libx265 \
  111.   --enable-nonfree
  112. make
  113. make install
  114. hash -d ffmpeg

复制代码

3、执行脚本build_ffmpeg_all.sh 执行脚本前需要保证使用root账户或者超级账户权限,然后为build_ffmpeg_all.sh添加可执行权限:
  1. chmod +x build_ffmpeg_all.sh
复制代码
最后,执行脚本
  1. sh build_ffmpeg_all.sh
复制代码








43

主题

30

回帖

251

积分

管理员

积分
251
 楼主| 发表于 2024-4-8 09:20:16 | 显示全部楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|上海录客智能科技 ( 沪ICP备17017717号-8 )|网站地图

GMT+8, 2024-12-22 14:06 , Processed in 0.147430 second(s), 25 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表