-
Notifications
You must be signed in to change notification settings - Fork 488
Expand file tree
/
Copy pathinstall_ffmpeg.sh
More file actions
executable file
·128 lines (113 loc) · 4.19 KB
/
install_ffmpeg.sh
File metadata and controls
executable file
·128 lines (113 loc) · 4.19 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
#!/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
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
GNU_ARCH="x86_64-linux-gnu"
CUDA_ARCH="x86_64-linux"
elif [ "$ARCH" = "aarch64" ]; then
GNU_ARCH="aarch64-linux-gnu"
CUDA_ARCH="sbsa-linux"
else
GNU_ARCH="${ARCH}-linux-gnu"
CUDA_ARCH="${ARCH}-linux"
fi
if ldd ${PREFIX}/bin/ffmpeg | grep ${GNU_ARCH} | cut -d ' ' -f 3 | grep -q . ; then
ldd ${PREFIX}/bin/ffmpeg | grep ${GNU_ARCH} | cut -d ' ' -f 3 | xargs -i cp -p {} /usr/local/lib/
fi
if [[ -d /usr/local/cuda/targets/${CUDA_ARCH}/lib/ ]]; then
cp -p /usr/local/cuda/targets/${CUDA_ARCH}/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
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 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/${GNU_ARCH}/pkgconfig/libvmaf*; do
if [[ -f "$pc" ]]; then
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