forked from laurensorensen/DPDP_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakebroadcast
More file actions
executable file
·191 lines (179 loc) · 8.57 KB
/
makebroadcast
File metadata and controls
executable file
·191 lines (179 loc) · 8.57 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# makebroadcast
# v 1.1 change from mov output to mxf output, force all output to hd
# v 1.2 revert to mov and ffmbc
version="1.2"
scriptdir=$(dirname $(which "$0"))
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffmbc ffprobe)
_initialize_make
usage(){
echo
echo "$(basename ${0}) ${version}"
echo "This application will create a file suitable for broadcast or editing from a video file or package input with the following options."
echo "Dependencies: ${dependencies[@]}"
echo "Usage: $(basename ${0}) [ -l ] [ -r ] [ -c ] fileorpackage1 [ fileorpackage2 ...]"
echo " -l (only use the left channel of the first audio track)"
echo " -r (only use the right channel of the first audio track)"
echo " -c (run the video through a crop detection filter, then crop the video accordingly during transcoding, slower)"
echo " -v (run the video through a volume adjustment filter, then adjust the volume accordingly during transcoding, slower)"
echo " -d directory ( directory to deliver the resulting file to )"
echo " -o directory ( directory to write the resulting file to )"
echo " -n (dry-run mode, show the commands that would be run but don't do anything)"
echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )"
echo " -E emailaddress ( send an email about process outcome )"
echo " -h ( display this help )"
echo
exit
}
[ "${#}" = 0 ] && usage
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":lrcvo:d:e:E:nh" opt ; do
case "${opt}" in
l) audiomap="L";;
r) audiomap="R";;
c) cropdetect="Y" ;;
v) voladjust="Y" ;;
o) outputdir_forced="$OPTARG" && _check_outputdir_forced ;;
d) deliverdir="$OPTARG" && check_deliverdir ;;
e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;;
E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;;
n) DRYRUN=true;;
h) usage ;;
*) echo "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
# get context about the input
input="$1"
if [ -z "${outputdir_forced}" ] ; then
[ -d "${input}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;};
[ -f "${input}" ] && { outputdir=$(dirname "${input}")"/service" && logdir="$(dirname "${input}")/service/logs" ;};
[ ! "${outputdir}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;};
else
outputdir="${outputdir_forced}"
logdir="${outputdir}/logs"
fi
_find_input "${input}"
mediaid=$(basename "${input}" | cut -d. -f1)
# set up output
_log -b
output="${outputdir}/${mediaid%.*}.mov"
[ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;};
_run mkdir -p "${outputdir}"
# clear local arrays
unset inputoptions
unset middleoptions
unset audiomapping_ffmbc
filterchain_start=""
# get information on the input
get_audio_index "${sourcefile}"
get_sar "${sourcefile}"
if [ "${cropdetect}" = "Y" ] ; then
get_cropdetection "${sourcefile}"
filterchain_start="${CROPADJ},"
width=$(echo "${CROPADJ}" | cut -d= -f2 | cut -d: -f1)
height=$(echo "${CROPADJ}" | cut -d= -f2 | cut -d: -f2)
dar="(${width}/${height})*${sar}"
else
get_width "${sourcefile}"
get_height "${sourcefile}"
get_dar "${sourcefile}"
fi
get_fieldorder "${sourcefile}"
if [ "${fieldorder}" != "tff" ] ; then
filterchain_start+="fieldorder=tff,"
fi
if [ "${audiomap}" = "L" ] ; then
audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:0:0:1:0 -map_audio_channel 0:${audio_index_1}:0:0:1:1)
elif [ "${audiomap}" = "R" ] ; then
audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:1:0:1:0 -map_audio_channel 0:${audio_index_1}:1:0:1:1)
else
get_audio_mapping "${sourcefile}"
fi
middleoptions+=(${audiomapping_ffmbc[@]})
# set fixed transcoding options
middleoptions+=(-r ntsc)
middleoptions+=(-tff)
middleoptions+=(-threads 4)
# decide on an output codec, aspect ratio, and padding strategy
darratio=$(echo "scale=3 ; ${dar}" | bc)
if [ "${darratio}" = "1.777" -a ! "${cropdetect}" = "Y" ] ; then
middleoptions+=(-s 1920x1080)
middleoptions+=(-target xdcamhd422)
middleoptions+=(-vtag xd5b)
middleoptions+=(-aspect 16:9)
elif [ $(echo "scale=3 ; ${darratio} > (16/9)" | bc -l) = 1 ] ; then
middleoptions+=(-vf "${filterchain_start}pad=${width}:${width}*(9/16)*(${sar}):(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1")
middleoptions+=(-target xdcamhd422)
middleoptions+=(-vtag xd5b)
middleoptions+=(-aspect 16:9)
elif [ $(echo "scale=3 ; $darratio > (3/2)" | bc -l) = 1 ] ; then
middleoptions+=(-vf "${filterchain_start}pad=${height}*(16/9)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1")
middleoptions+=(-target xdcamhd422)
middleoptions+=(-vtag xd5b)
middleoptions+=(-aspect 16:9)
elif [ "$width" = "720" -a "$height" = "480" -a $(echo "scale=3 ; $darratio < (3/2)" | bc -l) = 1 -a ! "$cropdetect" = "Y" ] ; then
filterchain_start=$(echo "${filterchain_start}" | sed 's/,$//g')
middleoptions+=(-vf ${filterchain_start})
middleoptions+=(-target imx30)
middleoptions+=(-aspect 4:3)
elif [ "${height}" -eq "486" -a "${width}" -eq "720" ] ; then
filterchain_start+="crop=720:480:0:4"
filterchain_start=$(echo "$filterchain_start" | sed 's/,$//g')
middleoptions+=(-vf ${filterchain_start})
middleoptions+=(-target imx30)
middleoptions+=(-aspect 4:3)
elif [ "${height}" -eq "512" -a "${width}" -eq "720" ] ;then
filterchain_start+="crop=720:480:0:32"
filterchain_start=$(echo "${filterchain_start}" | sed 's/,$//g')
middleoptions+=(-vf ${filterchain_start})
middleoptions+=(-target imx30)
middleoptions+=(-aspect 4:3)
else
middleoptions+=(-vf "${filterchain_start}pad=${height}*(4/3)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=720:480:interl=1")
middleoptions+=(-target imx30)
middleoptions+=(-aspect 4:3)
fi
# add audio options
middleoptions+=(-acodec pcm_s24be)
middleoptions+=(-ar 48k)
middleoptions+=(-ac 2)
# set input options for ffmbc
inputoptions+=(-y)
inputoptions+=(-threads 8)
inputoptions+=(-loglevel verbose)
# log ffmbc process
if [ "${logdir}" != "" ] ; then
_run mkdir -p "${logdir}"
export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt"
reportfile="ffmbc_$(date '+%Y%m%d-%H%M%S')_$(basename $0)_${version}.txt"
echo "ffmbc started on $(date '+%F at %T')" > "${logdir}/${reportfile}"
echo "Report written to \"${reportfile}\"" >> "${logdir}/${reportfile}"
echo "Command line:" >> "${logdir}/${reportfile}"
fi
if [ "${voladjust}" = "Y" ] ; then
get_volume_adjustment "${sourcefile}"
unset audio_pipe_opts
audio_pipe_opts=(-f s24le -ar 48000 -ac 2)
_run ffmpeg -v warning -stats -i "${input_movie}" -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc ${inputoptions[@]} -i "${input_movie}" ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a ${middleoptions[@]} "${output}"
else
get_codectagstring "${sourcefile}"
if [ "$codec_tag_string" = "FFV1" -a "$ffv1_version" = "3" ] ; then
if [ "${logdir}" != "" ] ; then
_run rm "${logdir}/${reportfile}"
fi
_run ffmpeg -report ${inputoptions[@]} -i "${sourcefile}" -vf "fieldorder=tff,pad=720:512:0:24,format=yuv422p,setsar=1/1,setdar=4/3,fps=fps=ntsc" -c:v mpeg2video -intra_vlc 1 -non_linear_quant 1 -qmin 1 -qmax 12 -intra -top 1 -b:v 30M -maxrate:v 30M -minrate:v 30M -bufsize 1001000 -rc_init_occupancy 1001000 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -rc_buf_aggressivity 0.25 -dc 10 -lmin QP2LAMBDA -vbsf imxdump -flags +ildct+ilme+low_delay -ps 1 -tag:v mx3n -c:a pcm_s24be -ar 48k -ac 2 "${output}"
else
_run ffmbc ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}"
fi
fi
echo
_summarize_make
_deliver_output
shift
_log -e
done