Rename volume adjustment scripts

This commit is contained in:
Michael Campagnaro 2023-08-07 18:07:21 -04:00
parent bb26b8ceff
commit 27a08fb402
3 changed files with 21 additions and 21 deletions

View File

@ -1,12 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Use this to get a report on the video audio volume. You can use this info # Use this to get a volume report from a video or audio file. You can use this
# manually normalize or increase/decrease a video's volume using the # info manually normalize or increase/decrease the volume using the
# change-video-volume script, supplying it the volume delta you want. Typically # change-volume script, supplying it the volume delta you want. Typically you
# you use the delta from the analysis report this script provides, e.g. if the # use the delta from the analysis report this script provides, e.g. if the
# max_volume is -5 db then you would call change-video-volume with a value of # max_volume is -5 db then you would call change-volume with a value of 5. I
# 5. I find that the two pass normalize-video-audio script works better than # find that the two pass normalize-audio script works better than this
# this approach...but it will take longer to run! # approach...but it will take longer to run!
# #
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885 # Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
@ -34,7 +34,7 @@ else
fi fi
if [[ $1 == "" ]]; then if [[ $1 == "" ]]; then
printf "${BOLD}${RED}Usage: analyze-video-volume <video filename>${NORMAL}\n" printf "${BOLD}${RED}Usage: analyze-volume <video or audio filename>${NORMAL}\n"
exit 1 exit 1
fi fi
@ -48,5 +48,5 @@ printf "\n${BOLD}Running: $cmd\n\n${NORMAL}"
eval $cmd eval $cmd
printf "\n${GREEN}${BOLD}Done analyzing audio in $filename\n${NORMAL}" printf "\n${GREEN}${BOLD}Done analyzing audio in $filename\n${NORMAL}"
printf "\n${YELLOW}${BOLD}Look at the reported max_volume value. If != 0 then call the change-video-volume script, passing it the filename, an output name and the delta to bring the volume to 0.\ne.g. if the max_volume is -5 db, then you would pass 5.${NORMAL}\n\n" printf "\n${YELLOW}${BOLD}Look at the reported max_volume value. If != 0 then call the change-volume script, passing it the filename, an output name and the delta to bring the volume to 0.\ne.g. if the max_volume is -5 db, then you would pass 5.${NORMAL}\n\n"

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Re-encodes the audio, modify the volume based on the supplied db delta. The # Re-encodes the audio, modify the volume based on the supplied db delta. If
# video is copied as-is. If you want to bring the max_volume to 0 db then call # given a video file then the file is copied as-is. If you want to bring the
# analyze-video-volume prior to this and pass a delta based on the reported # max_volume to 0 db then call analyze-volume prior to this and pass a delta
# max_volume. # based on the reported max_volume.
# #
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885 # Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
@ -31,7 +31,7 @@ else
fi fi
if [[ $1 == "" ]]; then if [[ $1 == "" ]]; then
printf "${BOLD}${RED}Usage: change-video-volume <filename> <output name> <volume delta in db>${NORMAL}\n" printf "${BOLD}${RED}Usage: change-volume <video or audio filename> <output name> <volume delta in db>${NORMAL}\n"
exit 1 exit 1
fi fi

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Use this to normalize the audio of a video using the average loudness, or RMS-based normalization. It does a pretty good job! # Use this to normalize the volume of a video or audio file using the average loudness, or RMS-based normalization. It does a pretty good job!
# If you want to modify the volume yourself then checkout the analyze-video-volume and change-video-volume scripts. # If you want to modify the volume manually then checkout the analyze-volume and change-volume scripts.
# #
# This does not re-encode the video. # This does not re-encode video when given a video file.
# #
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885 # Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
@ -31,7 +31,7 @@ else
fi fi
if [[ $1 == "" ]]; then if [[ $1 == "" ]]; then
printf "${BOLD}${RED}Usage: normalize-video-volume <filename> <optional output name>${NORMAL}\n" printf "${BOLD}${RED}Usage: normalize-volume <video or audio filename> <optional output name>${NORMAL}\n"
exit 1 exit 1
fi fi
@ -57,9 +57,9 @@ temp_file="/tmp/_audio_info_$RANDOM"
# 1st pass: # 1st pass:
cmd="ffmpeg -i \"$filename.$extension\" -pass 1 -filter:a loudnorm=print_format=json -vn -sn -dn -f null /dev/null 2>&1 | sed -n '/{/,/}/p' > $temp_file" cmd="ffmpeg -i \"$filename.$extension\" -pass 1 -filter:a loudnorm=print_format=json -vn -sn -dn -f null /dev/null 2>&1 | sed -n '/{/,/}/p' > $temp_file"
printf "\n${BOLD}Running 1st pass:\n$cmd\n\n${NORMAL}" printf "\n${BOLD}Running 1st pass:\n$cmd\n\n${NORMAL}"
eval $cmd eval "$cmd"
printf "\n${BOLD}${GREEN}Done.\n\n${NORMAL}" printf "${BOLD}${GREEN}Done.\n\n${NORMAL}"
ii=`grep \"input_i\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-` ii=`grep \"input_i\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-`
itp=`grep \"input_tp\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-` itp=`grep \"input_tp\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-`
@ -70,7 +70,7 @@ to=`grep \"target_offset\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-`
# 2nd pass: # 2nd pass:
cmd="ffmpeg -y -stats -loglevel level+error -i \"$filename.$extension\" -c:v copy -pass 2 -filter:a loudnorm=linear=true:I=-16:LRA=11:tp=-1.5:measured_I=$ii:measured_LRA=$ilra:measured_tp=$itp:measured_thresh=$it:offset=$to:print_format=summary -map 0 \"$output\"" cmd="ffmpeg -y -stats -loglevel level+error -i \"$filename.$extension\" -c:v copy -pass 2 -filter:a loudnorm=linear=true:I=-16:LRA=11:tp=-1.5:measured_I=$ii:measured_LRA=$ilra:measured_tp=$itp:measured_thresh=$it:offset=$to:print_format=summary -map 0 \"$output\""
printf "${BOLD}Re-encoding audio:\n$cmd\n\n${NORMAL}" printf "${BOLD}Re-encoding audio:\n$cmd\n\n${NORMAL}"
eval $cmd eval "$cmd"
printf "\n${GREEN}${BOLD}Done normalizing volume in $filename.$extension | output: $output${NORMAL}\n" printf "\n${GREEN}${BOLD}Done normalizing volume in $filename.$extension | output: $output${NORMAL}\n"
rm $temp_file rm $temp_file