Created
April 5, 2022 20:20
-
-
Save mondain/dd47796755776483db0f483753c3d1e2 to your computer and use it in GitHub Desktop.
Bash script for building openssl, librtmp, openh264, and ffmpeg for testing purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# explanation https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 | |
set -exuo pipefail | |
WORKDIR="$(pwd)" | |
mkdir -p ${WORKDIR} | |
SRC="$WORKDIR/ffmpeg_build" | |
CMPLD="$WORKDIR/compile" | |
NUM_PARALLEL_BUILDS=4 | |
if [[ -e "${CMPLD}" ]]; then | |
rm -rf "${CMPLD}" | |
fi | |
mkdir -p ${SRC} | |
mkdir -p ${CMPLD} | |
export PATH=${SRC}/bin:$PATH | |
export PKG_CONFIG_PATH="${SRC}/lib/pkgconfig" | |
export ARCH=amd64 | |
export LDFLAGS="-fPIC -L/usr/local/lib -L/usr/lib/amd64-linux-gnu" | |
export CFLAGS="-Wno-deprecated-declarations -fPIC -I/usr/local/include -I/usr/include/amd64-linux-gnu" | |
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" | |
function build_zlib () { | |
if [[ ! -e "${SRC}/lib/pkgconfig/zlib.pc" ]]; then | |
echo "Downloading: zlib (1.2.11)" | |
{(curl -Ls -o - https://zlib.net/zlib-1.2.11.tar.gz | tar zxf - -C $CMPLD/) &}; | |
wait | |
echo '♻️ ' Start compiling ZLIB | |
cd ${CMPLD}/zlib-1.2.11 | |
./configure --prefix=${SRC} | |
make -j ${NUM_PARALLEL_BUILDS} | |
make install | |
rm ${SRC}/lib/libz.so* || true | |
rm ${SRC}/lib/libz.* || true | |
fi | |
} | |
# librtmp needs an older openssl | |
function build_openssl () { | |
# build openssl https://github.com/openssl/openssl.git | |
if [[ ! -e "${SRC}/lib/pkgconfig/openssl.pc" ]]; then | |
echo "Cloning git repository" | |
git clone --depth 1 -b OpenSSL_1_0_2-stable https://github.com/openssl/openssl.git $CMPLD/openssl & | |
wait | |
echo '♻️ ' Start compiling openssl | |
cd ${CMPLD}/openssl | |
./Configure linux-x86_64 -Wall -Wa,--noexecstack --prefix=${SRC} zlib-dynamic no-hw no-shared -static | |
make -j ${NUM_PARALLEL_BUILDS} && make install_sw | |
fi | |
} | |
function build_rtmp () { | |
# build librtmp via rtmpdump https://repo.or.cz/rtmpdump.git | |
if [[ ! -e "${SRC}/lib/pkgconfig/librtmp.pc" ]]; then | |
echo "Cloning git repository" | |
git clone --depth 1 -b master https://repo.or.cz/rtmpdump.git $CMPLD/rtmpdump & | |
wait | |
echo '♻️ ' Start compiling rtmp | |
cd ${CMPLD}/rtmpdump/librtmp | |
sed "s/prefix=\/usr\/local/prefix=\/home\/mondain\/workspace\/tools\/ffmpeg-dev\/ffmpeg_build/" -i Makefile | |
make -j ${NUM_PARALLEL_BUILDS} SHARED= SO_INST= CRYPTO=OPENSSL SYS=posix prefix=${SRC} \ | |
CFLAGS="-I${SRC}/include -I${SRC}/include/openssl ${CFLAGS}" \ | |
LDFLAGS="-L${SRC}/lib -L${SRC}/lib64 ${LDFLAGS}" XLIBS="-ldl -l:libssl.a -l:libcrypto.a" && make install | |
fi | |
} | |
function build_lame () { | |
if [[ ! -e "${SRC}/lib/libmp3lame.a" ]]; then | |
echo "Cloning git repository" | |
git clone --depth 1 -b origin https://github.com/rbrito/lame.git $CMPLD/lame & | |
wait | |
cd ${CMPLD}/lame | |
./configure --prefix=${SRC} --enable-shared | |
make -j ${NUM_PARALLEL_BUILDS} | |
make install | |
fi | |
} | |
function build_openh264 () { | |
if [[ ! -e "${SRC}/lib/pkgconfig/openh264.pc" ]]; then | |
echo "Cloning git repository" | |
git clone --depth 1 -b openh264v2.2.0 https://github.com/cisco/openh264.git $CMPLD/openh264 & | |
wait | |
echo '♻️ ' Start compiling openh264 | |
cd ${CMPLD}/openh264 | |
# /home/mondain/workspace/github-infrared5/cauldron/red5pro-cauldron/ext/workdir/ffmpeg_build | |
sed "s/PREFIX=\/usr\/local/PREFIX=\/home\/mondain\/workspace\/tools\/ffmpeg-dev\/ffmpeg_build/" -i Makefile | |
make install OS=linux ARCH=${ARCH} | |
fi | |
} | |
function build_vpx () { | |
if [[ ! -e "${SRC}/lib/pkgconfig/vpx.pc" ]]; then | |
echo "Cloning git repository" | |
git clone --depth 1 -b master https://github.com/webmproject/libvpx $CMPLD/libvpx & | |
wait | |
echo '♻️ ' Start compiling VPX | |
cd ${CMPLD}/libvpx | |
./configure --prefix=${SRC} --enable-vp8 --enable-postproc --enable-vp9-postproc --enable-vp9-highbitdepth --disable-examples --disable-docs --enable-multi-res-encoding --disable-unit-tests --enable-pic --enable-shared | |
make -j ${NUM_PARALLEL_BUILDS} | |
make install | |
fi | |
} | |
function build_opus () { | |
if [[ ! -e "${SRC}/lib/pkgconfig/opus.pc" ]]; then | |
echo "Downloading: libopus (1.3.1)" | |
{(curl -Ls -o - https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz | tar zxf - -C $CMPLD/) &}; | |
wait | |
echo '♻️ ' Start compiling OPUS | |
cd ${CMPLD}/opus-1.3.1 | |
./configure --prefix=${SRC} --enable-shared --enable-dependency-tracking --enable-float-approx --disable-doc --disable-extra-programs --with-pic | |
make -j ${NUM_PARALLEL_BUILDS} | |
make install | |
fi | |
} | |
function build_ffmpeg () { | |
echo "Cloning git repository" | |
git clone --depth 1 -b master https://github.com/FFmpeg/FFmpeg $CMPLD/ffmpeg & | |
wait | |
echo '♻️ ' Start compiling FFMPEG | |
cd ${CMPLD}/ffmpeg | |
export PKG_CONFIG_PATH+=":${SRC}/lib/pkgconfig:/usr/local/lib/pkgconfig" | |
# --pkgconfigdir="${SRC}/lib/pkgconfig" \ | |
./configure --arch=amd64 --target-os=linux --prefix=${SRC} \ | |
--extra-cflags="-fPIC -fno-stack-check -I${SRC}/include" \ | |
--extra-ldflags="-fPIC -m64 -L${SRC}/lib" \ | |
--extra-ldexeflags=-pie \ | |
--extra-libs="-lpthread -lm -ldl -l:libssl.a -l:libcrypto.a" \ | |
--disable-doc \ | |
--enable-static \ | |
--enable-gpl --enable-nonfree \ | |
--enable-openssl \ | |
--enable-librtmp \ | |
--enable-libopenh264 \ | |
--enable-decoder=aac,h264,flv,mp3 \ | |
--enable-encoder=aac,libopenh264 \ | |
--enable-parser=aac,h264,mp3 \ | |
--enable-protocol=librtmp,file,pipe,hls \ | |
--enable-bsf=aac_adtstoasc,h264_mp4toannexb \ | |
--enable-filter=aresample,scale,fps,format,metadata,amovie,movie,overlay,null,asetpts,setpts,atrim,trim,rotate,transpose \ | |
--enable-demuxer=h264,mpegts,flv,mov,live_flv \ | |
--enable-muxer=mpegts,mp4,flv,mov \ | |
--enable-swresample --enable-swscale --enable-pthreads \ | |
--enable-asm --enable-x86asm \ | |
--enable-runtime-cpudetect \ | |
--enable-pic --enable-hardcoded-tables | |
echo "build start" | |
start_time="$(date -u +%s)" | |
make -j ${NUM_PARALLEL_BUILDS} | |
end_time="$(date -u +%s)" | |
elapsed="$(($end_time-$start_time))" | |
make install | |
echo "[FFmpeg] $elapsed seconds elapsed for build" | |
} | |
total_start_time="$(date -u +%s)" | |
#build_yasm | |
#build_nasm | |
#build_zlib | |
build_openssl | |
build_rtmp | |
#build_lame | |
build_openh264 | |
#build_vpx | |
build_opus | |
build_ffmpeg | |
total_end_time="$(date -u +%s)" | |
total_elapsed="$(($total_end_time-$total_start_time))" | |
echo "Total $total_elapsed seconds elapsed for build" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment