From 159c8cff90fbc3af56a0d5f23cae19343f8dcba0 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Sun, 19 May 2024 17:28:41 -0400 Subject: [PATCH] Improve ffmpeg audio fix scripts --- ...annel => copy-left-audio-channel-to-right} | 11 ++-- dotfiles/bin/copy-right-audio-channel-to-left | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) rename dotfiles/bin/{fix-audio-in-one-channel => copy-left-audio-channel-to-right} (61%) create mode 100644 dotfiles/bin/copy-right-audio-channel-to-left diff --git a/dotfiles/bin/fix-audio-in-one-channel b/dotfiles/bin/copy-left-audio-channel-to-right similarity index 61% rename from dotfiles/bin/fix-audio-in-one-channel rename to dotfiles/bin/copy-left-audio-channel-to-right index 613afc1..bfa2128 100644 --- a/dotfiles/bin/fix-audio-in-one-channel +++ b/dotfiles/bin/copy-left-audio-channel-to-right @@ -1,7 +1,6 @@ #!/usr/bin/env bash -# Use this to fix the audio of a video that has audio in only the left or right -# channel. This does not re-encode the video. +# Use this to copy audio from the left channel to the right. This does not re-encode the video. if which tput >/dev/null 2>&1; then ncolors=$(tput colors) @@ -27,7 +26,7 @@ else fi if [[ $1 == "" ]]; then - printf "${BOLD}${RED}Usage: fix-audio-in-one-channel ${NORMAL}\n" + printf "${BOLD}${RED}Usage: copy-left-audio-channel-to-right ${NORMAL}\n" exit 1 fi @@ -43,9 +42,9 @@ else output="${output_name}.$extension" fi -printf "\n${YELLOW}${BOLD}Repairing audio in $filename.$extension | output: $output${NORMAL}\n" +printf "\n${YELLOW}${BOLD}Copy left audio channeel to right channel in $filename.$extension | output: $output${NORMAL}\n" -ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:v copy -ac 1 -map 0 "$output" +ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:v copy -af "pan=stereo|c0=c0|c1=c0" -map 0 "$output" -printf "\n${GREEN}${BOLD}Done repairing audio in $filename.$extension | output: $output${NORMAL}\n\n" +printf "\n${GREEN}${BOLD}Done copying left audio channel to right channel in $filename.$extension | output: $output${NORMAL}\n\n" diff --git a/dotfiles/bin/copy-right-audio-channel-to-left b/dotfiles/bin/copy-right-audio-channel-to-left new file mode 100644 index 0000000..5dd874a --- /dev/null +++ b/dotfiles/bin/copy-right-audio-channel-to-left @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Use this to copy audio from the right channel to the left. This does not re-encode the video. + +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) +fi +if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + MAGENTA="$(tput setaf 5)" + CYAN="$(tput setaf 6)" + BOLD="$(tput bold)" + NORMAL="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + MAGENTA="" + CYAN="" + BOLD="" + NORMAL="" +fi + +if [[ $1 == "" ]]; then + printf "${BOLD}${RED}Usage: copy-right-audio-channel-to-left ${NORMAL}\n" + exit 1 +fi + +filename=$(basename -- "$1") +extension="${filename##*.}" +filename="${filename%.*}" + +output_name="$2" + +if [[ $output_name == "" ]]; then + output="${filename}_repaired_audio.$extension" +else + output="${output_name}.$extension" +fi + +printf "\n${YELLOW}${BOLD}Copy right audio channeel to left channel in $filename.$extension | output: $output${NORMAL}\n" + +ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:v copy -af "pan=stereo|c0=c1|c1=c1" -map 0 "$output" + +printf "\n${GREEN}${BOLD}Done copying right audio channel to left channel in $filename.$extension | output: $output${NORMAL}\n\n" +