2
0

build_ffmpeg.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. ff_src_dir="../../3rdparty"
  3. # the jobs to make ffmpeg
  4. if [[ "" == $SRS_JOBS ]]; then
  5. export SRS_JOBS="--jobs=1"
  6. fi
  7. ff_current_dir=$(pwd -P)
  8. ff_build_dir="${ff_current_dir}/_build"
  9. ff_release_dir="${ff_current_dir}/_release"
  10. echo "start to build the tools for transcode system:"
  11. echo "current_dir: ${ff_current_dir}"
  12. echo "build_dir: ${ff_build_dir}"
  13. echo "release_dir: ${ff_release_dir}"
  14. echo "SRS_JOBS: ${SRS_JOBS}"
  15. mkdir -p ${ff_build_dir}
  16. mkdir -p ${ff_release_dir}
  17. # yasm for libx264
  18. ff_yasm_bin=${ff_release_dir}/bin/yasm
  19. if [[ -f ${ff_yasm_bin} ]]; then
  20. echo "yasm is ok"
  21. else
  22. echo "build yasm-1.2.0"
  23. cd $ff_current_dir &&
  24. rm -rf yasm-1.2.0 && unzip -q ${ff_src_dir}/yasm-1.2.0.zip &&
  25. cd yasm-1.2.0 && ./configure --prefix=${ff_release_dir} &&
  26. make && make install
  27. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build yasm-1.2.0 failed"; exit 1; fi
  28. fi
  29. # add yasm to path, for x264 to use yasm directly.
  30. # ffmpeg can specifies the yasm path when configure it.
  31. export PATH=${PATH}:${ff_release_dir}/bin
  32. # libfdk-aac
  33. if [[ -f ${ff_release_dir}/lib/libfdk-aac.a ]]; then
  34. echo "libfdk_aac is ok"
  35. else
  36. echo "build fdk-aac-0.1.3"
  37. cd $ff_current_dir &&
  38. rm -rf fdk-aac-0.1.3 && unzip -q ${ff_src_dir}/fdk-aac-0.1.3.zip &&
  39. cd fdk-aac-0.1.3 && bash autogen.sh && ./configure --prefix=${ff_release_dir} --enable-static && make ${SRS_JOBS} && make install
  40. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build fdk-aac-0.1.3 failed"; exit 1; fi
  41. fi
  42. # lame-3.99
  43. if [[ -f ${ff_release_dir}/lib/libmp3lame.a ]]; then
  44. echo "libmp3lame is ok"
  45. else
  46. echo "build lame-3.99.5"
  47. cd $ff_current_dir &&
  48. rm -rf lame-3.99.5 && unzip -q ${ff_src_dir}/lame-3.99.5.zip &&
  49. cd lame-3.99.5 && ./configure --prefix=${ff_release_dir} --enable-static && make ${SRS_JOBS} && make install
  50. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build lame-3.99.5 failed"; exit 1; fi
  51. fi
  52. # speex-1.2rc1
  53. if [[ -f ${ff_release_dir}/lib/libspeex.a ]]; then
  54. echo "libspeex is ok"
  55. else
  56. echo "build speex-1.2rc1"
  57. cd $ff_current_dir &&
  58. rm -rf speex-1.2rc1 && unzip -q ${ff_src_dir}/speex-1.2rc1.zip &&
  59. cd speex-1.2rc1 && ./configure --prefix=${ff_release_dir} --enable-static && make ${SRS_JOBS} && make install
  60. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build speex-1.2rc1 failed"; exit 1; fi
  61. fi
  62. # x264 core.157
  63. if [[ -f ${ff_release_dir}/lib/libx264.a ]]; then
  64. echo "x264 is ok"
  65. else
  66. echo "build x264"
  67. cd $ff_current_dir &&
  68. rm -rf x264-snapshot-20181116-2245 && unzip -q ${ff_src_dir}/x264-snapshot-20181116-2245.zip &&
  69. cd x264-snapshot-20181116-2245 &&
  70. # chmod +w configure && patch -p0 <../../../3rdparty/patches/5.x264.osx.gcc.patch &&
  71. ./configure --prefix=${ff_release_dir} --disable-opencl --bit-depth=all \
  72. --enable-static --disable-avs --disable-swscale --disable-lavf \
  73. --disable-ffms --disable-gpac --disable-cli &&
  74. make ${SRS_JOBS} && make install
  75. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build x264 failed"; exit 1; fi
  76. fi
  77. # ffmpeg-4.1
  78. if [[ -f ${ff_release_dir}/bin/ffmpeg ]]; then
  79. echo "ffmpeg-4.1 is ok"
  80. else
  81. echo "build ffmpeg-4.1"
  82. cd $ff_current_dir &&
  83. rm -rf ffmpeg-4.1 && unzip -q ${ff_src_dir}/ffmpeg-4.1.zip &&
  84. echo "remove all so to force the ffmpeg to build in static" &&
  85. rm -f ${ff_release_dir}/lib/*.so* &&
  86. echo "export the dir to enable the build command canbe use." &&
  87. export ffmpeg_exported_release_dir=${ff_release_dir} &&
  88. cd ffmpeg-4.1 &&
  89. ./configure \
  90. --enable-gpl --enable-nonfree \
  91. --yasmexe=${ff_yasm_bin} \
  92. --prefix=${ff_release_dir} --cc= \
  93. --enable-static --disable-shared --disable-debug \
  94. --extra-cflags='-I${ffmpeg_exported_release_dir}/include' \
  95. --extra-ldflags='-L${ffmpeg_exported_release_dir}/lib -lm -ldl' \
  96. --disable-ffplay --disable-ffprobe --disable-doc \
  97. --enable-postproc --enable-bzlib --enable-zlib --enable-parsers \
  98. --enable-libx264 --enable-libmp3lame --enable-libfdk-aac --enable-libspeex \
  99. --enable-pthreads --extra-libs=-lpthread \
  100. --enable-encoders --enable-decoders --enable-avfilter --enable-muxers --enable-demuxers &&
  101. make ${SRS_JOBS} && make install
  102. ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build ffmpeg failed"; exit 1; fi
  103. fi