Created
February 27, 2024 14:30
-
-
Save freddydumont/b1d7bbc07a7bdb559f5a048c6c23f095 to your computer and use it in GitHub Desktop.
ffmpeg script to pad the start of an audio file with silence for a 1h total
This file contains 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
#!/bin/bash | |
output_folder="padded_audio" | |
mkdir -p "$output_folder" | |
# Function to pad audio file and preserve metadata | |
function pad_audio() { | |
input_file=$1 | |
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input_file") | |
if (( $(bc <<< "$duration < 3600") )); then | |
pad_duration=$(bc <<< "3600 - $duration") | |
output_file="$output_folder/padded_$input_file" | |
ffmpeg -i "$input_file" -f lavfi -i "aevalsrc=0:d=${pad_duration}" -filter_complex "[1:a][0:a]concat=n=2:v=0:a=1[a]" -map 0:v -map "[a]" -map_metadata 0 "$output_file" | |
else | |
echo "File $input_file is already one hour or longer. Skipping." | |
fi | |
} | |
# Process audio files one by one | |
for file in *.mp3; do | |
pad_audio "$file" | |
done | |
echo "Padding process completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment