1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1685: Cross build RTC with FFmpeg

This commit is contained in:
winlin 2021-06-19 21:55:12 +08:00
parent 1c75a270b3
commit 1e9de0e191
267 changed files with 12603 additions and 1451 deletions

View file

@ -604,6 +604,9 @@ if [[ $SRS_SRTP_ASM == YES ]]; then
echo "SRTP with openssl(ASM) optimization" &&
SRTP_CONFIG="export PKG_CONFIG_PATH=../openssl/lib/pkgconfig" && SRTP_OPTIONS="--enable-openssl"
fi
if [[ $SRS_CROSS_BUILD == YES ]]; then
SRTP_OPTIONS="$SRTP_OPTIONS --host=$(echo $SRS_TOOL_CC|awk -F '-gcc' '{print $1}')"
fi
# Patched ST from https://github.com/ossrs/state-threads/tree/srs
if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/_release/lib/libsrtp2.a ]]; then
echo "The libsrtp-2-fit is ok.";
@ -627,10 +630,10 @@ if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit sta
#####################################################################################
# libopus, for WebRTC to transcode AAC with Opus.
#####################################################################################
if [[ $SRS_RTC == YES ]]; then
if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then
# Only build static libraries if no shared FFmpeg.
if [[ $SRS_SHARED_FFMPEG == NO ]]; then
OPUS_OPTIONS="--disable-shared"
OPUS_OPTIONS="--disable-shared --disable-doc"
fi
if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1/_release/lib/libopus.a ]]; then
echo "The opus-1.3.1 is ok.";
@ -639,7 +642,8 @@ if [[ $SRS_RTC == YES ]]; then
(
rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
tar xf ../../3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 &&
./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS && make ${SRS_JOBS} && make install
./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS &&
make ${SRS_JOBS} && make install &&
cd .. && rm -rf opus && ln -sf opus-1.3.1/_release opus
)
fi
@ -656,19 +660,30 @@ fi
#####################################################################################
if [[ $SRS_FFMPEG_FIT == YES ]]; then
FFMPEG_OPTIONS=""
if [[ $SRS_CROSS_BUILD == YES ]]; then
FFMPEG_CONFIGURE=./configure
else
FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/opus/lib/pkgconfig ./configure"
fi
# If disable nasm, disable all ASMs.
if [[ $SRS_NASM == NO ]]; then
nasm -v >/dev/null 2>&1 && NASM_BIN_OK=YES
if [[ $NASM_BIN_OK != YES || $SRS_NASM == NO || $SRS_CROSS_BUILD == YES ]]; then
FFMPEG_OPTIONS="--disable-asm --disable-x86asm --disable-inline-asm"
fi
# If no nasm, we disable the x86asm.
nasm -v >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
FFMPEG_OPTIONS="--disable-x86asm"
fi
# Only build static libraries if no shared FFmpeg.
if [[ $SRS_SHARED_FFMPEG == YES ]]; then
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-shared"
fi
# For cross-build.
if [[ $SRS_CROSS_BUILD == YES ]]; then
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-cross-compile --arch=arm --target-os=linux"
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cross-prefix=$(echo $SRS_TOOL_CC|awk -F 'gcc' '{print $1}')"
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cc=${SRS_TOOL_CC} --cxx=${SRS_TOOL_CXX} --ar=${SRS_TOOL_AR} --ld=${_ST_LD}"
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=opus --enable-encoder=opus"
else
FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus"
fi
if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/_release/lib/libavcodec.a ]]; then
echo "The ffmpeg-4-fit is ok.";
@ -678,20 +693,24 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then
rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit &&
# Create a hidden directory .src
cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && cp -R ../../../3rdparty/ffmpeg-4-fit/* . &&
# For libopus and other codecs.
ABS_OBJS=$(cd .. && pwd) &&
# Build source code.
PKG_CONFIG_PATH=$ABS_OBJS/opus/lib/pkgconfig ./configure \
--prefix=`pwd`/_release \
--pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" ${FFMPEG_OPTIONS} \
$FFMPEG_CONFIGURE \
--prefix=`pwd`/_release --pkg-config=pkg-config ${FFMPEG_OPTIONS} \
--disable-everything --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \
--disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \
--disable-avdevice --disable-avformat --disable-swscale --disable-postproc --disable-avfilter --disable-network \
--disable-dct --disable-dwt --disable-error-resilience --disable-lsp --disable-lzo --disable-faan --disable-pixelutils \
--disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuda-llvm --disable-cuvid \
--disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuvid \
--disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi \
--disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv \
--disable-lzma --disable-sdl2 --disable-everything --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm \
--enable-decoder=libopus --enable-encoder=aac --enable-encoder=opus --enable-encoder=libopus --enable-libopus &&
--enable-encoder=aac &&
# See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/
if [[ $SRS_CROSS_BUILD == YES ]]; then
sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' config.h &&
sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h &&
sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h
fi &&
make ${SRS_JOBS} && make install &&
cd .. && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg
)

View file

@ -5,7 +5,7 @@ help=no
# feature options
SRS_HDS=NO
SRS_SRT=NO
SRS_RTC=RESERVED
SRS_RTC=YES
SRS_CXX11=NO
SRS_CXX14=NO
SRS_NGINX=NO
@ -196,6 +196,11 @@ function parse_user_option() {
echo "Error: The $option is not supported yet"; exit 1
fi
if [[ $option == '--arm' || $option == '--mips' || $option == '--with-arm-ubuntu12' || $option == '--with-mips-ubuntu12' ]]; then
echo "Error: Removed misleading option $option, please read https://github.com/ossrs/srs/wiki/v4_CN_SrsLinuxArm#ubuntu-cross-build-srs"
exit -1
fi
# Parse options to variables.
case "$option" in
-h) help=yes ;;
@ -315,14 +320,6 @@ function parse_user_option() {
# Alias for --arm, cross build.
--cross-build) SRS_CROSS_BUILD=YES ;;
--arm) SRS_CROSS_BUILD=YES ;;
--mips) SRS_CROSS_BUILD=YES ;;
--with-arm-ubuntu12) SRS_CROSS_BUILD=YES ;;
--without-arm-ubuntu12) SRS_CROSS_BUILD=NO ;;
--arm-ubuntu12) SRS_CROSS_BUILD=$(switch2value $value) ;;
--with-mips-ubuntu12) SRS_CROSS_BUILD=YES ;;
--without-mips-ubuntu12) SRS_CROSS_BUILD=NO ;;
--mips-ubuntu12) SRS_CROSS_BUILD=$(switch2value $value) ;;
# Deprecated, might be removed in future.
--with-nginx) SRS_NGINX=YES ;;
@ -386,11 +383,6 @@ function apply_auto_options() {
SRS_X86_X64=YES; opt="--x86-x64 $opt";
fi
# Setup the default values if not set.
if [[ $SRS_RTC == RESERVED ]]; then
SRS_RTC=YES; if [[ $SRS_CROSS_BUILD == YES ]]; then SRS_RTC=NO; fi
fi
# The SRT code in SRS requires c++11, although we build libsrt without c++11.
# TODO: FIXME: Remove c++11 code in SRT of SRS.
if [[ $SRS_SRT == YES ]]; then

View file

@ -19,6 +19,10 @@ fi
# Use isolate cache for different SRS version.
SRS_PLATFORM="${SRS_PLATFORM}-SRS4"
if [[ $SRS_CROSS_BUILD == YES ]]; then
SRS_PLATFORM="${SRS_PLATFORM}-CROSSBUILD"
fi
echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS_DIR: ${SRS_OBJS_DIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}"
# For src object files on each platform.