diff --git a/ffmpeg/tst-build.sh b/ffmpeg/tst-build.sh new file mode 100755 index 0000000000000000000000000000000000000000..ba2378572464b83043d56f54512601d653139b7e --- /dev/null +++ b/ffmpeg/tst-build.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +# Desc: 编译测试工具 +# Args: +# $1 -- g_install_dir,可选参数,指定工具安装路径 +# 说明: +# 编译脚本是名字固定为tst-build.sh的bash脚本 +# 如果不指定参数g_install_dir,那么默认安装在当前目录.install路径下 +# 编译失败则将.install目录重命名为.install.fail +# .install目录存在表示工具已经编译过,不再重复编译 + +g_tool_dir="$(dirname "$(realpath "$0")")" +g_install_dir="$1" + +build_dep_pkg_list=" + ffmpeg + gcc + make + nasm + dnf-utils +" + +build_tool() { + command -v ffmpeg >/dev/null 2>&1 || { echo "ERROR: ffmpeg not found in PATH"; return 1; } + command -v ffprobe >/dev/null 2>&1 || { echo "ERROR: ffprobe not found in PATH"; return 1; } + echo "system ffmpeg: $(ffmpeg -version | head -1)" + + echo "=== installing build dependencies ===" + local tmpdir spec_file + tmpdir=$(mktemp -d) || return 1 + ( + cd "$tmpdir" || exit 1 + yumdownloader --source ffmpeg || exit 1 + rpm2cpio ffmpeg-*.src.rpm | cpio -idm '*.spec' 2>/dev/null || exit 1 + ) + spec_file=$(find "$tmpdir" -maxdepth 1 -name '*.spec' | head -1) + if [ -n "$spec_file" ]; then + yum-builddep -y "$spec_file" || echo "WARNING: yum-builddep failed, configure may detect fewer features" + else + echo "WARNING: failed to extract .spec from SRPM, falling back to package name" + yum-builddep -y ffmpeg || echo "WARNING: yum-builddep failed, configure may detect fewer features" + fi + rm -rf "$tmpdir" + + cp -r "$g_tool_dir" "$g_install_dir" && cd "$g_install_dir/ffmpeg" || return 1 + + echo "=== applying patch ===" + patch -p1 < x.patch || return 1 + + echo "=== running configure ===" + local sys_flags supported + sys_flags=$(ffmpeg -version | grep '^configuration:' | sed 's/^configuration: //') + if [ -z "$sys_flags" ]; then + echo "ERROR: failed to extract configuration from 'ffmpeg -version'" + return 1 + fi + + supported=$(./configure --help | grep -oE -- '--[a-zA-Z0-9_-]+' | sort -u) + if [ -z "$supported" ]; then + echo "ERROR: failed to parse supported options from './configure --help'" + return 1 + fi + + local -a args=() + eval "args=( $sys_flags )" + + local -a filtered=() + local opt key check_key skipped=0 has_nonfree=0 has_fdk=0 has_gpl=0 + for opt in "${args[@]}"; do + key="${opt%%=*}" + [[ "$key" != --* ]] && continue + + case "$key" in + --optflags|--extra-cflags|--extra-cxxflags|--extra-objcflags|\ + --extra-ldflags|--extra-ldexeflags|--extra-ldsoflags|--extra-libs) + echo "SKIP build-env option: $key" + skipped=$((skipped + 1)) + continue ;; + esac + + local alt_key="$key" + if [[ "$key" == --enable-* ]]; then + alt_key="${key/--enable-/--disable-}" + elif [[ "$key" == --disable-* ]]; then + alt_key="${key/--disable-/--enable-}" + fi + if echo "$supported" | grep -qxF -e "$key" -e "$alt_key"; then + filtered+=( "$opt" ) + [[ "$key" == "--enable-nonfree" ]] && has_nonfree=1 + [[ "$key" == "--enable-libfdk-aac" ]] && has_fdk=1 + [[ "$key" == "--enable-gpl" ]] && has_gpl=1 + else + echo "SKIP unsupported option: $opt" + skipped=$((skipped + 1)) + fi + done + + if (( has_fdk && has_gpl && !has_nonfree )); then + echo "ADD --enable-nonfree (required by --enable-libfdk-aac with --enable-gpl)" + filtered+=( "--enable-nonfree" ) + fi + + echo "configure: ${#filtered[@]} options kept, $skipped skipped" + ./configure "${filtered[@]}" || return 1 + + echo "=== building test utilities (HOSTPROGS) ===" + make SKIP_LIBS=1 -j"$(nproc)" \ + tests/audiogen tests/videogen tests/rotozoom \ + tests/tiny_psnr tests/tiny_ssim tests/base64 tests/audiomatch \ + || return 1 +} + +# 下面代码建议保持不变 +main() { + [ -z "$g_install_dir" ] && g_install_dir="${g_tool_dir}.install" + + if [ -f "$g_install_dir" ]; then + echo "$g_install_dir not dir" + return 1 + elif [ -d "$g_install_dir" ]; then + echo "dir $g_install_dir existed, ignore rebuild" + return 0 + else + echo "build to dir $g_install_dir" + fi + + for pkg in $build_dep_pkg_list; do + rpm -q "$pkg" || yum install -y "$pkg" + done + + mkdir -p "$g_install_dir" + if build_tool; then + echo "build $g_tool_dir success, dir $g_install_dir" + return 0 + else + [ -e "${g_install_dir}.fail" ] && rm -rf "${g_install_dir}.fail" + mv "$g_install_dir" "${g_install_dir}.fail" + echo "build $g_tool_dir fail, dir $g_install_dir" + return 1 + fi +} + +main "$@" diff --git a/ffmpeg/x.patch b/ffmpeg/x.patch new file mode 100644 index 0000000000000000000000000000000000000000..2916f14a20e7f12e8ae75496c18ac7a1810afeb3 --- /dev/null +++ b/ffmpeg/x.patch @@ -0,0 +1,70 @@ +diff --git a/Makefile b/Makefile +index 01c04d6bba..e8acf8b290 100644 +--- a/Makefile ++++ b/Makefile +@@ -129,12 +129,16 @@ include $(SRC_PATH)/$(1)/Makefile + include $(SRC_PATH)/ffbuild/library.mak + endef + ++ifndef SKIP_LIBS + $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D)))) + + include $(SRC_PATH)/fftools/Makefile ++endif # !SKIP_LIBS ++ + include $(SRC_PATH)/doc/Makefile + include $(SRC_PATH)/doc/examples/Makefile + ++ifndef SKIP_LIBS + $(ALLFFLIBS:%=lib%/version.o): libavutil/ffversion.h + + $(PROGS): %$(PROGSSUF)$(EXESUF): %$(PROGSSUF)_g$(EXESUF) +@@ -148,6 +152,7 @@ endif + + %$(PROGSSUF)_g$(EXESUF): $(FF_DEP_LIBS) + $(call LINK,$(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)) ++endif # !SKIP_LIBS + + VERSION_SH = $(SRC_PATH)/ffbuild/version.sh + ifeq ($(VERSION_TRACKING),yes) +diff --git a/tests/Makefile b/tests/Makefile +index 4b3fa6a54a..a1b2c3d4e5 100644 +--- a/tests/Makefile ++++ b/tests/Makefile +@@ -359,5 +359,24 @@ testclean:: + + include $(SRC_PATH)/tests/checkasm/Makefile + ++ifdef SKIP_LIBS ++# Use system ffmpeg/ffprobe, create stub libraries for deps ++ffmpeg$(PROGSSUF)$(EXESUF): ++ @echo "SYSLINK ffmpeg (using system binary)" ++ @cp -f $$(which ffmpeg) $@ ++ ++ffprobe$(PROGSSUF)$(EXESUF): ++ @echo "SYSLINK ffprobe (using system binary)" ++ @cp -f $$(which ffprobe) $@ ++ ++$(FF_DEP_LIBS): ++ @echo "STUB $@" ++ @mkdir -p $$(dir $@) && ar rcs $@ ++ ++$(FF_STATIC_DEP_LIBS): ++ @echo "STUB $@" ++ @mkdir -p $$(dir $@) && ar rcs $@ ++endif ++ + .PHONY: fate* lcov lcov-reset + .INTERMEDIATE: coverage.info +diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak +index a1b2c3d4e5..f6g7h8i9j0 100644 +--- a/tests/fate/checkasm.mak ++++ b/tests/fate/checkasm.mak +@@ -94,6 +94,8 @@ $(FATE_CHECKASM): tests/checkasm/checkasm$(EXESUF) + $(FATE_CHECKASM): CMD = run tests/checkasm/checkasm$(EXESUF) --test=$(@:fate-checkasm-%=%) + $(FATE_CHECKASM): CMP = null + ++ifndef SKIP_LIBS + FATE += $(FATE_CHECKASM) ++endif + fate-checkasm: $(FATE_CHECKASM)