forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_volume
executable file
·72 lines (63 loc) · 2.88 KB
/
fix_volume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# this script takes one argument which is a video file. It evaluates the audio of the file, determines the difference needed to change the audio to -30dB as a mean_volume and then makes that adjustment to an output MXF file. The video track is simply copied.
unset dependencies
dependencies=(ffmbc ffmbc)
# local variables
suffix="_voladj"
scriptdir=$(dirname "$0")
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
usage(){
echo
echo "$(basename $0) ${version}"
echo "This application will use an input video file to produce an output video file where the audio is adjusted to meet an integrated loudness of -23dB. If the integrated loudness of the input is already within 1dB of the target then no change will occur. The output file will be produced in the same directory as the input but be distinguished by a suffix in the filename: ${suffix}."
echo "Dependencies: ${dependencies[@]}"
echo "Usage: $(basename $0) file1 [ file2 ...]"
echo " -h display this help"
echo
exit
}
[ "$#" = 0 ] && usage
check_dependencies "${dependencies[@]}"
# command line arguments
OPTIND=1
while getopts ":h" opt ; do
case $opt in
h) usage ;;
*) echo "Invalid option: -$OPTARG" ; exit 1 ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
log -b
while [ "$*" != "" ] ; do
input_movie="$1"
name=$(basename "$1")
extension="${name#*.}"
get_codectagstring
unset ffmbc_opts
unset audio_pipe_opts
audio_pipe_opts=(-f s24le -ar 48000 -ac 2)
ffmbc_opts+=(-vcodec copy)
[ "${codec_tag_string}" = "mpeg" ] && extension="mxf"
output_movie="${input_movie%.*}${suffix}.${extension}"
if [ -f "${output_movie}" ] ; then
report -wt "The intended output of $(basename $0) already exists. Skipping for now. Please delete ${output_movie} and rerun or figure out why you are trying to do this."
else
get_volume_adjustment "${input_movie}"
if [ -n "${VOLADJ}" ] ; then
report -dt "Generating ${output_movie} ..."
echo "ffmpeg -i ${input_movie} -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc -i ${input_movie} ${ffmbc_opts[@]} ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a -acodec pcm_s24le -ar 48000 -ac 2 ${output_movie}"
ffmpeg -i ${input_movie} -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc -i ${input_movie} ${ffmbc_opts[@]} ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a -acodec pcm_s24le -ar 48000 -ac 2 ${output_movie}
report -dst "Done with ${name}."
else
report -dst "Integrated loudness for $name is ${integrated_loudness}dB. Reference is ${reference}. No adjustment is needed for ${name}, skipping."
fi
fi
shift
done
log -e