-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-ffmpeg-static.sh
executable file
·225 lines (197 loc) · 7.59 KB
/
install-ffmpeg-static.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# This script will install the latest static nightly build of ffmpeg on Ubuntu
echo "************************************************"
echo "************************************************"
echo "**** FFMPEG STATIC INSTALL SCRIPT"
echo "**** This script installs latest ffmpeg git master build from https://johnvansickle.com/ffmpeg/"
echo "**** See: https://github.com/jontybrook/ffmpeg-install-script"
echo "**** Author: [email protected]"
echo "************************************************"
echo "************************************************"
echo "Starting ffmpeg static install script..."
# Check if sudo is required so we can adapt the script accordingly.
# In docker build contexts, sudo is usually not required nor installed. To support this use case,
# if sudo is not installed, the script will run the commands without sudo.
echo "Checking if sudo is required"
if hash sudo 2>/dev/null; then
echo "sudo is installed. The script will use sudo where required."
sudo_required=true
else
echo "sudo is not installed. The script will run commands without sudo."
sudo_required=false
fi
# Check that md5sum and wget are installed
echo "Checking that md5sum and wget are installed"
if ! hash md5sum 2>/dev/null; then
echo "md5sum is not installed. Please install it using 'sudo apt-get install md5sum'"
echo "The script will now exit"
exit 1
fi
# Create a temporary directory
temp_dir=$(mktemp -d)
echo "Temporary directory is: $temp_dir"
# Remember pwd so we can cd back to it later
previousWorkingDirectory=$(pwd)
# create and cd into /tmp/ffmpeg-install
echo "Creating and navigating to /tmp/ffmpeg-install directory"
mkdir -p $temp_dir/ffmpeg-install
cd $temp_dir/ffmpeg-install
# Find the architecture of the system
echo "Finding the architecture of the system"
# Get the architecture using uname
arch=$(uname -m)
# Map the uname output to your required format
architecture=""
case $arch in
x86_64)
echo "Detected amd64 architecture. The appropriate ffmpeg build will be downloaded"
architecture="amd64"
;;
i686 | i386)
echo "Detected i686 architecture. The appropriate ffmpeg build will be downloaded"
architecture="i686"
;;
armv6l | armv7l)
echo "Detected armhf architecture. The appropriate ffmpeg build will be downloaded"
architecture="armhf"
;;
aarch64)
echo "Detected arm64 architecture. The appropriate ffmpeg build will be downloaded"
architecture="arm64"
;;
*)
echo "!!!!!!!!!!!!"
echo "FFMPEG INSTALL FAILED: Unknown architecture: $arch"
echo "This script only works on amd64, i686, armhf and arm64 architectures"
echo "The script will now exit"
echo "!!!!!!!!!!!!"
echo "FFMPEG INSTALL FAILED: Unknown architecture: $arch" >&2
cd $previousWorkingDirectory # cd back to the previous working directory
exit 1
;;
esac
# If --stable is passed as an argument, install the latest release build of ffmpeg
# otherwise install the latest static 'git master' build of ffmpeg
buildVersion="git"
buildDownloadUrlPrefix="https://johnvansickle.com/ffmpeg/builds"
if [[ $1 == "--stable" ]] || [[ $2 == "--stable" ]]; then
buildVersion="release"
buildDownloadUrlPrefix="https://johnvansickle.com/ffmpeg/releases"
echo "Installing the latest stable build of ffmpeg"
fi
# Download the latest static nightly build of ffmpeg
echo "Downloading the latest $buildVersion build of ffmpeg"
if $sudo_required; then
sudo wget "$buildDownloadUrlPrefix/ffmpeg-$buildVersion-$architecture-static.tar.xz"
else
wget "$buildDownloadUrlPrefix/ffmpeg-$buildVersion-$architecture-static.tar.xz"
fi
# Download the md5 checksum file
echo "Downloading the md5 checksum file..."
if $sudo_required; then
sudo wget "$buildDownloadUrlPrefix/ffmpeg-$buildVersion-$architecture-static.tar.xz.md5"
else
wget "$buildDownloadUrlPrefix/ffmpeg-$buildVersion-$architecture-static.tar.xz.md5"
fi
# Verify the checksum
echo "Verifying the checksum of the downloaded file.."
if ! md5sum -c ffmpeg-$buildVersion-$architecture-static.tar.xz.md5; then
echo "MD5 checksum verification failed. The downloaded file may be corrupted."
echo "The script will now exit."
cd $previousWorkingDirectory # cd back to the previous working directory
exit 1
fi
# Unpack the build
echo "Unpacking the build.."
tar -xvf $temp_dir/ffmpeg-install/ffmpeg-$buildVersion-$architecture-static.tar.xz -C $temp_dir/ffmpeg-install/
# Find the directory name of the unpacked build (it changes with each nightly build) and cd into it.
# The format is ffmpeg-git-YYYYMMDD-amd64-static
echo "Navigating to the unpacked build directory"
cd $temp_dir/ffmpeg-install/ffmpeg-*-*/
# Cat out the readme so we can log it during builds that use this script
echo "Displaying the contents of readme.txt"
cat readme.txt
# ! Important note - From readme.txt in version ffmpeg-git-20231128-amd64-static...
# "A limitation of statically linking glibc is the loss of DNS resolution. Installing
# nscd through your package manager will fix this."
# Install nscd
echo "Installing nscd"
if $sudo_required; then
sudo apt-get install nscd
else
apt-get install nscd
fi
# Check if FFmpeg is installed using apt
if dpkg -s ffmpeg &>/dev/null; then
echo "FFmpeg is already installed using apt"
if [[ $1 == "--force" ]]; then
echo "Removing ffmpeg..."
if $sudo_required; then
sudo apt-get remove ffmpeg
else
apt-get remove ffmpeg
fi
else
read -p "Do you want to remove it? (y/n): " answer
if [[ $answer == "y" ]]; then
echo "Removing ffmpeg..."
if $sudo_required; then
sudo apt-get remove ffmpeg
else
apt-get remove ffmpeg
fi
fi
fi
fi
# Check if ffmpeg is installed via some other method
if hash ffmpeg 2>/dev/null; then
echo "ffmpeg is already installed at $(which ffmpeg)"
if [[ $1 == "--force" ]]; then
echo "Removing ffmpeg..."
if $sudo_required; then
sudo rm $(which ffmpeg)
else
rm $(which ffmpeg)
fi
else
read -p "Do you want to remove it? (y/n): " answer
if [[ $answer == "y" ]]; then
echo "Removing ffmpeg..."
if $sudo_required; then
sudo rm $(which ffmpeg)
else
rm $(which ffmpeg)
fi
fi
fi
fi
# Copy the ffmpeg and ffprobe binaries to /usr/local/bin
echo "Copying ffmpeg and ffprobe binaries to /usr/local/bin"
if $sudo_required; then
sudo cp ffmpeg ffprobe /usr/local/bin
else
cp ffmpeg ffprobe /usr/local/bin
fi
# Check if the ffmpeg and ffprobe binaries copied successfully
if hash ffmpeg 2>/dev/null; then
echo "ffmpeg is now installed at $(which ffmpeg)"
else
echo "!!!!!!!!!!!!"
echo "FFMPEG INSTALL FAILED: ffmpeg is not installed"
echo "The script will now exit"
echo "!!!!!!!!!!!!"
echo "FFMPEG INSTALL FAILED: ffmpeg is not installed" >&2
exit 1
fi
cd $previousWorkingDirectory # cd back to the previous working directory
echo "Cleaning up temproary directory $temp_dir"
rm -rf $temp_dir
# Check the version of ffmpeg
echo "************************************************"
echo "** ffmpeg installation complete"
echo "** You should see the version of ffmpeg installed printed out below (ffmpeg -version)"
echo "************************************************"
ffmpeg -version
echo "************************************************"
echo "** ffmpeg static install script finished"
echo "************************************************"