Created
January 19, 2026 14:38
-
-
Save mauryaratan/6cd551db2ca01d33ab83232336a500ff to your computer and use it in GitHub Desktop.
A function expanded a given audio/video up to 2 hours using FFMPEG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| expand() { | |
| local file="$1" | |
| local filename="${file%.*}" | |
| local extension="${file##*.}" | |
| # Convert extension to lowercase using 'tr' (works on Mac & Linux) | |
| local ext_lower=$(echo "$extension" | tr '[:upper:]' '[:lower:]') | |
| local duration | |
| local loops | |
| # 1. Get duration in seconds | |
| duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file") | |
| # 2. Calculate loops needed to exceed 2 hours (7200 seconds) | |
| loops=$(echo "$duration" | awk '{print int(7200/$1) + 1}') | |
| echo "Input length: $duration sec | Loops: $loops" | |
| # 3. Logic check: wav/mp3 -> flac, others -> copy original | |
| if [[ "$ext_lower" == "wav" || "$ext_lower" == "mp3" ]]; then | |
| # Audio Mode: Convert to FLAC (48kHz) | |
| ffmpeg -stream_loop "$loops" -i "$file" -c:a flac -ar 48000 "${filename}-expanded.flac" | |
| else | |
| # Video/Other Mode: Stream copy | |
| ffmpeg -stream_loop "$loops" -i "$file" -c copy "${filename}-expanded.${extension}" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment