ffmpeg-effect: handle input files without an audio track - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 3f0d1a63bf72da4943bb830d8ca7d86c6b4a8586 DIR parent c4bdefe72c60a62c55e32acaa0f240fe1f88633c HTML Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Tue, 22 Jun 2021 22:08:15 +0200 ffmpeg-effect: handle input files without an audio track when no audio track is present, add one from the overlay Signed-off-by: Annna Robert-Houdin <annna@bitreich.org> Diffstat: M ffmpeg-effect | 45 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) --- DIR diff --git a/ffmpeg-effect b/ffmpeg-effect @@ -15,20 +15,43 @@ usage() { exit 1 } -mix_audio() { - $ffmpeg_common -i "$2" -i "$1" \ - -filter_complex "amerge=inputs=2" \ +has_audio() { + ffprobe "$1" 2>&1 | grep -qE 'Stream .* Audio: ' +} + +replace_audio() { + $ffmpeg_common -i "$1" -i "$2" \ + -c:v copy -map 1:v:0 -map 0:a:0 -shortest \ "$3" </dev/null } +mix_audio() { + if has_audio "$2"; then + $ffmpeg_common -i "$1" -i "$2" \ + -filter_complex "amerge=inputs=2" \ + "$3" </dev/null + else + replace_audio "$1" "$2" "$3" + fi +} + mix_audio_video() { - $ffmpeg_common -i "$2" \ - -i "$1" \ - -filter_complex " - [0:v] scale=w=${4:-1920}:h=${5:-1080}, pad=w=${4:-1920}:h=${5:-1080} [video0]; - [video0][1:v] blend=all_mode=average:shortest=1; - amix=inputs=2:duration=shortest:weights=3 2" \ - "$3" </dev/null + if has_audio "$2"; then + $ffmpeg_common -i "$2" \ + -i "$1" \ + -filter_complex " + [0:v] scale=w=${4:-1920}:h=${5:-1080}, pad=w=${4:-1920}:h=${5:-1080} [video0]; + [video0][1:v] blend=all_mode=average:shortest=1; + amix=inputs=2:duration=shortest:weights=3 2" \ + "$3" </dev/null + else + $ffmpeg_common -i "$2" \ + -i "$1" \ + -filter_complex " + [0:v] scale=w=${4:-1920}:h=${5:-1080}, pad=w=${4:-1920}:h=${5:-1080} [video0]; + [video0][1:v] blend=all_mode=average:shortest=1" \ + "$3" </dev/null + fi } process_filter() { @@ -70,7 +93,7 @@ process_filter() { sexify) mix_audio "${mediadir}/careless_whisper.mp3" "$2" "$3";; doomify) - mix_audio "$2" "${mediadir}/doom.mp3" "$3";; + mix_audio "${mediadir}/doom.mp3" "$2" "$3";; scrollify) mix_audio "${mediadir}/elder_scrolls.mp3" "$2" "$3";; sendtohell|amsterdamify)