ffmpeg 跨平台编译

Signed-off-by: wang_wei <liuwei793@h-partners.com>
Change-Id: If56ebbe040a925491abfc21bc0b15c7b280b6c66
This commit is contained in:
wang_wei 2024-06-12 10:51:30 +08:00
parent 5825b2e392
commit fd4f2dc74d
4 changed files with 533 additions and 4 deletions

View File

@ -7,6 +7,7 @@ print("current_cpu = ${current_cpu}")
print("current_os = ${current_os}") print("current_os = ${current_os}")
print("host_os = ${host_os}") print("host_os = ${host_os}")
print("is_mingw = ${is_mingw}") print("is_mingw = ${is_mingw}")
is_cross_platform_build = defined(is_arkui_x) && is_arkui_x
ffmpeg_selected_platform = "" ffmpeg_selected_platform = ""
if (current_cpu == "arm64" && current_os == "ohos") { if (current_cpu == "arm64" && current_os == "ohos") {
@ -1678,10 +1679,18 @@ ohos_source_set("ffmpeg_dynamic") {
} }
action("gen_config_header") { action("gen_config_header") {
script = "//third_party/ffmpeg/ohos_config.sh" if (current_os == "ios") {
script = "//third_party/ffmpeg/ios_config.sh"
if (ffmpeg_selected_platform == "aarch64") { } else if (current_os == "android" && host_os == "mac") {
deps = [ "//third_party/musl:musl_libs" ] script = "//third_party/ffmpeg/android_mac_config.sh"
} else {
script = "//third_party/ffmpeg/ohos_config.sh"
}
if (!is_cross_platform_build) {
if (ffmpeg_selected_platform == "aarch64") {
print("third_party:ffmpeg # deps //third_party/musl:musl_libs")
deps = [ "//third_party/musl:musl_libs" ]
}
} }
ucc = "false" ucc = "false"
@ -1713,3 +1722,16 @@ ohos_shared_library("libohosffmpeg") {
cflags = [ "-Wno-array-parameter" ] cflags = [ "-Wno-array-parameter" ]
ldflags = ldflags_asm ldflags = ldflags_asm
} }
ohos_static_library("libohosffmpeg_static") {
sanitize = {
integer_overflow = true
boundary_sanitize = true
}
deps = [ ":ffmpeg_dynamic" ]
public_configs = [ ":libohosffmpeg_public_config" ]
part_name = "ffmpeg"
subsystem_name = "thirdparty"
cflags = [ "-Wno-array-parameter" ]
ldflags = ldflags_asm
}

250
android_mac_config.sh Executable file
View File

@ -0,0 +1,250 @@
# FFmpeg build configure
#!/bin/bash
set -ex
FFMPEG_PATH=$1
FFMPEG_OUT_PATH=$2
FFMPEG_PLAT=$3
LLVM_PATH=$4
SYSROOT_PATH=$5
USE_CLANG_COVERAGE=$6
oldPath=`pwd`
FFMPEG_PATH=${oldPath}/${FFMPEG_PATH}
FFMPEG_OUT_PATH=${oldPath}/${FFMPEG_OUT_PATH}
currentPath=${oldPath}/${FFMPEG_OUT_PATH}tmp
mkdir -p ${currentPath}
cd ${currentPath}
if [ ${FFMPEG_PLAT} = "aarch64" ]; then
FF_CONFIG_OPTIONS="
--arch=aarch64
--target-os=linux
--disable-programs
--disable-avdevice
--disable-postproc
--disable-avfilter
--disable-network
--disable-dwt
--disable-faan
--disable-pixelutils
--disable-bsfs
--disable-encoders
--disable-decoders
--disable-hwaccels
--disable-muxers
--disable-demuxers
--disable-parsers
--disable-protocols
--disable-devices
--disable-filters
--disable-doc
--disable-debug
--disable-iconv
--disable-stripping
--disable-vaapi
--disable-vdpau
--disable-zlib
--disable-xlib
--disable-cuvid
--disable-cuda
--disable-libxcb
--disable-libxcb_shm
--disable-libxcb_shape
--disable-libxcb_xfixes
--disable-sdl2
--disable-bzlib
--disable-lzma
--disable-vulkan
--enable-demuxer=mp3,aac,ape,flac,ogg,wav,mov,mpegts,amr,amrnb,amrwb,matroska,flv,mpegps
--enable-muxer=mp4,h264,ipod,amr
--enable-parser=h263,h264,mpeg4video,vp8,vp9,mpegvideo
--enable-parser=mpegaudio,aac,aac_latm,av3a,amr
--enable-decoder=h263,h264,mpeg2video,mpeg4,vp8,vp9
--enable-decoder=mp3,mp3float,aac,aac_latm,ape,flac,vorbis,opus,amrnb,amrwb
--enable-decoder=png,bmp
--enable-encoder=aac,aac_latm,opus,flac
--enable-encoder=mpeg4,h263
--enable-bsf=h264_mp4toannexb
--enable-protocol=file
--enable-cross-compile
--enable-shared
--enable-lsp
--cc=${LLVM_PATH}/bin/clang
--ld=${LLVM_PATH}/bin/clang
--strip=${LLVM_PATH}/bin/llvm-strip
"
EXTRA_CFLAGS="
--target=aarch64-linux-ohos
--sysroot=${SYSROOT_PATH}
"
EXTRA_LDFLAGS="
--target=aarch64-linux-ohos
--sysroot=${SYSROOT_PATH}
"
if [ ${USE_CLANG_COVERAGE} = "true" ]; then
EXTRA_CFLAGS="
--target=aarch64-linux-ohos
--sysroot=${SYSROOT_PATH}
--coverage
-mllvm
-limited-coverage-experimental=true
"
EXTRA_LDFLAGS="
--target=aarch64-linux-ohos
--sysroot=${SYSROOT_PATH}
--coverage
-fno-use-cxa-atexit
"
fi
FF_CONFIG_OPTIONS=`echo $FF_CONFIG_OPTIONS`
${FFMPEG_PATH}/configure ${FF_CONFIG_OPTIONS} --extra-cflags="${EXTRA_CFLAGS}" --extra-ldflags="${EXTRA_LDFLAGS}"
else
FF_CONFIG_OPTIONS="
--disable-programs
--disable-avdevice
--disable-postproc
--disable-avfilter
--disable-network
--disable-dwt
--disable-faan
--disable-pixelutils
--disable-bsfs
--disable-encoders
--disable-decoders
--disable-hwaccels
--disable-muxers
--disable-demuxers
--disable-parsers
--disable-protocols
--disable-devices
--disable-filters
--disable-asm
--disable-doc
--disable-debug
--disable-iconv
--disable-stripping
--disable-vaapi
--disable-vdpau
--disable-zlib
--disable-xlib
--disable-cuvid
--disable-cuda
--disable-libxcb
--disable-libxcb_shm
--disable-libxcb_shape
--disable-libxcb_xfixes
--disable-sdl2
--disable-bzlib
--disable-lzma
--enable-demuxer=mp3,aac,ape,flac,ogg,wav,mov,mpegts,amr,amrnb,amrwb,matroska,flv,mpegps
--enable-muxer=mp4,h264,ipod,amr
--enable-parser=h263,h264,mpeg4video,vp8,vp9,mpegvideo
--enable-parser=mpegaudio,aac,aac_latm,av3a,amr
--enable-decoder=h263,h264,mpeg2video,mpeg4,vp8,vp9
--enable-decoder=mp3,mp3float,aac,aac_latm,ape,flac,vorbis,opus,amrnb,amrwb
--enable-decoder=png,bmp
--enable-encoder=aac,aac_latm,opus,flac
--enable-encoder=mpeg4,h263
--enable-bsf=h264_mp4toannexb
--enable-protocol=file
--enable-lsp
"
FF_CONFIG_OPTIONS=`echo $FF_CONFIG_OPTIONS`
${FFMPEG_PATH}/configure ${FF_CONFIG_OPTIONS}
fi
sed -i '' 's/HAVE_SYSCTL 1/HAVE_SYSCTL 0/g' config.h
sed -i '' 's/HAVE_MACH_ABSOLUTE_TIME 1/HAVE_MACH_ABSOLUTE_TIME 0/g' config.h
sed -i '' 's/HAVE_SYSCTL=yes/!HAVE_SYSCTL=yes/g' ./ffbuild/config.mak
sed -i '' 's/HAVE_GLOB 1/HAVE_GLOB 0/g' config.h
sed -i '' 's/HAVE_GLOB=yes/!HAVE_GLOB=yes/g' config.h
sed -i '' 's/HAVE_GMTIME_R 1/HAVE_GMTIME_R 0/g' config.h
sed -i '' 's/HAVE_LOCALTIME_R 1/HAVE_LOCALTIME_R 0/g' config.h
sed -i '' 's/HAVE_PTHREAD_CANCEL 1/HAVE_PTHREAD_CANCEL 0/g' config.h
sed -i '' 's/HAVE_VALGRIND_VALGRIND_H 1/HAVE_VALGRIND_VALGRIND_H 0/g' config.h
tmp_file=".tmpfile"
## remove invalid restrict define
sed 's/#define av_restrict restrict/#define av_restrict/' ./config.h >$tmp_file
mv $tmp_file ./config.h
## replace original FFMPEG_CONFIGURATION define with $FF_CONFIG_OPTIONS
sed '/^#define FFMPEG_CONFIGURATION/d' ./config.h >$tmp_file
mv $tmp_file ./config.h
total_line=`wc -l ./config.h | sed -e 's/^[ \t]*//g' | cut -d ' ' -f 1`
tail_line=`expr $total_line - 3`
head -3 config.h > $tmp_file
echo "#define FFMPEG_CONFIGURATION \"${FF_CONFIG_OPTIONS}\"" >> $tmp_file
tail -$tail_line config.h >> $tmp_file
mv $tmp_file ./config.h
rm -f config.err
## rm BUILD_ROOT information
sed '/^BUILD_ROOT=/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^CC=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^AS=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^LD=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^DEPCC=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
sed -i '' 's/restrict restrict/restrict /g' config.h
sed -i '' '/getenv(x)/d' config.h
sed -i '' 's/HAVE_DOS_PATHS 0/HAVE_DOS_PATHS 1/g' config.h
mv config.h ${FFMPEG_OUT_PATH}/config.h
mv ./ffbuild/config.mak ${FFMPEG_OUT_PATH}/config.mak
rm -rf ${FFMPEG_OUT_PATH}/libavcodec
mv -f libavcodec ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavformat
mv -f libavformat ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavutil
mv -f libavutil ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavdevice
mv -f libavdevice ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavfilter
mv -f libavfilter ${FFMPEG_OUT_PATH}
rm -rf ./ffbuild
cd $oldPath
rm -rf ${currentPath}
## other work need to be done manually
cat <<!EOF
#####################################################
****NOTICE****
You need to modify the file config.mak and delete
all full path string in macro:
SRC_PATH, SRC_PATH_BARE, BUILD_ROOT, LDFLAGS.
Please refer to the old version of config.mak to
check how to modify it.
#####################################################
!EOF

249
ios_config.sh Executable file
View File

@ -0,0 +1,249 @@
# FFmpeg build configure
#!/bin/bash
set -ex
FFMPEG_PATH=$1
FFMPEG_OUT_PATH=$2
FFMPEG_PLAT=$3
LLVM_PATH=$4
SYSROOT_PATH=$5
USE_CLANG_COVERAGE=$6
oldPath=`pwd`
FFMPEG_PATH=${oldPath}/${FFMPEG_PATH}
FFMPEG_OUT_PATH=${oldPath}/${FFMPEG_OUT_PATH}
currentPath=${oldPath}/${FFMPEG_OUT_PATH}tmp
mkdir -p ${currentPath}
cd ${currentPath}
if [ ${FFMPEG_PLAT} = "aarch64" ]; then
FF_CONFIG_OPTIONS="
--arch=aarch64
--target-os=darwin
--disable-programs
--disable-avdevice
--disable-postproc
--disable-avfilter
--disable-network
--disable-dwt
--disable-faan
--disable-pixelutils
--disable-bsfs
--disable-encoders
--disable-decoders
--disable-hwaccels
--disable-muxers
--disable-demuxers
--disable-parsers
--disable-protocols
--disable-devices
--disable-filters
--disable-doc
--disable-debug
--disable-iconv
--disable-stripping
--disable-vaapi
--disable-vdpau
--disable-zlib
--disable-xlib
--disable-cuvid
--disable-cuda
--disable-libxcb
--disable-libxcb_shm
--disable-libxcb_shape
--disable-libxcb_xfixes
--disable-sdl2
--disable-bzlib
--disable-lzma
--disable-vulkan
--enable-demuxer=mp3,aac,ape,flac,ogg,wav,mov,mpegts,amr,amrnb,amrwb,matroska
--enable-muxer=mp4,h264,ipod
--enable-parser=h263,h264,mpeg4video,vp8,vp9,mpegvideo
--enable-parser=mpegaudio,aac,aac_latm,av3a,amr
--enable-decoder=h263,h264,mpeg2video,mpeg4,vp8,vp9
--enable-decoder=mp3,mp3float,aac,aac_latm,ape,flac,vorbis,opus,amrnb,amrwb
--enable-decoder=png,bmp
--enable-encoder=aac,aac_latm,opus,flac
--enable-encoder=mpeg4,h263
--enable-bsf=h264_mp4toannexb
--enable-protocol=file
--enable-cross-compile
--enable-shared
--enable-lsp
--cc=${LLVM_PATH}/bin/clang
--ld=${LLVM_PATH}/bin/clang
--strip=${LLVM_PATH}/bin/llvm-strip
"
EXTRA_CFLAGS="
--target=aarch64-darwin
--sysroot=${SYSROOT_PATH}
"
EXTRA_LDFLAGS="
--target=aarch64-darwin
--sysroot=${SYSROOT_PATH}
"
if [ ${USE_CLANG_COVERAGE} = "true" ]; then
EXTRA_CFLAGS="
--target=aarch64-darwin
--sysroot=${SYSROOT_PATH}
--coverage
-mllvm
-limited-coverage-experimental=true
"
EXTRA_LDFLAGS="
--target=aarch64-darwin
--sysroot=${SYSROOT_PATH}
--coverage
-fno-use-cxa-atexit
"
fi
FF_CONFIG_OPTIONS=`echo $FF_CONFIG_OPTIONS`
${FFMPEG_PATH}/configure ${FF_CONFIG_OPTIONS} --extra-cflags="${EXTRA_CFLAGS}" --extra-ldflags="${EXTRA_LDFLAGS}"
else
FF_CONFIG_OPTIONS="
--disable-programs
--disable-avdevice
--disable-postproc
--disable-avfilter
--disable-network
--disable-dwt
--disable-faan
--disable-pixelutils
--disable-bsfs
--disable-encoders
--disable-decoders
--disable-hwaccels
--disable-muxers
--disable-demuxers
--disable-parsers
--disable-protocols
--disable-devices
--disable-filters
--disable-asm
--disable-doc
--disable-debug
--disable-iconv
--disable-stripping
--disable-vaapi
--disable-vdpau
--disable-zlib
--disable-xlib
--disable-cuvid
--disable-cuda
--disable-libxcb
--disable-libxcb_shm
--disable-libxcb_shape
--disable-libxcb_xfixes
--disable-sdl2
--disable-bzlib
--disable-lzma
--enable-demuxer=mp3,aac,ape,flac,ogg,wav,mov,mpegts,amr,amrnb,amrwb,matroska
--enable-muxer=mp4,h264,ipod
--enable-parser=h263,h264,mpeg4video,vp8,vp9,mpegvideo
--enable-parser=mpegaudio,aac,aac_latm,av3a,amr
--enable-decoder=h263,h264,mpeg2video,mpeg4,vp8,vp9
--enable-decoder=mp3,mp3float,aac,aac_latm,ape,flac,vorbis,opus,amrnb,amrwb
--enable-decoder=png,bmp
--enable-encoder=aac,aac_latm,opus,flac
--enable-encoder=mpeg4,h263
--enable-bsf=h264_mp4toannexb
--enable-protocol=file
--enable-lsp
"
FF_CONFIG_OPTIONS=`echo $FF_CONFIG_OPTIONS`
${FFMPEG_PATH}/configure ${FF_CONFIG_OPTIONS}
fi
sed -i '' 's/HAVE_SYSCTL 1/HAVE_SYSCTL 0/g' config.h
sed -i '' 's/HAVE_SYSCTL=yes/!HAVE_SYSCTL=yes/g' ./ffbuild/config.mak
sed -i '' 's/HAVE_GLOB 1/HAVE_GLOB 0/g' config.h
sed -i '' 's/HAVE_GLOB=yes/!HAVE_GLOB=yes/g' config.h
sed -i '' 's/HAVE_GMTIME_R 1/HAVE_GMTIME_R 0/g' config.h
sed -i '' 's/HAVE_LOCALTIME_R 1/HAVE_LOCALTIME_R 0/g' config.h
sed -i '' 's/HAVE_PTHREAD_CANCEL 1/HAVE_PTHREAD_CANCEL 0/g' config.h
sed -i '' 's/HAVE_VALGRIND_VALGRIND_H 1/HAVE_VALGRIND_VALGRIND_H 0/g' config.h
tmp_file=".tmpfile"
## remove invalid restrict define
sed 's/#define av_restrict restrict/#define av_restrict/' ./config.h >$tmp_file
mv $tmp_file ./config.h
## replace original FFMPEG_CONFIGURATION define with $FF_CONFIG_OPTIONS
sed '/^#define FFMPEG_CONFIGURATION/d' ./config.h >$tmp_file
mv $tmp_file ./config.h
total_line=`wc -l ./config.h | sed -e 's/^[ \t]*//g' | cut -d ' ' -f 1`
tail_line=`expr $total_line - 3`
head -3 config.h > $tmp_file
echo "#define FFMPEG_CONFIGURATION \"${FF_CONFIG_OPTIONS}\"" >> $tmp_file
tail -$tail_line config.h >> $tmp_file
mv $tmp_file ./config.h
rm -f config.err
## rm BUILD_ROOT information
sed '/^BUILD_ROOT=/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^CC=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^AS=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^LD=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
## rm amr-eabi-gcc
sed '/^DEPCC=arm-eabi-gcc/d' ./ffbuild/config.mak > $tmp_file
rm -f ./ffbuild/config.mak
mv $tmp_file ./ffbuild/config.mak
sed -i '' 's/restrict restrict/restrict /g' config.h
sed -i '' '/getenv(x)/d' config.h
sed -i '' 's/HAVE_DOS_PATHS 0/HAVE_DOS_PATHS 1/g' config.h
mv config.h ${FFMPEG_OUT_PATH}/config.h
mv ./ffbuild/config.mak ${FFMPEG_OUT_PATH}/config.mak
rm -rf ${FFMPEG_OUT_PATH}/libavcodec
mv -f libavcodec ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavformat
mv -f libavformat ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavutil
mv -f libavutil ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavdevice
mv -f libavdevice ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavfilter
mv -f libavfilter ${FFMPEG_OUT_PATH}
rm -rf ./ffbuild
cd $oldPath
rm -rf ${currentPath}
## other work need to be done manually
cat <<!EOF
#####################################################
****NOTICE****
You need to modify the file config.mak and delete
all full path string in macro:
SRC_PATH, SRC_PATH_BARE, BUILD_ROOT, LDFLAGS.
Please refer to the old version of config.mak to
check how to modify it.
#####################################################
!EOF

View File

@ -9,7 +9,13 @@ FFMPEG_PLAT=$3
LLVM_PATH=$4 LLVM_PATH=$4
SYSROOT_PATH=$5 SYSROOT_PATH=$5
USE_CLANG_COVERAGE=$6 USE_CLANG_COVERAGE=$6
oldPath=`pwd`
FFMPEG_PATH=${oldPath}/${FFMPEG_PATH}
FFMPEG_OUT_PATH=${oldPath}/${FFMPEG_OUT_PATH}
currentPath=${oldPath}/${FFMPEG_OUT_PATH}tmp
mkdir -p ${currentPath}
cd ${currentPath}
if [ ${FFMPEG_PLAT} = "aarch64" ]; then if [ ${FFMPEG_PLAT} = "aarch64" ]; then
FF_CONFIG_OPTIONS=" FF_CONFIG_OPTIONS="
@ -227,6 +233,8 @@ mv -f libavdevice ${FFMPEG_OUT_PATH}
rm -rf ${FFMPEG_OUT_PATH}/libavfilter rm -rf ${FFMPEG_OUT_PATH}/libavfilter
mv -f libavfilter ${FFMPEG_OUT_PATH} mv -f libavfilter ${FFMPEG_OUT_PATH}
rm -rf ./ffbuild rm -rf ./ffbuild
cd $oldPath
rm -rf ${currentPath}
## other work need to be done manually ## other work need to be done manually
cat <<!EOF cat <<!EOF