-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_ffmpeg.sh
More file actions
executable file
·159 lines (143 loc) · 5.26 KB
/
Copy pathinstall_ffmpeg.sh
File metadata and controls
executable file
·159 lines (143 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# Stop execution on any error
# Note: we can override this in the Dockerfile RUN command with an || true.
# which is useful for debugging
set -e
strip_libs=false
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--strip)
strip_libs=true
shift 1
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
OS_NAME=$(uname -s)
is_ubuntu=false
is_fedora=false
is_alpine=false
if [[ "$OS_NAME" == "Linux" ]]; then
if grep -q "Ubuntu" /etc/os-release; then
is_ubuntu=true
elif grep -q "Fedora" /etc/os-release; then
is_fedora=true
elif [[ -f /etc/alpine-release ]]; then
is_alpine=true
fi
fi
copy_linked_libs_by_path() {
local pattern=$1
local destination=$2
mapfile -t libs < <(ldd "${PREFIX}/bin/ffmpeg" | awk '{print $3}' | grep '^/' | grep "$pattern" | sort -u)
if [[ ${#libs[@]} -eq 0 ]]; then
return
fi
mkdir -p "$destination"
for lib in "${libs[@]}"; do
if [[ -f "$lib" ]]; then
cp -p "$lib" "$destination/"
fi
done
}
install_ffmpeg() {
echo "Installing ffmpeg"
## cleanup
# This is used for both the source and packages version ( be robust about looking for libs to copy )
if [ ! -f ${PREFIX}/bin/ffmpeg ]; then
echo "ERROR: ffmpeg not found in ${PREFIX}/bin"
exit 1
fi
mkdir -p /usr/local/lib /usr/local/lib64
if $is_ubuntu; then
copy_linked_libs_by_path "x86_64-linux-gnu" /usr/local/lib
fi
if $is_fedora; then
copy_linked_libs_by_path "/usr/lib64" /usr/local/lib64
copy_linked_libs_by_path "/lib64" /usr/local/lib64
fi
copy_linked_libs_by_path "${PREFIX}/lib64" /usr/local/lib64
copy_linked_libs_by_path "${PREFIX}/lib" /usr/local/lib
# some nvidia libs are in the cuda targets directory
if [[ -d /usr/local/cuda/targets/x86_64-linux/lib/ ]]; then
cp -p /usr/local/cuda/targets/x86_64-linux/lib/libnpp* /usr/local/lib
fi
# Create symbolic links for shared libraries in /usr/local/lib
for libdir in /usr/local/lib /usr/local/lib64; do
if compgen -G "${libdir}/lib*.so.*" > /dev/null; then
for lib in "${libdir}"/*.so.*; do
[ -e "$lib" ] || continue
ln -sf "${lib##*/}" "${lib%%.so.*}".so
done
fi
done
# Copy ffmpeg binaries and share directory to /usr/local
cp -r ${PREFIX}/bin/* /usr/local/bin/
if [ -d "${PREFIX}/share/ffmpeg" ]; then cp -r ${PREFIX}/share/ffmpeg /usr/local/share/; fi
if [ ! -d /usr/local/include ]; then
mkdir -p /usr/local/include
fi
# Build configuration and copy include directories
LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib ffmpeg -buildconf
for lib in ${PREFIX}/include/libav* ${PREFIX}/include/libpostproc ${PREFIX}/include/libsw*; do
if [[ -d "$lib" ]]; then
cp -rp "$lib" /usr/local/include/
else
echo "Warning: Directory '$lib' not found."
fi
done
# Create pkgconfig directories and copy and modify pkgconfig files
mkdir -p /usr/local/lib/pkgconfig /usr/local/lib64/pkgconfig
for pc in \
${PREFIX}/lib/pkgconfig/libav*.pc \
${PREFIX}/lib/pkgconfig/libpostproc.pc \
${PREFIX}/lib/pkgconfig/kvazaar.pc \
${PREFIX}/lib/pkgconfig/libsw*.pc \
${PREFIX}/lib/x86_64-linux-gnu/pkgconfig/libvmaf* \
${PREFIX}/lib64/pkgconfig/libav*.pc \
${PREFIX}/lib64/pkgconfig/libpostproc.pc \
${PREFIX}/lib64/pkgconfig/kvazaar.pc \
${PREFIX}/lib64/pkgconfig/libsw*.pc \
${PREFIX}/lib64/pkgconfig/libvmaf*; do
if [[ -f "$pc" ]]; then
if [[ "$pc" == *"/lib64/pkgconfig/"* ]]; then
sed "s:${PREFIX}:/usr/local:g" "$pc" > /usr/local/lib64/pkgconfig/"${pc##*/}"
else
sed "s:${PREFIX}:/usr/local:g" "$pc" > /usr/local/lib/pkgconfig/"${pc##*/}"
fi
else
# glob might not expand, so warn only if file literally missing
[[ "$pc" == *"*"* ]] || echo "Warning: File '$pc' not found."
fi
done
}
fakeroot_install_with_striped_libs() {
echo "Installing ffmpeg with fakeroot and striped libs"
mkdir -p /tmp/fakeroot/lib
ldd ${PREFIX}/bin/ffmpeg | cut -d ' ' -f 3 | strings | xargs -I R cp R /tmp/fakeroot/lib/
for lib in /tmp/fakeroot/lib/*; do strip --strip-all $lib; done
cp -r ${PREFIX}/bin /tmp/fakeroot/bin/
if [ -d "${PREFIX}/share/ffmpeg" ]; then cp -r ${PREFIX}/share/ffmpeg /tmp/fakeroot/share/; fi
LD_LIBRARY_PATH=/tmp/fakeroot/lib /tmp/fakeroot/bin/ffmpeg -buildconf
}
fakeroot_install() {
echo "Using fakeroot to install ffmpeg"
mkdir -p /tmp/fakeroot/lib
ldd ${PREFIX}/bin/ffmpeg | cut -d ' ' -f 3 | strings | xargs -I R cp R /tmp/fakeroot/lib/
cp -r ${PREFIX}/bin /tmp/fakeroot/bin/
if [ -d "${PREFIX}/share/ffmpeg" ]; then cp -r ${PREFIX}/share/ffmpeg /tmp/fakeroot/share/; fi
LD_LIBRARY_PATH=/tmp/fakeroot/lib /tmp/fakeroot/bin/ffmpeg -buildconf
}
# if strip_libs is true then call the install_with_striped_libs function
# else if is_alpine is true then call the fakeroot_install function
if $strip_libs; then
fakeroot_install_with_striped_libs
elif $is_alpine; then
fakeroot_install
else
install_ffmpeg
fi