Skip to content

Instantly share code, notes, and snippets.

@Jubjub
Last active February 2, 2021 14:10
Show Gist options
  • Save Jubjub/79c32cf84fb1fc1e9f5f03305f170b84 to your computer and use it in GitHub Desktop.
Save Jubjub/79c32cf84fb1fc1e9f5f03305f170b84 to your computer and use it in GitHub Desktop.
A script to synchronize a movie and a commentary with auto ducking. Uses only ffmpeg.
#!/bin/sh
if [ $# -eq 0 ]
then
echo "usage: ./commentary_sync.sh movie commentary subtitle"
exit
fi
ffmpeg -i "$1" -vn -acodec copy audio.aac
ffmpeg -i audio.aac -i "$2" -filter_complex "[1:a]asplit=2[sc][mix];[0:a][sc]sidechaincompress=threshold=0.1:ratio=3[bg]; [bg][mix]amerge[final]" -map [final] final.aac
ffmpeg -i "$1" -i final.aac -i "$3" -c copy -map 0:v:0 -map 1:a:0 -map 2:s:0 synchronized.mkv
rm audio.aac
rm final.aac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment