Skip to content

Commit a77bca0

Browse files
committed
Add rpath fixups to Mac non-GPL FFmpeg build
1 parent ec24944 commit a77bca0

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

.github/workflows/build_ffmpeg.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
# per new major release of FFmepg.
1010
name: Build non-GPL FFmpeg from source
1111

12+
#on:
13+
# workflow_dispatch:
14+
# schedule:
15+
# - cron: '0 0 * * 0' # on sunday
16+
1217
on:
13-
workflow_dispatch:
14-
schedule:
15-
- cron: '0 0 * * 0' # on sunday
18+
push:
19+
branches: [ main ]
20+
pull_request:
21+
1622

1723
defaults:
1824
run:

packaging/build_ffmpeg.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,90 @@ tar -xf ffmpeg.tar.gz --strip-components 1
6464

6565
make -j install
6666
ls ${prefix}/*
67+
68+
# macos: Fix rpath so that the libraries are searched dynamically in user environment.
69+
# In Linux, this is handled by `--enable-rpath` flag.
70+
if [[ "$(uname)" == Darwin ]]; then
71+
ffmpeg_version="${FFMPEG_VERSION:-4.1.8}"
72+
major_ver=${ffmpeg_version:0:1}
73+
if [[ ${major_ver} == 4 ]]; then
74+
avutil=libavutil.56
75+
avcodec=libavcodec.58
76+
avformat=libavformat.58
77+
avdevice=libavdevice.58
78+
avfilter=libavfilter.7
79+
elif [[ ${major_ver} == 5 ]]; then
80+
avutil=libavutil.57
81+
avcodec=libavcodec.59
82+
avformat=libavformat.59
83+
avdevice=libavdevice.59
84+
avfilter=libavfilter.8
85+
elif [[ ${ffmpeg_version} == master || ${major_ver} == 6 ]]; then
86+
avutil=libavutil.58
87+
avcodec=libavcodec.60
88+
avformat=libavformat.60
89+
avdevice=libavdevice.60
90+
avfilter=libavfilter.9
91+
else
92+
printf "Error: unexpected FFmpeg major version: %s\n" ${major_ver}
93+
exit 1;
94+
fi
95+
96+
otool="/usr/bin/otool"
97+
# NOTE: miniconda has a version of otool and install_name_tool installed and we want
98+
# to use the default sytem version instead of the miniconda version since the miniconda
99+
# version can produce inconsistent results
100+
101+
# Attempt to use /usr/bin/otool as our default otool
102+
if [[ ! -e ${otool} ]]; then
103+
otool="$(which otool)"
104+
fi
105+
install_name_tool="/usr/bin/install_name_tool"
106+
# Attempt to use /usr/bin/install_name_tool as our default install_name_tool
107+
if [[ ! -e ${install_name_tool} ]]; then
108+
install_name_tool="$(which install_name_tool)"
109+
fi
110+
111+
# list up the paths to fix
112+
for lib in ${avcodec} ${avdevice} ${avfilter} ${avformat} ${avutil}; do
113+
${otool} -l ${prefix}/lib/${lib}.dylib | grep -B2 ${prefix}
114+
done
115+
116+
# Replace the hardcoded paths to @rpath
117+
${install_name_tool} \
118+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
119+
-delete_rpath ${prefix}/lib \
120+
-id @rpath/${avcodec}.dylib \
121+
${prefix}/lib/${avcodec}.dylib
122+
${otool} -l ${prefix}/lib/${avcodec}.dylib | grep -B2 ${prefix}
123+
124+
${install_name_tool} \
125+
-change ${prefix}/lib/${avformat}.dylib @rpath/${avformat}.dylib \
126+
-change ${prefix}/lib/${avcodec}.dylib @rpath/${avcodec}.dylib \
127+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
128+
-delete_rpath ${prefix}/lib \
129+
-id @rpath/${avdevice}.dylib \
130+
${prefix}/lib/${avdevice}.dylib
131+
${otool} -l ${prefix}/lib/${avdevice}.dylib | grep -B2 ${prefix}
132+
133+
${install_name_tool} \
134+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
135+
-delete_rpath ${prefix}/lib \
136+
-id @rpath/${avfilter}.dylib \
137+
${prefix}/lib/${avfilter}.dylib
138+
${otool} -l ${prefix}/lib/${avfilter}.dylib | grep -B2 ${prefix}
139+
140+
${install_name_tool} \
141+
-change ${prefix}/lib/${avcodec}.dylib @rpath/${avcodec}.dylib \
142+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
143+
-delete_rpath ${prefix}/lib \
144+
-id @rpath/${avformat}.dylib \
145+
${prefix}/lib/${avformat}.dylib
146+
${otool} -l ${prefix}/lib/${avformat}.dylib | grep -B2 ${prefix}
147+
148+
${install_name_tool} \
149+
-delete_rpath ${prefix}/lib \
150+
-id @rpath/${avutil}.dylib \
151+
${prefix}/lib/${avutil}.dylib
152+
${otool} -l ${prefix}/lib/${avutil}.dylib | grep -B2 ${prefix}
153+
fi

0 commit comments

Comments
 (0)