-
Notifications
You must be signed in to change notification settings - Fork 461
/
install_ffmpeg.sh
112 lines (99 loc) · 3.97 KB
/
install_ffmpeg.sh
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
#!/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_alpine=false
if [[ "$OS_NAME" == "Linux" ]]; then
if grep -q "Ubuntu" /etc/os-release; then
is_ubuntu=true
elif [[ -f /etc/alpine-release ]]; then
is_alpine=true
fi
fi
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
# Check if ffmpeg library is linked to x86_64-linux-gnu and copy it to /usr/local/lib
if ldd ${PREFIX}/bin/ffmpeg | grep x86_64-linux-gnu | cut -d ' ' -f 3 | grep -q . ; then
ldd ${PREFIX}/bin/ffmpeg | grep x86_64-linux-gnu | cut -d ' ' -f 3 | xargs -i cp -p {} /usr/local/lib/
fi
# 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
# Check if ffmpeg library is linked to opt/ffmpeg and copy it to /usr/local/lib
if ldd ${PREFIX}/bin/ffmpeg | grep opt/ffmpeg | cut -d ' ' -f 3 | grep -q . ; then
ldd ${PREFIX}/bin/ffmpeg | grep opt/ffmpeg | cut -d ' ' -f 3 | xargs -i cp -p {} /usr/local/lib/
fi
# Create symbolic links for shared libraries in /usr/local/lib
for lib in /usr/local/lib/*.so.*; do
ln -sf "${lib##*/}" "${lib%%.so.*}".so
done
# Copy ffmpeg binaries and share directory to /usr/local
cp -r ${PREFIX}/bin/* /usr/local/bin/
cp -r ${PREFIX}/share/ffmpeg /usr/local/share/
if [ ! -d /usr/local/include ]; then
mkdir -p /usr/local/include
fi
# Build configuration and copy include directories
LD_LIBRARY_PATH=/usr/local/lib ffmpeg -buildconf && \
cp -rp ${PREFIX}/include/libav* ${PREFIX}/include/libpostproc ${PREFIX}/include/libsw* /usr/local/include
# Create pkgconfig directory and copy and modify pkgconfig files
mkdir -p /usr/local/lib/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*; do
if [[ -f "$pc" ]]; then
# sed "s:${PREFIX}:/usr/local:g" <"$pc" >/usr/local/lib/pkgconfig/"${pc##*/}"
sed "s:${PREFIX}:/usr/local:g; s:/lib64:/lib:g" <"$pc" >/usr/local/lib/pkgconfig/"${pc##*/}"; \
else
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/
cp -r ${PREFIX}/share/ffmpeg /tmp/fakeroot/share/
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/
cp -r ${PREFIX}/share/ffmpeg /tmp/fakeroot/share/
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