99runs :
1010 using : ' composite'
1111 steps :
12+ - name : Set ffmpeg install config
13+ shell : bash
14+ run : |
15+ VERSION=8.1
16+ echo "FFMPEG_VERSION=${VERSION}" >> "$GITHUB_ENV"
17+ echo "FFMPEG_ASSET=ffmpeg-${VERSION}-essentials_build.zip" >> "$GITHUB_ENV"
18+
1219 - name : Check for preinstalled ffmpeg
1320 id : check
1421 shell : bash
@@ -26,42 +33,79 @@ runs:
2633 if : ${{ steps.check.outputs.installed == 'false' && runner.os == 'Linux' }}
2734 shell : bash
2835 run : |
29- for attempt in 1 2 3; do
36+ attempts=4
37+ for attempt in $(seq 1 $attempts); do
3038 echo "apt-get attempt $attempt"
3139 if sudo apt-get update && sudo apt-get install -y ffmpeg; then
3240 exit 0
3341 fi
34- sleep 10
42+ if [ "$attempt" -lt "$attempts" ]; then
43+ delay=$(( 15 * (1 << (attempt - 1)) + RANDOM % 6 ))
44+ echo "install failed; sleeping ${delay}s before retry"
45+ sleep "$delay"
46+ fi
3547 done
36- echo "Failed to install ffmpeg via apt-get after 3 attempts" >&2
48+ echo "Failed to install ffmpeg via apt-get after $attempts attempts" >&2
3749 exit 1
3850
3951 - name : Install ffmpeg (macOS)
4052 if : ${{ steps.check.outputs.installed == 'false' && runner.os == 'macOS' }}
4153 shell : bash
4254 run : |
43- for attempt in 1 2 3; do
55+ attempts=4
56+ for attempt in $(seq 1 $attempts); do
4457 echo "brew attempt $attempt"
4558 if brew install ffmpeg; then
4659 exit 0
4760 fi
48- sleep 10
61+ if [ "$attempt" -lt "$attempts" ]; then
62+ delay=$(( 15 * (1 << (attempt - 1)) + RANDOM % 6 ))
63+ echo "install failed; sleeping ${delay}s before retry"
64+ sleep "$delay"
65+ fi
4966 done
50- echo "Failed to install ffmpeg via brew after 3 attempts" >&2
67+ echo "Failed to install ffmpeg via brew after $attempts attempts" >&2
5168 exit 1
5269
53- - name : Install ffmpeg (Windows)
70+ - name : Cache ffmpeg (Windows)
5471 if : ${{ steps.check.outputs.installed == 'false' && runner.os == 'Windows' }}
72+ id : cache-ffmpeg-windows
73+ uses : actions/cache@v4
74+ with :
75+ path : C:\ffmpeg-bin
76+ key : ffmpeg-windows-${{ env.FFMPEG_VERSION }}-v1
77+
78+ - name : Install ffmpeg (Windows)
79+ if : ${{ steps.check.outputs.installed == 'false' && runner.os == 'Windows' && steps.cache-ffmpeg-windows.outputs.cache-hit != 'true' }}
5580 shell : pwsh
81+ env :
82+ GH_TOKEN : ${{ github.token }}
5683 run : |
57- for ($attempt = 1; $attempt -le 3; $attempt++) {
58- Write-Host "choco attempt $attempt"
59- choco install ffmpeg -y --no-progress
60- if ($LASTEXITCODE -eq 0) { exit 0 }
61- Start-Sleep -Seconds 10
84+ $attempts = 4
85+ $downloaded = $false
86+ for ($attempt = 1; $attempt -le $attempts; $attempt++) {
87+ Write-Host "download attempt $attempt (GyanD/codexffmpeg $env:FFMPEG_VERSION)"
88+ gh release download $env:FFMPEG_VERSION --repo GyanD/codexffmpeg --pattern $env:FFMPEG_ASSET --clobber
89+ if ($LASTEXITCODE -eq 0) { $downloaded = $true; break }
90+ if ($attempt -lt $attempts) {
91+ $delay = [int]([math]::Pow(2, $attempt - 1) * 15) + (Get-Random -Minimum 0 -Maximum 6)
92+ Write-Host "download failed; sleeping ${delay}s before retry"
93+ Start-Sleep -Seconds $delay
94+ }
6295 }
63- Write-Error "Failed to install ffmpeg via choco after 3 attempts"
64- exit 1
96+ if (-not $downloaded) {
97+ Write-Error "Failed to download ffmpeg after $attempts attempts"
98+ exit 1
99+ }
100+ Expand-Archive -Path $env:FFMPEG_ASSET -DestinationPath ffmpeg-extract -Force
101+ New-Item -ItemType Directory -Force -Path C:\ffmpeg-bin | Out-Null
102+ Copy-Item -Path (Join-Path "ffmpeg-extract" "ffmpeg-$env:FFMPEG_VERSION-essentials_build\bin\*.exe") -Destination C:\ffmpeg-bin\
103+ Remove-Item -Recurse -Force ffmpeg-extract, $env:FFMPEG_ASSET
104+
105+ - name : Add ffmpeg to PATH (Windows)
106+ if : ${{ steps.check.outputs.installed == 'false' && runner.os == 'Windows' }}
107+ shell : pwsh
108+ run : Add-Content -Path $env:GITHUB_PATH -Value 'C:\ffmpeg-bin'
65109
66110 - name : Verify ffmpeg
67111 shell : bash
0 commit comments