Skip to content

Commit eefdbc3

Browse files
Fix: FFmpeg build script undefined behavior
FFmpeg build script was using 'git am' to apply patches, which lead to undefined behavior if the script was already running in a directory with git or where patches were already applied. Remove the need for git altogether to avoid future issues.
1 parent 7e39939 commit eefdbc3

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

.github/actions/build/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ runs:
4040
gstreamer1.0-tools \
4141
gstreamer1.0-libav \
4242
libgstreamer1.0-dev \
43-
libgstreamer-plugins-base1.0-dev
43+
libgstreamer-plugins-base1.0-dev \
44+
patch \
45+
unzip
4446
shell: bash
4547
- name: 'installation: Build mtl'
4648
run: |

.github/scripts/setup_environment.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ function setup_ubuntu_install_dependencies() {
175175
if [ "${ECOSYSTEM_BUILD_AND_INSTALL_FFMPEG_PLUGIN}" == "1" ]; then
176176
echo "Installing FFMPEG dependencies"
177177
apt install -y \
178-
nasm
178+
nasm \
179+
unzip \
180+
patch
179181
fi
180182

181183
if [ "${ECOSYSTEM_BUILD_AND_INSTALL_GSTREAMER_PLUGIN}" == "1" ]; then

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ _temp*
100100
gpu_offline_install
101101

102102
# Ecosystem
103-
script/FFmpeg
103+
FFmpeg-release-*
104104
script/dpdk_*
105105
ecosystem/librist/librsit
106106
ecosystem/msdk/MediaSDK
107107
tools/readpcap/readpcap_*
108108
swig
109-
openh264
109+
openh264*
110110
level-zero-*

ecosystem/ffmpeg_plugin/build.sh

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55

66
set -e
77

8-
# Default values
9-
ffmpeg_ver="7.0"
108
enable_gpu=false
119
script_path="$(dirname "$(readlink -f "$0")")"
10+
VERSIONS_ENV_PATH="$(dirname "$(readlink -qe "${BASH_SOURCE[0]}")")/../../versions.env"
11+
12+
if [ -f "$VERSIONS_ENV_PATH" ]; then
13+
# shellcheck disable=SC1090
14+
. "$VERSIONS_ENV_PATH"
15+
else
16+
echo -e "Error: versions.env file not found at $VERSIONS_ENV_PATH"
17+
exit 1
18+
fi
1219

1320
# Help message function
1421
usage() {
1522
echo "Usage: $0 [options]"
1623
echo "Options:"
17-
echo " -v <version> Specify the FFmpeg version to build (default is $ffmpeg_ver)"
24+
echo " -v <version> Specify the FFmpeg version to build (default is $FFMPEG_VERSION)"
1825
echo " -g Enable GPU direct mode during compilation"
1926
echo " -h Display this help and exit"
2027
}
@@ -23,7 +30,7 @@ usage() {
2330
while getopts ":v:hg" opt; do
2431
case "${opt}" in
2532
v)
26-
ffmpeg_ver=${OPTARG}
33+
FFMPEG_VERSION=${OPTARG}
2734
;;
2835
g)
2936
enable_gpu=true
@@ -45,23 +52,47 @@ while getopts ":v:hg" opt; do
4552
done
4653

4754
build_openh264() {
48-
rm -rf openh264
49-
git clone https://github.com/cisco/openh264.git
50-
cd openh264
51-
git checkout openh264v2.4.0
55+
if command -v pkg-config >/dev/null 2>&1; then
56+
if pkg-config --exists openh264; then
57+
echo "openh264 is already installed (detected by pkg-config). Skipping build."
58+
return
59+
fi
60+
else
61+
echo "Warning: pkg-config not found. Skipping openh264 installation check."
62+
fi
63+
64+
if [ -d "openh264-openh264v2.4.0" ]; then
65+
echo "openh264v2.4.0 directory already exists. Removing it to ensure a clean build."
66+
rm -rf openh264-openh264v2.4.0
67+
fi
68+
69+
wget https://github.com/cisco/openh264/archive/refs/heads/openh264v2.4.0.zip
70+
unzip openh264v2.4.0.zip && rm -f openh264v2.4.0.zip
71+
cd openh264-openh264v2.4.0
5272
make -j "$(nproc)"
5373
sudo make install
5474
sudo ldconfig
5575
cd ../
5676
}
5777

5878
build_ffmpeg() {
59-
rm -rf FFmpeg
60-
git clone https://github.com/FFmpeg/FFmpeg.git
61-
cd FFmpeg
62-
git checkout release/"$ffmpeg_ver"
79+
if [ -d "FFmpeg-release-${FFMPEG_VERSION}" ]; then
80+
echo "FFmpeg directory already exists. Removing it to ensure a clean build."
81+
rm -rf "FFmpeg-release-${FFMPEG_VERSION}"
82+
fi
83+
84+
wget "https://github.com/FFmpeg/FFmpeg/archive/refs/heads/release/${FFMPEG_VERSION}.zip"
85+
unzip "${FFMPEG_VERSION}.zip" && rm -f "${FFMPEG_VERSION}.zip"
86+
87+
cd "FFmpeg-release-${FFMPEG_VERSION}"
6388
cp -f "$script_path"/mtl_* ./libavdevice/
64-
git am "$script_path"/"$ffmpeg_ver"/*.patch
89+
90+
for patch_file in "$script_path"/"$FFMPEG_VERSION"/*.patch; do
91+
if [ -f "$patch_file" ]; then
92+
echo "Applying patch: $(basename "$patch_file")"
93+
patch -p1 <"$patch_file"
94+
fi
95+
done
6596

6697
if [ "$enable_gpu" = true ]; then
6798
echo "Building with MTL_GPU_DIRECT_ENABLED"
@@ -80,4 +111,4 @@ build_ffmpeg() {
80111
build_openh264
81112
build_ffmpeg
82113

83-
echo "Building ffmpeg $ffmpeg_ver plugin is finished"
114+
echo "Building ffmpeg $FFMPEG_VERSION plugin is finished"

versions.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ICE_DMID=859252
44
ONE_API_GPU_VER=1.22.3
55
LIBRIST_COMMIT_VER=9f09a3defd6e59839aae3e3b7b5411213fa04b8a
66
RUST_HOOK_CARGO_VER=0.5.5
7+
FFMPEG_VERSION=7.0
78

89
DPDK_REPO=https://github.com/dpdk/dpdk/archive/refs/tags/v${DPDK_VER}.tar.gz
910
ICE_REPO=https://downloadmirror.intel.com/${ICE_DMID}/ice-${ICE_VER}.tar.gz

0 commit comments

Comments
 (0)