Skip to content

Instantly share code, notes, and snippets.

@0xallie
Last active February 28, 2020 06:36
Show Gist options
  • Save 0xallie/46ae469ca9e5b6d22009348cd7afa299 to your computer and use it in GitHub Desktop.
Save 0xallie/46ae469ca9e5b6d22009348cd7afa299 to your computer and use it in GitHub Desktop.
Generate ffmpeg command to crossfade audio files
#!/usr/bin/env bash
duration=$1
shift
if ! [[ "$duration" =~ ^[0-9]+$ ]]; then
printf '%s: error: first argument must be an integer (crossfade duration in seconds)\n' "$0" >&2
exit 1
fi
if [[ "$#" -lt 2 ]]; then
printf '%s: error: at least 2 inputs required for crossfade\n' "$0" >&2
exit 1
fi
crossfade_filter="acrossfade=d=${duration}:c1=exp:c2=exp"
filter_str="[0:0][1:0]${crossfade_filter}"
printf 'ffmpeg -i %q -i %q ' "$1" "$2"
let i=3
for f in "${@:3}"; do
printf -- '-i %q ' "$f"
let b=i-2
let a=b+1
filter_str="${filter_str}[tmp${b}];[tmp${b}][${a}:0]${crossfade_filter}"
let i++
done
printf -- '-filter_complex "%s[out]" -map "[out]"\n' "$filter_str"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment