-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathfix_volume
executable file
·46 lines (40 loc) · 2.26 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
#!/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.
# local variables
suffix="_voladj"
scriptdir=`dirname "$0"`
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
log -b
[ $# = 0 ] && { report -wt "You must supply one or many arguments. Usage: $(basename $0) [ file1 file2 ... ] ."; exit 2 ;};
while [ "$*" != "" ] ; do
input_movie="$1"
name=`basename "$1"`
get_codectagstring
#[ "$codec_tag_string" = "mpeg" ] && { ffmpeg_opts+=" -c:v copy -c:a pcm_s24le" ; extension="mxf" ; } ;
#[ "$codec_tag_string" = "mpeg" ] || { ffmpeg_opts+=" -c:v copy -c:a pcm_s24le" ; extension="mov" ; } ;
[ "$codec_tag_string" = "mpeg" ] && { ffmpeg_opts+=" -c:a pcm_s24le -f s24le -ar 48000 -ac 2 " ; ffmbc_opts=" -vcodec copy -f s24le -ar 48000 -ac 2 -map_audio_channel 1:0:0:0:1:0 -map_audio_channel 1:0:1:0:1:1 " ; extension="mxf" ; } ;
[ "$codec_tag_string" = "mpeg" ] || { ffmpeg_opts+=" -c:a pcm_s24le -f s24le -ar 48000 -ac 2 " ; ffmbc_opts=" -vcodec copy -f s24le -ar 48000 -ac 2 -map_audio_channel 1:0:0:0:1:0 -map_audio_channel 1:0:1:0:1:1 " ; extension="mov" ; } ;
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 ..."
#cmd="ffmpeg -i \"$input_movie\" $ffmpeg_opts -af volume=${VOLADJ}dB '$output_movie'"
cmd="ffmpeg -i \"$input_movie\" $ffmpeg_opts -af volume=${VOLADJ}dB - | ffmbc -i \"$input_movie\" $ffmbc_opts -i pipe:0 -acodec pcm_s24le \"$output_movie\""
report -dt "Running: $cmd"
eval "$cmd"
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