Skip to content

Commit a7c7683

Browse files
Copilotthawn
andcommitted
Refactor: Extract ffmpeg installation logic into reusable scripts
Co-authored-by: thawn <1308449+thawn@users.noreply.github.com>
1 parent 69cd2b9 commit a7c7683

File tree

5 files changed

+93
-91
lines changed

5 files changed

+93
-91
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Script to install ffmpeg on Linux with timeout and retry
3+
# Usage: install-ffmpeg-linux.sh
4+
5+
set -e
6+
7+
TIMEOUT_SECONDS=60
8+
URL="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz"
9+
PATTERN="ffmpeg-*-amd64-static"
10+
11+
echo "Downloading and installing ffmpeg..."
12+
13+
# Try to download and install ffmpeg with timeout
14+
if timeout "$TIMEOUT_SECONDS" wget -q "$URL" && \
15+
timeout "$TIMEOUT_SECONDS" tar -xf ffmpeg-release-amd64-static.tar.xz; then
16+
sudo mv ${PATTERN}/ffmpeg /usr/local/bin/
17+
sudo mv ${PATTERN}/ffprobe /usr/local/bin/
18+
rm -rf ${PATTERN}*
19+
echo "ffmpeg installed successfully on first attempt"
20+
else
21+
echo "First attempt failed or timed out, retrying..."
22+
# Clean up any partial downloads
23+
rm -rf ${PATTERN}* 2>/dev/null || true
24+
# Retry with timeout
25+
if timeout "$TIMEOUT_SECONDS" wget -q "$URL" && \
26+
timeout "$TIMEOUT_SECONDS" tar -xf ffmpeg-release-amd64-static.tar.xz; then
27+
sudo mv ${PATTERN}/ffmpeg /usr/local/bin/
28+
sudo mv ${PATTERN}/ffprobe /usr/local/bin/
29+
rm -rf ${PATTERN}*
30+
echo "ffmpeg installed successfully on second attempt"
31+
else
32+
echo "ffmpeg installation failed after 2 attempts"
33+
exit 1
34+
fi
35+
fi
36+
37+
# Verify installation
38+
ffmpeg -version | head -n1
39+
echo "ffmpeg installation complete"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Script to install ffmpeg on macOS with timeout and retry
3+
# Usage: install-ffmpeg-macos.sh <target_dir>
4+
# Example: install-ffmpeg-macos.sh lib/mac
5+
6+
set -e
7+
8+
TARGET_DIR="${1:-lib/mac}"
9+
TIMEOUT_SECONDS=60
10+
URL="https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip"
11+
12+
echo "Downloading and installing ffmpeg for macOS..."
13+
14+
# Function to attempt download and extraction
15+
attempt_install() {
16+
local TEMP_DIR=$(mktemp -d)
17+
cd "$TEMP_DIR"
18+
19+
if timeout "$TIMEOUT_SECONDS" wget -q "$URL" -O ffmpeg.zip && \
20+
timeout "$TIMEOUT_SECONDS" unzip -q ffmpeg.zip; then
21+
chmod +x ffmpeg
22+
mv ffmpeg "$GITHUB_WORKSPACE/$TARGET_DIR/ffmpeg"
23+
cd "$GITHUB_WORKSPACE"
24+
chmod -R u+w "$TEMP_DIR" || true
25+
rm -rf "$TEMP_DIR"
26+
return 0
27+
else
28+
cd "$GITHUB_WORKSPACE"
29+
chmod -R u+w "$TEMP_DIR" || true
30+
rm -rf "$TEMP_DIR"
31+
return 1
32+
fi
33+
}
34+
35+
# First attempt
36+
if attempt_install; then
37+
echo "ffmpeg downloaded successfully on first attempt"
38+
else
39+
echo "First attempt failed or timed out, retrying..."
40+
# Retry
41+
if attempt_install; then
42+
echo "ffmpeg downloaded successfully on second attempt"
43+
else
44+
echo "ffmpeg installation failed after 2 attempts"
45+
exit 1
46+
fi
47+
fi
48+
49+
# Verify installation
50+
"$GITHUB_WORKSPACE/$TARGET_DIR/ffmpeg" -version | head -n1
51+
echo "ffmpeg installation complete"

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,7 @@ jobs:
8282
tttool --help || { echo "Error: tttool installation failed"; exit 1; }
8383
8484
- name: Install ffmpeg (static build)
85-
run: |
86-
# Try to download and install ffmpeg with 60 second timeout
87-
if timeout 60 wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
88-
timeout 60 tar -xf ffmpeg-release-amd64-static.tar.xz; then
89-
sudo mv ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/
90-
sudo mv ffmpeg-*-amd64-static/ffprobe /usr/local/bin/
91-
rm -rf ffmpeg-*-amd64-static*
92-
echo "ffmpeg installed successfully on first attempt"
93-
else
94-
echo "First attempt failed or timed out, retrying..."
95-
# Clean up any partial downloads
96-
rm -rf ffmpeg-*-amd64-static* 2>/dev/null || true
97-
# Retry with 60 second timeout
98-
if timeout 60 wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
99-
timeout 60 tar -xf ffmpeg-release-amd64-static.tar.xz; then
100-
sudo mv ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/
101-
sudo mv ffmpeg-*-amd64-static/ffprobe /usr/local/bin/
102-
rm -rf ffmpeg-*-amd64-static*
103-
echo "ffmpeg installed successfully on second attempt"
104-
else
105-
echo "ffmpeg installation failed after 2 attempts"
106-
exit 1
107-
fi
108-
fi
85+
run: .github/scripts/install-ffmpeg-linux.sh
10986

11087
- name: Install Python dependencies
11188
run: |

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,7 @@ jobs:
9090
tttool --help || { echo "Error: tttool installation failed"; exit 1; }
9191
9292
- name: Install ffmpeg (static build)
93-
run: |
94-
# Try to download and install ffmpeg with 60 second timeout
95-
if timeout 60 wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
96-
timeout 60 tar -xf ffmpeg-release-amd64-static.tar.xz; then
97-
sudo mv ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/
98-
sudo mv ffmpeg-*-amd64-static/ffprobe /usr/local/bin/
99-
rm -rf ffmpeg-*-amd64-static*
100-
echo "ffmpeg installed successfully on first attempt"
101-
else
102-
echo "First attempt failed or timed out, retrying..."
103-
# Clean up any partial downloads
104-
rm -rf ffmpeg-*-amd64-static* 2>/dev/null || true
105-
# Retry with 60 second timeout
106-
if timeout 60 wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
107-
timeout 60 tar -xf ffmpeg-release-amd64-static.tar.xz; then
108-
sudo mv ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/
109-
sudo mv ffmpeg-*-amd64-static/ffprobe /usr/local/bin/
110-
rm -rf ffmpeg-*-amd64-static*
111-
echo "ffmpeg installed successfully on second attempt"
112-
else
113-
echo "ffmpeg installation failed after 2 attempts"
114-
exit 1
115-
fi
116-
fi
93+
run: .github/scripts/install-ffmpeg-linux.sh
11794

11895
- name: Install Python dependencies
11996
run: |

.github/workflows/release-executables.yml

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -226,49 +226,7 @@ jobs:
226226
}
227227
228228
- name: Download ffmpeg for macOS
229-
run: |
230-
echo "Downloading ffmpeg for macOS"
231-
232-
# Create temp directory for extraction
233-
TEMP_DIR=$(mktemp -d)
234-
cd "$TEMP_DIR"
235-
236-
# Try to download and extract ffmpeg with 60 second timeout
237-
if timeout 60 wget -q "https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip" -O ffmpeg.zip && \
238-
timeout 60 unzip -q ffmpeg.zip; then
239-
# Move binary to lib/mac
240-
chmod +x ffmpeg
241-
mv ffmpeg "$GITHUB_WORKSPACE/lib/mac/ffmpeg"
242-
echo "ffmpeg downloaded successfully on first attempt"
243-
else
244-
echo "First attempt failed or timed out, retrying..."
245-
# Clean up any partial downloads
246-
cd "$GITHUB_WORKSPACE"
247-
chmod -R u+w "$TEMP_DIR" || true
248-
rm -rf "$TEMP_DIR"
249-
# Create new temp directory
250-
TEMP_DIR=$(mktemp -d)
251-
cd "$TEMP_DIR"
252-
# Retry with 60 second timeout
253-
if timeout 60 wget -q "https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip" -O ffmpeg.zip && \
254-
timeout 60 unzip -q ffmpeg.zip; then
255-
# Move binary to lib/mac
256-
chmod +x ffmpeg
257-
mv ffmpeg "$GITHUB_WORKSPACE/lib/mac/ffmpeg"
258-
echo "ffmpeg downloaded successfully on second attempt"
259-
else
260-
echo "ffmpeg installation failed after 2 attempts"
261-
exit 1
262-
fi
263-
fi
264-
265-
# Cleanup temp directory - change permissions first to ensure deletion succeeds
266-
cd "$GITHUB_WORKSPACE"
267-
chmod -R u+w "$TEMP_DIR" || true
268-
rm -rf "$TEMP_DIR"
269-
270-
# Verify
271-
lib/mac/ffmpeg -version
229+
run: .github/scripts/install-ffmpeg-macos.sh lib/mac
272230

273231
- name: Build macOS executable with PyInstaller
274232
run: |

0 commit comments

Comments
 (0)