-
Notifications
You must be signed in to change notification settings - Fork 27
/
makederiv
executable file
·892 lines (862 loc) · 52.3 KB
/
makederiv
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
#!/bin/bash
# makederiv, makes a derivative file appropriate for editing, upload, and other functions
VERSION="1.0"
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
SUFFIX=""
CHAPTERIZE=""
_initialize_make
_usage(){
echo
echo "$(basename "makederiv") ${VERSION}"
echo "This application will create a derivative file from a video file or package input with the following options."
echo "Dependencies: ${DEPENDENCIES[@]}"
echo "Usage: $(basename "${0}") [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]"
echo " -T derivative (specify a derivative video type:)"
echo " broadcast (mov) for broadcast"
echo " broadcast_copy (mov) for broadcast"
echo " prores (mov) for editing"
echo " youtube (mp4) for uploading"
echo " resourcespace (mp4) for uploading to resourcespace"
echo " quick (mp4)"
echo " dvd (iso)"
echo " mp3 (mp3)"
echo " podcast (mov or m4a)"
echo " waveform (png)"
echo " audiographs (png)"
echo " showwaves (mp4)"
echo " transcriptiondisc (wav)"
echo " streamable"
echo " -m (only use the first track)"
echo " -D (downmix the first two mono tracks, ignored if the first two audio tracks are not mono)"
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 " -a (downmix all audio tracks into a stereo output)"
echo " -t (burn timecode overlay)"
echo " -u subtitle_file (burn in a subtitle file)"
echo " -w (burn pts overlay)"
echo " -X (burn in timecode, pts, and clipname)"
echo " -C (generate chapter-based segmented output in addition to full output)"
echo " -S suffix (add custom suffix to end of output filename)"
echo " -I starttime (use a custom starting time from the source video, use HH:MM:SS.mmm format or something acceptable to ffmpeg)"
echo " -O endtime (use a custom ending time from the source video, use HH:MM:SS.mmm format or something acceptable to ffmpeg)"
echo " -v Y|N (run the video through a volume adjustment filter, then adjust the volume accordingly during transcoding, slower; defaults to ${VOLADJUST})"
echo " -d directory (directory to deliver the resulting file to)"
echo " -o directory (directory to write the resulting file to)"
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 " -n (dry-run mode: show the commands that would be run but don't do anything)"
echo " -h (display this help)"
echo " FOR BROADCAST USE ONLY:"
echo " -F (apply a formula, override default settings)"
echo " -s (create slate, which adds color bars, a slate, and 30 seconds of black at the end)"
echo " -c (run the video through a crop detection filter, then crop the video accordingly during transcoding, slower)"
echo " FOR YOUTUBE USE ONLY:"
echo " -Y (attempt to use uploadyoutube on the resulting file)"
echo " FOR DVD USE ONLY:"
echo " -p dvdlabelprefix (overrides label set in mmconfig)"
exit
}
user_input=${@}
OPTIND=1
while getopts ":T:lrmDav:d:o:e:E:F:scYp:tu:wXCS:I:O:nh" OPT ; do
case "${OPT}" in
T) OUTPUT_TYPE="${OPTARG}";;
l) AUDIOMAP="L";;
r) AUDIOMAP="R";;
m) AUDIOMAP="M";;
D) AUDIOMAP="D";;
a) AUDIOMAP="A";;
v) VOLADJUST="${OPTARG}";;
d) DELIVERDIR="${OPTARG}" && (_check_deliverdir) ;;
o) OUTPUTDIR_FORCED="${OPTARG}" && (_check_outputdir_forced) ;;
e) EMAILADDRESS_DELIVERY="${OPTARG}" && (_check_emailaddress "${EMAILADDRESS_DELIVERY}") ;;
E) EMAILADDRESS_OUTCOME="${OPTARG}" && (_check_emailaddress "${EMAILADDRESS_OUTCOME}") ;;
F) FORMULA="${OPTARG}";;
s) ADDSLATE="Y";;
c) CROPDETECT="Y" ;;
Y) YOUTUBEUPLOAD="Y";;
p) DVDLABELPREFIX="${OPTARG}";;
t) TCBURN="Y";;
u) SUBTITLE_FILE="${OPTARG}";;
w) PTSBURN="Y";;
X) INFOBURN="Y";;
C) CHAPTERIZE="Y";;
S) SUFFIX="${OPTARG}";;
I) INTIME="${OPTARG}";;
O) OUTTIME="${OPTARG}";;
n) DRYRUN=true;;
h) _usage ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
:) echo "Option -${OPTARG} requires an argument" ; _writeerrorlog "makederiv" "The option selected required an argument and none was provided. The script had to exit." ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
DEPENDENCIES=(ffmpeg ffprobe)
# set derivative extensions and paths
if [[ "${OUTPUT_TYPE}" == "broadcast" ]] ; then
EXTENSION="mov"
RELATIVEPATH="objects/service"
USEACCESSTIMES="Y"
if [[ "${ADDSLATE}" = "Y" ]]; then
SUFFIX="_SLATE"
fi
elif [[ "${OUTPUT_TYPE}" == "broadcast_copy" ]] ; then
EXTENSION="mov"
RELATIVEPATH=""
SUFFIX="_COPY"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "prores" ]] ; then
EXTENSION="mov"
RELATIVEPATH="objects/access/prores"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "youtube" ]]; then
EXTENSION="mp4"
RELATIVEPATH="objects/access/youtube_up"
if [[ "${TCBURN}" == "Y" ]]; then
SUFFIX="_TCBURN"
fi
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "window" ]] ; then
EXTENSION="mp4"
RELATIVEPATH="objects/access/window"
SUFFIX="_WINDOW"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "resourcespace" ]] ; then
PREFERRED_SOURCE="service"
EXTENSION="mp4"
RELATIVEPATH="objects/access/resourcespace"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "quick" ]] ; then
PREFERRED_SOURCE="service"
EXTENSION="mp4"
RELATIVEPATH="objects/access/quick"
SUFFIX="_quick"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "dvd" ]] ; then
PREFERRED_SOURCE="service"
EXTENSION="iso"
RELATIVEPATH="objects/access/dvd"
DEPENDENCIES+=(dvdauthor mkisofs)
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "mp3" ]] ; then
EXTENSION="mp3"
RELATIVEPATH="objects/access/mp3"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "podcast" ]] ; then
# extension is set later in the loop because it will be adjusted based on audio-only or audio-video
PREFERRED_SOURCE="service"
RELATIVEPATH="objects/access/podcast"
SUFFIX="_podcast"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "waveform" ]] ; then
EXTENSION="png"
RELATIVEPATH="metadata/depictions"
SUFFIX="_waveform"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "audiographs" ]] ; then
EXTENSION="png"
RELATIVEPATH="metadata/depictions"
SUFFIX="_audiographs"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "showwaves" ]] ; then
EXTENSION="mp4"
RELATIVEPATH="objects/access/showwaves"
SUFFIX="_showwaves"
USEACCESSTIMES="N"
elif [[ "${OUTPUT_TYPE}" == "streamable" ]] ; then
EXTENSION="mp4"
RELATIVEPATH="objects/access/streamable"
USEACCESSTIMES="Y"
elif [[ "${OUTPUT_TYPE}" == "spectogram" ]] ; then
EXTENSION="png"
RELATIVEPATH="objects/access/showwaves"
SUFFIX="_spectogram"
USEACCESSTIMES="N"
elif [[ "${OUTPUT_TYPE}" == "transcriptiondisc" ]] ; then
EXTENSION="wav"
RELATIVEPATH="objects/restoration"
SUFFIX="_transcriptiondisc"
USEACCESSTIMES="Y"
else
echo "No matches for specified output type."
_usage
fi
_check_dependencies "${DEPENDENCIES[@]}"
while [[ "${@}" != "" ]] ; do
# get context about the input
INPUT="${1}"
_report -dt "==== Starting to make a ${OUTPUT_TYPE} copy from ${INPUT}. ===="
shift
if [ -z "${OUTPUTDIR_FORCED}" ] ; then
if [[ -d "${INPUT}" ]] ; then
OUTPUTDIR="${INPUT}/${RELATIVEPATH}"
LOGDIR="${INPUT}/metadata/logs"
elif [[ -f "${INPUT}" ]] ; then
OUTPUTDIR=$(dirname "${INPUT}")"/$(basename "${RELATIVEPATH}")"
LOGDIR="$(dirname "${INPUT}")/$(basename "${RELATIVEPATH}")/logs"
else
OUTPUTDIR="${INPUT}/${RELATIVEPATH}"LOGDIR="${INPUT}/metadata/logs"
fi
else
OUTPUTDIR="${OUTPUTDIR_FORCED}"
LOGDIR="${OUTPUTDIR}/logs"
fi
_unset_variables
_find_input "${INPUT}"
MEDIAID=$(basename "${INPUT}" | cut -d. -f1)
INGESTLOG="${LOGDIR}/capture.log"
if [[ ! -f "${INGESTLOG}" && -f "${INPUT}/metadata/submissionDocumentation/logs/capture.log" ]] ; then
INGESTLOG="${INPUT}/metadata/submissionDocumentation/logs/capture.log"
_report -wt "The capture.log is found in the ./metadata/submissionDocumentation/logs/ directory. Using that for now but consider moving it to ./metadata/logs/"
fi
_report_to_db
# get information on the input
_get_height "${SOURCEFILE}"
_get_width "${SOURCEFILE}"
_get_seconds "${SOURCEFILE}"
_get_codectagstring "${SOURCEFILE}"
_get_videostreamcount "${SOURCEFILE}"
_get_audiostreamcount "${SOURCEFILE}"
_get_dar "${SOURCEFILE}"
_get_sar "${SOURCEFILE}"
_get_format "${SOURCEFILE}"
# processing for chapter-based segmented output
if [[ "${CHAPTERIZE}" == "Y" ]] ; then
_get_chapterlist "${SOURCEFILE}"
_report -d "${SOURCEFILE} contains a chapter list."
echo "${CHAPTER_LIST}"
echo "${CHAPTER_LIST}" | while read chapter ; do
CHAP_ID="$(echo "${chapter}" | cut -d"|" -f1)"
CHAP_START="$(echo "${chapter}" | cut -d"|" -f2)"
CHAP_END="$(echo "${chapter}" | cut -d"|" -f3)"
CHAP_TITLE="$(echo "${chapter}" | cut -d"|" -f4- | sed 's/ /_/g;s/[^a-zA-Z0-9_]//g;s/__/_/g')"
CHAP_SUFFIX="_SEG$(printf "%02d\n" "${CHAP_ID}")_${CHAP_TITLE}"
echo "Creating ${OUTPUT_TYPE} chapter output ${CHAP_TITLE} (${CHAP_START}-${CHAP_END})"
("${SCRIPTDIR}/makederiv" -T "${OUTPUT_TYPE}" -I "$CHAP_START" -O "${CHAP_END}" -S "$CHAP_SUFFIX" "${INPUT}")
done
exit
fi
if [[ "${OUTPUT_TYPE}" == "podcast" ]] ; then
if [[ "${VIDEOSTREAMCOUNT}" -gt 0 ]] ; then
EXTENSION="mov"
else
EXTENSION="m4a"
fi
fi
if [[ "${CHAPTERIZE}" != "Y" ]] ; then
_set_up_output
fi
INPUTOPTIONS+=(-y)
INPUTOPTIONS+=(-nostdin)
# set in and out times if used; ignore out time if a slate is being created
if [[ -f "${INGESTLOG}" && "${ISOBJECT}" = "Y" ]] ; then
if [[ -z "${INTIME}" ]] ; then
INTIME=$(_readingestlog "intime")
fi
if [[ -z "${OUTTIME}" ]] ; then
OUTTIME=$(_readingestlog "outtime")
fi
fi
if [[ -n "${INTIME}" && "${USEACCESSTIMES}" = "Y" ]] ; then
_report -dt "Transcoding will use intime (${INTIME}) during transcoding."
INPUTOPTIONS+=(-seek_timestamp 1)
MIDDLEOPTIONS+=(-ss "${INTIME}")
METADATA_COMMENT+=("mediaid=${MEDIAID} ")
METADATA_COMMENT+=("in=${INTIME} ")
fi
if [[ -n "${OUTTIME}" && "${USEACCESSTIMES}" = "Y" && "${ADDSLATE}" = "Y" ]] ; then
_report -dt "Transcoding will NOT use outtime (${OUTTIME}) during transcoding, as there is a slate being created for this file."
elif [[ -n "${OUTTIME}" && "${USEACCESSTIMES}" = "Y" && "${ADDSLATE}" != "Y" ]] ; then
_report -dt "Transcoding will use outtime (${OUTTIME}) during transcoding."
INPUTOPTIONS+=(-to "${OUTTIME}")
METADATA_COMMENT+=("out=${OUTTIME} ")
fi
if [[ "${USEACCESSTIMES}" = "N" ]]; then
_report -dt "Transcoding will NOT use intime (${INTIME}) or outtime (${OUTTIME}) during transcoding"
fi
if [[ -n "${METADATA_COMMENT}" ]] ; then
MIDDLEOPTIONS+=(-metadata "comment=${METADATA_COMMENT[*]}")
fi
# read audio decision from ingestlog
if [[ -z "${AUDIOMAP}" && "${ISOBJECT}" = "Y" ]] ; then
AUDIODECISION="$(_readingestlog audiodecision)"
if [[ "${AUDIODECISION}" == "Only use left of the first audio track [for 21st Century]" ]] ; then
AUDIOMAP="L"
elif [[ "${AUDIODECISION}" == "Only use right of the first audio track" ]] ; then
AUDIOMAP="R"
elif [[ "${AUDIODECISION}" == "Only use the first track" ]] ; then
AUDIOMAP="M"
elif [[ "${AUDIODECISION}" == "Downmix the first two mono tracks" ]] ; then
AUDIOMAP="D"
elif [[ "${AUDIODECISION}" == "Downmix all tracks" ]] ; then
AUDIOMAP="A"
fi
fi
# encoding options
if [[ "${VIDEOSTREAMCOUNT}" -gt 0 ]] ; then
if [[ "${CODEC_TAG_STRING}" == "mjp2" ]] ; then
INPUTOPTIONS+=(-vcodec libopenjpeg)
fi
if [[ "${OUTPUT_TYPE}" == "broadcast" ]] ; then
_get_broadcastduration "${SOURCEFILE}"
if [ "${CROPDETECT}" = "Y" ] ; then
_get_cropdetection "${SOURCEFILE}"
_add_video_filter "${CROPADJ}"
WIDTH=$(echo "${CROPADJ}" | cut -d= -f2 | cut -d: -f1)
HEIGHT=$(echo "${CROPADJ}" | cut -d= -f2 | cut -d: -f2)
DAR="(${WIDTH}/${HEIGHT})*${SAR}"
fi
# set options for zeroing timecode if input is MXF
if [[ "${FORMAT}" == "mxf" ]] ; then
metadata_option="-metadata"
else
metadata_option="-metadata:s:v:0"
fi
# if adding a slate: request metadata
if [[ "${ADDSLATE}" == "Y" ]] ; then
MEDIAID4SLATE=$(_readingestlog "media ID slate")
if [ -z "${MEDIAID4SLATE}" ] ; then
cowsay "MediaID?"
echo -n ":: "
read -r MEDIAID4SLATE
fi
SERIESTITLE=$(_readingestlog "Series Title")
if [ -z "${SERIESTITLE}" ] ; then
cowsay -t "Series Title?"
echo -n ":: "
read -r SERIESTITLE
fi
EPISODETITLE=$(_readingestlog "Episode Title")
if [ -z "${EPISODETITLE}" ] ; then
cowsay -s "Episode Title?"
echo -n ":: "
read -r EPISODETITLE
fi
SLATE_MEDIAID=$(_maketemp)
echo "${MEDIAID4SLATE}" > "${SLATE_MEDIAID}"
SLATE_SERIES=$(_maketemp)
echo "${SERIESTITLE}" > "${SLATE_SERIES}"
SLATE_EPISODE=$(_maketemp)
echo "${EPISODETITLE}" > "${SLATE_EPISODE}"
SLATE_DURATION=$(_maketemp)
echo "${BROADCASTDURATION}" > "${SLATE_DURATION}"
SLATE_CH1=$(_maketemp)
echo "Ch. 1 Stereo L" > "${SLATE_CH1}"
SLATE_CH2=$(_maketemp)
echo "Ch. 2 Stereo R" > "${SLATE_CH2}"
SLATE_CH3=$(_maketemp)
echo "Ch. 3 Mono Mix" > "${SLATE_CH3}"
SLATE_CH4=$(_maketemp)
echo "Ch. 4 Mono Mix" > "${SLATE_CH4}"
COLORBARS_SECS=60
SLATE_SECS=20
COUNTDOWN_SECS=8.2
BLACK_SECS=1.8
END_BLACK_SECS=30
fontfile="/System/Library/Fonts/HelveticaNeue.dfont"
fontenable="enable=gte(t\,${COLORBARS_SECS})*lt(t\,${COLORBARS_SECS}+${SLATE_SECS})"
MIDDLEOPTIONS+=(-f lavfi -i "smptehdbars=s=1920x1080:r=30000/1001:sar=16/9:d=${COLORBARS_SECS}" \
-f lavfi -i "aevalsrc=0.1*sin(1000*2*PI*t):d=${COLORBARS_SECS}:s=48000:c=stereo" \
-f lavfi -i "color=c=BlueViolet:s=1920x1080:r=30000/1001:sar=16/9:d=${COUNTDOWN_SECS},geq=r='X/W*r(X,Y)':g='(1-X/W)*g(X,Y)':b='(H-Y)/H*b(X,Y)'" \
-f lavfi -i "aevalsrc=0:d=${SLATE_SECS}:s=48000:c=stereo" \
-f lavfi -i "color=black:s=1920x1080:r=30000/1001:sar=16/9:d=${COUNTDOWN_SECS}" \
-f lavfi -i "sine=r=48000:frequency=1:beep_factor=400:duration=${COUNTDOWN_SECS}" \
-f lavfi -i "color=black:s=1920x1080:r=30000/1001:sar=16/9:d=${BLACK_SECS}" \
-f lavfi -i "aevalsrc=0:d=${BLACK_SECS}:s=48000:c=stereo" \
-f lavfi -i "color=black:s=1920x1080:r=30000/1001:sar=16/9:d=${END_BLACK_SECS}" \
-f lavfi -i "aevalsrc=0:d=${END_BLACK_SECS}:s=48000:c=stereo")
MIDDLEOPTIONS+=("$metadata_option" timecode=00:58:30\;00)
else
MIDDLEOPTIONS+=("$metadata_option" timecode=00:00:00.00)
fi
# determine filter choice if set in capture
if [[ -f "${INGESTLOG}" && "${ISOBJECT}" = "Y" ]] ; then
if [[ "${FORMULA}" == "none" ]] ; then
FILTERCHOICE=$(_readingestlog "filter choice")
_add_video_filter "${FILTERCHOICE}"
echo "${FILTERCHOICE}"
fi
fi
#options for either xdcam or imx
MIDDLEOPTIONS+=(-r ntsc)
MIDDLEOPTIONS+=(-c:v mpeg2video)
MIDDLEOPTIONS+=(-intra_vlc 1)
MIDDLEOPTIONS+=(-non_linear_quant 1)
MIDDLEOPTIONS+=(-qmin 5)
MIDDLEOPTIONS+=(-dc 10)
MIDDLEOPTIONS+=(-lmin QP2LAMBDA)
MIDDLEOPTIONS+=(-ps 1)
MIDDLEOPTIONS+=(-flags +ildct+ilme)
MIDDLEOPTIONS+=(-pix_fmt yuv422p)
MIDDLEOPTIONS+=(-top 1)
MIDDLEOPTIONS+=(-mpv_flags strict_gop)
MIDDLEOPTIONS+=(-drop_frame_timecode 1)
#xdcam options
MIDDLEOPTIONSXDCAM+=(-s 1920x1080)
MIDDLEOPTIONSXDCAM+=(-vtag xd5b)
MIDDLEOPTIONSXDCAM+=(-aspect 16:9)
MIDDLEOPTIONSXDCAM+=(-q:v 1)
MIDDLEOPTIONSXDCAM+=(-qmax 23)
MIDDLEOPTIONSXDCAM+=(-g 15)
MIDDLEOPTIONSXDCAM+=(-bf 2)
MIDDLEOPTIONSXDCAM+=(-b:v 50M)
MIDDLEOPTIONSXDCAM+=(-maxrate:v 50M)
MIDDLEOPTIONSXDCAM+=(-minrate:v 50M)
MIDDLEOPTIONSXDCAM+=(-bufsize 17825792)
MIDDLEOPTIONSXDCAM+=(-rc_init_occupancy 17825792)
# imx options
MIDDLEOPTIONSIMX+=(-aspect 4:3)
MIDDLEOPTIONSIMX+=(-qmax 12)
MIDDLEOPTIONSIMX+=(-g 1)
MIDDLEOPTIONSIMX+=(-b:v 30M)
MIDDLEOPTIONSIMX+=(-maxrate:v 30M)
MIDDLEOPTIONSIMX+=(-minrate:v 30M)
MIDDLEOPTIONSIMX+=(-bufsize 1001000)
MIDDLEOPTIONSIMX+=(-rc_init_occupancy 1001000)
MIDDLEOPTIONSIMX+=(-rc_max_vbv_use 1)
MIDDLEOPTIONSIMX+=(-rc_min_vbv_use 1)
MIDDLEOPTIONSIMX+=(-rc_buf_aggressivity 0.25)
MIDDLEOPTIONSIMX+=(-bsf:v imxdump)
MIDDLEOPTIONSIMX+=(-tag:v mx3n)
# decide on an output codec, aspect ratio, and padding strategy
DARRATIO=$(echo "scale=3 ; ${DAR}" | bc)
if [ "${FORMULA}" = "tff" ] ; then
_add_video_filter "setfield=tff"
elif [ "${FORMULA}" = "bff" ] ; then
_add_video_filter "setfield=bff"
fi
_add_video_filter "fieldorder=tff"
if [ "${FORMULA}" = "hds" ] ; then
_add_video_filter "scale=size=hd1080:interl=1"
_add_video_filter "setdar=16/9"
_add_video_filter "fps=fps=ntsc"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSXDCAM[@]}")
elif [ "${FORMULA}" = "sds" ] ; then
_add_video_filter "scale=720:480"
_add_video_filter "pad=720:512:0:24"
_add_video_filter "setdar=4/3"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSIMX[@]}")
elif [ "${DARRATIO}" = "1.777" -a ! "${CROPDETECT}" = "Y" ] ; then
_add_video_filter "scale=size=hd1080:interl=1"
_add_video_filter "setdar=16/9"
_add_video_filter "fps=fps=ntsc"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSXDCAM[@]}")
elif [ $(echo "scale=3 ; ${DARRATIO} > (16/9)" | bc -l) = 1 ] ; then
_add_video_filter "scale=size=hd1080:interl=1:force_original_aspect_ratio=decrease"
_add_video_filter "pad=1920:1080:(ow-iw)/2:(oh-ih)/2"
_add_video_filter "setdar=16/9"
_add_video_filter "fps=fps=ntsc"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSXDCAM[@]}")
elif [ $(echo "scale=3 ; $DARRATIO > (3/2)" | bc -l) = 1 -o "${ADDSLATE}" = "Y" ] ; then
_add_video_filter "scale=size=hd1080:interl=1:force_original_aspect_ratio=decrease"
_add_video_filter "pad=1920:1080:(ow-iw)/2:(oh-ih)/2"
_add_video_filter "setdar=16/9"
_add_video_filter "fps=fps=ntsc"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSXDCAM[@]}")
elif [ "${WIDTH}" = "720" -a "${HEIGHT}" = "480" -a $(echo "scale=3 ; ${DARRATIO} < (3/2)" | bc -l) = 1 -a ! "${CROPDETECT}" = "Y" ] ; then
_add_video_filter "scale=720:480"
_add_video_filter "pad=720:512:0:24"
_add_video_filter "setdar=4/3"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSIMX[@]}")
elif [ "${HEIGHT}" -eq "486" -a "${WIDTH}" -eq "720" ] ; then
_add_video_filter "crop=720:484:0:0"
_add_video_filter "pad=720:512:0:28"
_add_video_filter "setdar=4/3"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSIMX[@]}")
elif [ "${HEIGHT}" -eq "512" -a "${WIDTH}" -eq "720" ] ;then
_add_video_filter "setdar=4/3"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSIMX[@]}")
else
_add_video_filter "scale=720:480"
_add_video_filter "pad=720:512:0:24"
_add_video_filter "setdar=4/3"
MIDDLEOPTIONS+=("${MIDDLEOPTIONSIMX[@]}")
fi
_add_video_filter "format=yuv422p"
_add_video_filter "lutyuv=clipval"
elif [[ "${OUTPUT_TYPE}" == "broadcast_copy" ]] ; then
MIDDLEOPTIONS+=(-map 0:v)
MIDDLEOPTIONS+=(-c:v copy)
if [[ "${FORMAT}" == "mxf" ]] ; then
metadata_option="-metadata"
else
metadata_option="-metadata:s:v:0"
fi
MIDDLEOPTIONS+=("$metadata_option" timecode=00:00:00.00)
elif [[ "${OUTPUT_TYPE}" == "prores" ]] ; then
MIDDLEOPTIONS+=(-map 0:v)
MIDDLEOPTIONS+=(-c:v prores_ks)
MIDDLEOPTIONS+=(-profile:v 3)
MIDDLEOPTIONS+=(-flags +ildct+ilme)
elif [[ "${OUTPUT_TYPE}" == "youtube" ]] || [[ "${OUTPUT_TYPE}" == "resourcespace" ]] ; then
MIDDLEOPTIONS+=(-movflags faststart)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-force_key_frames chapters)
# MIDDLEOPTIONS+=(-bufsize 1835k)
MIDDLEOPTIONS+=(-f mp4)
if [[ "${OUTPUT_TYPE}" == "youtube" ]] ; then
MIDDLEOPTIONS+=(-crf 18)
if [ "${FILESECONDS%.*}" -gt "7200" ] ; then
MIDDLEOPTIONS+=(-maxrate 2190k)
elif [ "${FILESECONDS%.*}" -gt "3600" ] ; then
MIDDLEOPTIONS+=(-maxrate 4380k)
else
MIDDLEOPTIONS+=(-maxrate 8760k)
fi
else
MIDDLEOPTIONS+=(-crf 23)
if [ "${FILESECONDS%.*}" -gt "7200" ] ; then
MIDDLEOPTIONS+=(-maxrate 800k)
elif [ "${FILESECONDS%.*}" -gt "3600" ] ; then
MIDDLEOPTIONS+=(-maxrate 900k)
else
MIDDLEOPTIONS+=(-maxrate 2000k)
fi
fi
if [[ "${WIDTH}" == 720 && "${HEIGHT}" == 486 ]] ; then
_add_video_filter "crop=720:480:0:4"
elif [[ "${WIDTH}" == 720 && "${HEIGHT}" == 512 ]] ; then
_add_video_filter "crop=720:480:0:32"
fi
_add_video_filter "yadif"
elif [[ "${OUTPUT_TYPE}" == "window" ]] ; then
MIDDLEOPTIONS+=(-movflags faststart)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-force_key_frames chapters)
MIDDLEOPTIONS+=(-f mp4)
MIDDLEOPTIONS+=(-crf 21)
if [[ "${WIDTH}" == 720 && "${HEIGHT}" == 486 ]] ; then
_add_video_filter "crop=720:480:0:4"
elif [[ "${WIDTH}" == 720 && "${HEIGHT}" == 512 ]] ; then
_add_video_filter "crop=720:480:0:32"
fi
_add_video_filter "yadif"
elif [[ "${OUTPUT_TYPE}" == "streamable" ]]; then
MIDDLEOPTIONS+=(-movflags faststart)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-force_key_frames chapters)
MIDDLEOPTIONS+=(-bufsize 1M)
MIDDLEOPTIONS+=(-maxrate 1M)
MIDDLEOPTIONS+=(-f mp4)
if [[ "${OUTPUT_TYPE}" == "streamable" ]] ; then
MIDDLEOPTIONS+=(-crf 18)
if [ "${FILESECONDS%.*}" -gt "7200" ] ; then
MIDDLEOPTIONS+=(-maxrate 2190k)
elif [ "${FILESECONDS%.*}" -gt "3600" ] ; then
MIDDLEOPTIONS+=(-maxrate 4380k)
else
MIDDLEOPTIONS+=(-maxrate 8760k)
fi
else
MIDDLEOPTIONS+=(-crf 23)
if [ "${FILESECONDS%.*}" -gt "7200" ] ; then
MIDDLEOPTIONS+=(-maxrate 800k)
elif [ "${FILESECONDS%.*}" -gt "3600" ] ; then
MIDDLEOPTIONS+=(-maxrate 900k)
else
MIDDLEOPTIONS+=(-maxrate 2000k)
fi
fi
if [[ "${WIDTH}" == 720 && "${HEIGHT}" == 486 ]] ; then
_add_video_filter "crop=720:480:0:4"
elif [[ "${WIDTH}" == 720 && "${HEIGHT}" == 512 ]] ; then
_add_video_filter "crop=720:480:0:32"
fi
_add_video_filter "yadif"
elif [[ "${OUTPUT_TYPE}" == "quick" ]] ; then
MIDDLEOPTIONS+=(-map 0:v)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-preset ultrafast)
MIDDLEOPTIONS+=(-crf 24)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-s 640x360)
MIDDLEOPTIONS+=(-force_key_frames chapters)
MIDDLEOPTIONS+=(-f mp4)
MIDDLEOPTIONS+=(-movflags faststart)
elif [[ "${OUTPUT_TYPE}" == "dvd" ]] ; then
DARRATIO=$(echo "scale=3 ; ${DAR}" | bc)
if [ $(echo "scale=5 ; ${DARRATIO} > 1.5" | bc -l) = 1 ] ;then
ASPECT="16/9"
DVDASPECT="16:9"
else
ASPECT="4/3"
DVDASPECT="4:3"
fi
_get_maxdvdbitrate "${SOURCEFILE}"
MIDDLEOPTIONS+=(-r:v ntsc)
MIDDLEOPTIONS+=(-c:v mpeg2video)
MIDDLEOPTIONS+=(-c:a ac3)
MIDDLEOPTIONS+=(-f dvd)
MIDDLEOPTIONS+=(-bf 2)
MIDDLEOPTIONS+=(-qscale:v 2)
MIDDLEOPTIONS+=(-mbd rd)
MIDDLEOPTIONS+=(-s 720x480)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-g 18)
MIDDLEOPTIONS+=(-b:v "${MAXDVDBITRATE}")
MIDDLEOPTIONS+=(-bt 400k)
MIDDLEOPTIONS+=(-top 0)
MIDDLEOPTIONS+=(-flags +ildct+ilme)
MIDDLEOPTIONS+=(-maxrate "${MAXDVDBITRATE}")
MIDDLEOPTIONS+=(-minrate 0)
MIDDLEOPTIONS+=(-bufsize 3600k)
MIDDLEOPTIONS+=(-packetsize 2048)
MIDDLEOPTIONS+=(-muxrate 10080000)
MIDDLEOPTIONS+=(-lmin 1)
MIDDLEOPTIONS+=(-lmax 200000)
MIDDLEOPTIONS+=(-aspect "${ASPECT}")
if [[ "${WIDTH}" == 720 && "${HEIGHT}" == 486 ]] ; then
_add_video_filter "crop=720:480:0:4"
elif [[ "${WIDTH}" == 720 && "${HEIGHT}" == 512 ]] ; then
_add_video_filter "crop=720:480:0:32"
elif [[ "${WIDTH}" != 720 && "${HEIGHT}" != 480 ]] ; then
_add_video_filter "scale=720:480:interl=1"
fi
_add_video_filter "fieldorder=bff"
_add_video_filter "setdar=${ASPECT}"
elif [[ "${OUTPUT_TYPE}" == "podcast" ]] ; then
MIDDLEOPTIONS+=(-movflags faststart)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-force_key_frames chapters)
MIDDLEOPTIONS+=(-crf 26)
_add_video_filter "yadif"
elif [[ "${OUTPUT_TYPE}" == "m4a" ]] || [[ "${OUTPUT_TYPE}" == "mp3" ]] || [[ "${OUTPUT_TYPE}" == "waveform" ]] ; then
_report -dt "No video stream needed for ${OUTPUT_TYPE}."
elif [[ "${OUTPUT_TYPE}" == "m4a" ]] || [[ "${OUTPUT_TYPE}" == "audiographs" ]] ; then
_report _dt "No video stream needed for ${OUTPUT_TYPE}."
elif [[ "${OUTPUT_TYPE}" == "mp3" ]] || [[ "${OUTPUT_TYPE}" == "audiographs" ]] ; then
_report -dt "No video stream needed for ${OUTPUT_TYPE}."
else
echo "Invalid video derivative type."
fi
fi
if [[ "${AUDIOSTREAMCOUNT}" -gt 0 ]] ; then
_get_audio_index "${SOURCEFILE}"
if [[ "${FORMAT}" == "mov" ]] ; then
AUDIO_STTS_ENTRIES=$(mediaconch -mt "${SOURCEFILE}" | xmlstarlet sel -N mt="https://mediaarea.net/mediatrace" -v -t -m "mt:MediaTrace/mt:media/mt:block[@name='File header']/mt:block[@name='Track'][mt:block[@name='Media']/mt:block[@name='Media Information']/mt:block[@name='Sound Media Header']][1]/mt:block[@name='Media']/mt:block[@name='Media Information']/mt:block[@name='Sample Table']/mt:block[@name='Time to Sample']" -v "mt:data[@name='Number of entries']" )
if [[ "${AUDIO_STTS_ENTRIES}" -gt 2 ]] ; then
_add_audio_filter "aresample=async=1"
_report -d "The audio framerate is variable; adding 'aresample=async=1'"
fi
fi
if [[ "${OUTPUT_TYPE}" == "broadcast" ]] ; then
MIDDLEOPTIONS+=(-acodec pcm_s24be)
MIDDLEOPTIONS+=(-ar 48k)
_get_audio_mapping -bv "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "broadcast_copy" ]] ; then
MIDDLEOPTIONS+=(-map 0:a)
MIDDLEOPTIONS+=(-c:a copy)
elif [[ "${OUTPUT_TYPE}" == "prores" ]] ; then
MIDDLEOPTIONS+=(-map 0:a)
MIDDLEOPTIONS+=(-c:a pcm_s16le)
elif [[ "${OUTPUT_TYPE}" == "youtube" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-b:a 320k)
MIDDLEOPTIONS+=(-ar 48000)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "window" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-b:a 320k)
MIDDLEOPTIONS+=(-ar 48000)
_get_audio_mapping "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "resourcespace" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-b:a 128k)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "quick" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-b:a 96k)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "dvd" ]] ; then
MIDDLEOPTIONS+=(-b:a 448000)
MIDDLEOPTIONS+=(-ar 48000)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "mp3" ]] ; then
MIDDLEOPTIONS+=(-ac 2)
MIDDLEOPTIONS+=(-r:a 44100)
MIDDLEOPTIONS+=(-sample_fmt s16p)
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "podcast" ]] ; then
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ar 48000)
if [[ "${VIDEOSTREAMCOUNT}" -gt 0 ]] ; then
MIDDLEOPTIONS+=(-b:a 96k)
else
MIDDLEOPTIONS+=(-b:a 128k)
MIDDLEOPTIONS+=(-sample_fmt fltp)
fi
_get_audio_mapping -v "${SOURCEFILE}"
elif [[ "${OUTPUT_TYPE}" == "waveform" ]] ; then
MIDDLEOPTIONS+=(-vn)
MIDDLEOPTIONS+=(-frames:v 1)
_add_audio_filter "acrossover=split='15 250 1000 4000'[a01][a02][a03][a04][a05];
[a01]showwavespic=split_channels=1:scale=log:s=1920x240:[email protected][v01];
[a02]showwavespic=split_channels=1:scale=log:s=1920x240:[email protected][v02];
[a03]showwavespic=split_channels=1:scale=log:s=1920x240:[email protected][v03];
[a04]showwavespic=split_channels=1:scale=log:s=1920x240:[email protected][v04];
[a05]showwavespic=split_channels=1:scale=log:s=1920x240:[email protected][v05];
[v01][v02]overlay[v2];
[v2][v03]overlay[v3];
[v3][v04]overlay[v4];
[v4][v05]overlay"
elif [[ "${OUTPUT_TYPE}" == "spectogram" ]] ; then
MIDDLEOPTIONS+=(-vn)
MIDDLEOPTIONS+=(-frames:v 1)
_add_audio_filter "showspectrumpic=mode=combined:color=intensity:scale=log:fscale=lin:s=1024x1024"
elif [[ "${OUTPUT_TYPE}" == "transcriptiondisc" ]] ; then
MIDDLEOPTIONS+=(-ac 1)
_add_audio_filter "adeclick=window=55:overlap=75[DC1];
[DC1]acrossover=split=1500 8000:order=20th[LOW][MID][HIGH];
[LOW]adeclick=window=55:overlap=75[LOW1];
[MID]adeclick=window=55:overlap=75:t=1[MID1];
[HIGH]adeclick=window=55:overlap=75[HIGH1];
[LOW1][MID1][HIGH1]amix=inputs=3[DCMIX];
[DCMIX]highpass=f=60:t=s,lowpass=f=10000:t=s"
elif [[ "${OUTPUT_TYPE}" == "audiographs" ]] ; then
MIDDLEOPTIONS+=(-vn)
MIDDLEOPTIONS+=(-frames:v 1)
MIDDLEOPTIONS+=(-map "[chart]")
_ss_to_hhmmss(){
# if milliseconds are used it will round down to nearest second for instance 60.9, will return 1:00
INT="${1%.*}"
[[ -z "$INT" ]] && INT="0"
DEC="$(echo "${1#*.}" | head -c 3)"
printf "%02d\:%02d\:%02d.${DEC}\n" $(($INT/3600)) $(($INT%3600/60)) $(($INT%60))
}
# image settings
AUDIO_SAMPLE_RATE=48000
HEADER_HEIGHT=24
HEADER_HEIGHT_BIG=$(echo "${HEADER_HEIGHT} * 2" | bc)
TIMELINE_FONTSIZE=16
FONT_FILE="/Library/Fonts/Menlo.ttc"
DRAWGRAPH_SETTINGS="bg=Black"
BORDER_COLOR="LightGrey"
HORIZONTAL_MARKINGS_240="drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:height=ih/16,drawgrid=thickness=1:color=${BORDER_COLOR}@0.5:height=ih/4,drawgrid=thickness=1:color=${BORDER_COLOR}@0.8:height=ih/2"
HORIZONTAL_MARKINGS_120="drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:height=ih/8,drawgrid=thickness=1:color=${BORDER_COLOR}@0.5:height=ih/4,drawgrid=thickness=1:color=${BORDER_COLOR}@0.8:height=ih/2"
BASENAME=$(basename "${INPUT}")
#file variables
SAMPLE_RATE=$(ffprobe "${SOURCEFILE}" -show_entries stream=sample_rate -of default=nw=1:nk=1)
DURATION=$(ffprobe "${SOURCEFILE}" -show_entries stream=duration -of default=nw=1:nk=1)
GRAPH_W=6000
AUDIO_FRAME_SIZE="$(echo "((${DURATION}*${AUDIO_SAMPLE_RATE})/${GRAPH_W})+1" | bc)"
# adding 0.5 in the above equation to ensure that the result is rounded to the nearest integer, rather than simply rounded down
AUDIOFORMAT="aresample=${AUDIO_SAMPLE_RATE},aformat=sample_fmts=dbl,asetnsamples=n=${AUDIO_FRAME_SIZE}:p=0"
VERTICAL_MARKINGS=$(echo "${GRAPH_W} / 150" | bc)
TILE_FLOOR=$(echo "scale=6; ( ( ( ${AUDIO_SAMPLE_RATE} * ${DURATION} ) / ${AUDIO_FRAME_SIZE} ) / ${GRAPH_W} )" | bc | perl -nl -MPOSIX -e 'print floor($_);')
TILE_MOD=$(echo " ( ( ( ${AUDIO_SAMPLE_RATE} * ${DURATION} ) / ${AUDIO_FRAME_SIZE} ) % ${GRAPH_W} )" | bc)
TILE_CEILING=$(echo "scale=6; ( ( ( ${AUDIO_SAMPLE_RATE} * ${DURATION} ) / ${AUDIO_FRAME_SIZE} ) / ${GRAPH_W} ) " | bc | perl -nl -MPOSIX -e 'print ceil($_);')
X_AXIS_MAX=$(echo "scale=6; $DURATION / (( ${TILE_FLOOR} * ${GRAPH_W} + ${TILE_MOD} ) / ( ${TILE_CEILING} * ${GRAPH_W} ))" | bc)
PAD_W="240"
PAD=",pad=iw+${PAD_W}:ih:${PAD_W}:0"
IMAGE_W=$(echo "${GRAPH_W} + ${PAD_W}" | bc)
unset TIMELINE
COUNTER=0
while [ "${COUNTER}" -lt "${VERTICAL_MARKINGS}" ]; do
((COUNTER++))
MARK="$(echo "scale=6; $DURATION * ($COUNTER / $VERTICAL_MARKINGS)" | bc)"
MARK_X="$(echo "scale=6; $GRAPH_W * ($COUNTER / $VERTICAL_MARKINGS)" | bc)"
MARK_TIME="$(_ss_to_hhmmss "${MARK}")"
TIMELINE+=",drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:text='${MARK_TIME}':x=${MARK_X}-text_w:y=(${HEADER_HEIGHT}-${TIMELINE_FONTSIZE})/2"
done
_add_audio_filter "asplit=10[e][f][g][h][i][j][k][l][m][n];`#timeline`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT}${TIMELINE},split=6[top1][top2][top3][top4][top5][top6];color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT_BIG},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=36:text='Audio_QC_Graph_Filename_${BASENAME}_Duration_$(_ss_to_hhmmss "${DURATION}")_Audio_Frame_Size_${AUDIO_FRAME_SIZE}'[Header];`#int_loudnorm`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Interstitial_(with_loudnorm)_-1...1._Differences_in_readings_from_sample_to_sample._May_indicate_dropped_samples.'[intAH];[e]loudnorm=tp=0,${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_difference:m2=adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_difference:min=0:max=1:slide=picture:s=${GRAPH_W}x120,${HORIZONTAL_MARKINGS_120}[intA1];`#min/max`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Min/Max_Level_-1...1._Blue=channel_1,_pink=channel_2.'[minmaxH];[k]${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_level:m2=lavfi.astats.2.Max_level:m3=lavfi.astats.1.Min_level:m4=lavfi.astats.2.Min_level:fg1=0xFFFF00FF:fg2=0xFFFF0000:fg3=0xFFFF00FF:fg4=0xFFFF0000:min=-1:max=1:slide=picture:s=${GRAPH_W}x240,${HORIZONTAL_MARKINGS_240}[minmax1];`#int_unprocessed`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Interstitial_(unprocessed)_-1...1._Differences_in_readings_from_sample_to_sample._May_indicate_dropped_samples.'[intBH];[f]${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_difference:m2=adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_difference:min=0:max=1:slide=picture:s=${GRAPH_W}x120,${HORIZONTAL_MARKINGS_120}[intB1];`#dc_offset`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='DC_Offset_-0.01...0.01._Offsetting_of_the_mean_amplitude_displacement_from_zero,_in_dB._Shows_cumulative_average_over_recording;_the_offset_should_equal_0_by_the_end_of_the_graph.'[dcoffH];[g]${AUDIOFORMAT},astats=metadata=1:reset=0,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.DC_offset:m2=lavfi.astats.2.DC_offset:min=-0.01:max=0.01:slide=picture:s=${GRAPH_W}x240:fg1=if(gte(VAL\,0.005)\,0xFF0000FF\,if(lte(VAL\,-0.005)\,0xFF0000FF\,0xFF00FF00)),${HORIZONTAL_MARKINGS_240}[dcoff1];`#peak/rms_left`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Peak_Level_/_RMS_Level_Left_-70...0dB._Yellow=peak_level,_purple=RMS_level'[peakLH];[h]${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Peak_level:fg1=0xFF00FFFF:m2=lavfi.astats.1.RMS_level:fg2=0xFF800080:max=0:min=-70:slide=picture:mode=bar:s=${GRAPH_W}x240:slide=picture,${HORIZONTAL_MARKINGS_240}[peakL1];`#peak/rms_right`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Peak_Level_/_RMS_Level_Right_-70...0dB._Yellow=peak_level,_purple=RMS_level'[peakRH];[i]${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.2.Peak_level:fg1=0xFF00FFFF:m2=lavfi.astats.2.RMS_level:fg2=0xFF800080:max=0:min=-70:slide=picture:mode=bar:s=${GRAPH_W}x240:slide=picture,${HORIZONTAL_MARKINGS_240}[peakR1];`#crest`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Crest_Factor_0...10._Ratio_of_peak_to_RMS_level_(not_in_dB)._Blue=channel_1,_pink=channel_2.'`#High_levels_may_indicate_prior_compression`[crestH];[n]${AUDIOFORMAT},astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Crest_factor:m2=lavfi.astats.2.Crest_factor:fg1=0xFFFF00FF:fg2=0xFFFF0000:max=10:min=0:slide=picture:mode=line:s=${GRAPH_W}x240:slide=picture,${HORIZONTAL_MARKINGS_240}[crest1];`#phase`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Phase_-1_(out_of_phase)_to_1_(in_phase)._Green=+0.9_to_+1,_reasonable_for_mono/error_for_stereo._Yellow=0_to_+0.9,_error_for_mono/reasonable_for_stereo._Orange=0_to_-0.5,_error_for_mono/strong_possibility_of_error_for_stereo_if_occurring_more_than_briefly._Red=-0.5_to_-1,_error_for_mono/strong_possibility_of_error_for_stereo.'[phaseH];[j]${AUDIOFORMAT},aphasemeter=video=0,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.aphasemeter.phase:max=1:min=-1:slide=picture:s=${GRAPH_W}x240:slide=picture:fg1=if(gte(VAL\,0.9)\,0xFF00FF00\,if(gte(VAL\,0)\,0xFF00FFFF\,if(gte(VAL\,-0.5)\,0xFF0096FF\,0xFF0000FF))),${HORIZONTAL_MARKINGS_240}[phase1];`#null_test_dc`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Null_Test_DC_Offset._Shows_DC_offset_after_one_track_is_inverted_and_overlaid_over_the_other._Should_be_flat_for_mono._Red=-1_to_0,_green=0_to_+1.'[diffH];[l]aeval=val(0)|-val(1),${AUDIOFORMAT},aformat=channel_layouts=mono,astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.DC_offset:min=-0.01:max=0.01:slide=picture:s=${GRAPH_W}x240:fg1=if(lt(VAL\,0)\,0xFF0000FF\,0xFF00FF00),${HORIZONTAL_MARKINGS_240}[diff1];`#null_test_min/max`color=c=${BORDER_COLOR}:s=${GRAPH_W}x${HEADER_HEIGHT},drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=24:text='Null_Test_Min/Max_Levels_-1...1._Shows_min/max_levels_after_one_track_is_inverted_and_overlaid_over_the_other._Blue=channel_1,_pink=channel_2.'[nullminmaxH];[m]aeval=val(0)|-val(1),${AUDIOFORMAT},aformat=channel_layouts=mono,astats=metadata=1:reset=1,adrawgraph=${DRAWGRAPH_SETTINGS}:m1=lavfi.astats.1.Max_level:m2=lavfi.astats.2.Max_level:m3=lavfi.astats.1.Min_level:m4=lavfi.astats.2.Min_level:fg1=0xFFFF00FF:fg2=0xFFFF00FF:fg3=0xFFFF0000:fg4=0xFFFF0000:min=-1:max=1:slide=picture:s=${GRAPH_W}x240,${HORIZONTAL_MARKINGS_240}[nullminmax1];[Header][top1][minmaxH][minmax1][peakLH][peakL1][top2][peakRH][peakR1][crestH][crest1][phaseH][phase1][top3][nullminmaxH][nullminmax1][diffH][diff1][top4][dcoffH][dcoff1][top5][intAH][intA1][intBH][intB1][top6]vstack=27,drawgrid=thickness=1:[email protected]:width=iw/${VERTICAL_MARKINGS},drawgrid=thickness=1:color=${BORDER_COLOR}@0.2:width=(iw/${VERTICAL_MARKINGS})/10[graph];color=c=${BORDER_COLOR}:s=${PAD_W}x${HEADER_HEIGHT_BIG}[HeaderG];color=c=${BORDER_COLOR}:s=${PAD_W}x${HEADER_HEIGHT},split=16[top1G][top2G][top3G][top4G][top5G][top6G][minmaxHG][peakLHG][peakRHG][crestHG][phaseHG][nullminmaxHG][diffHG][dcoffHG][intAHG][intBHG];`#1-1_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x240,drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-0.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='+0.5',drawgrid=thickness=1:[email protected]:height=ih/16,drawgrid=thickness=1:[email protected]:height=ih/4,drawgrid=thickness=1:[email protected]:height=ih/2,split=6[minmax1G][phase1G][crest1G][nullminmax1G][diff1G][dcoff1G];`#1-1_120p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x120,drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='0',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-0.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='+0.5',drawgrid=thickness=1:[email protected]:height=ih/8,drawgrid=thickness=1:[email protected]:height=ih/4,drawgrid=thickness=1:[email protected]:height=ih/2,split=2[intA1G][intB1G];`#0-70_240p_grat`color=c=${BORDER_COLOR}:s=${PAD_W}x240,drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.52:x=w*0.7:text='-35',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.77:x=w*0.7:text='-52.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.27:x=w*0.7:text='-17.5',drawtext=fontfile=${FONT_FILE}:fontcolor=black:fontsize=${TIMELINE_FONTSIZE}:y=h*0.02:x=w*0.7:text='0',drawgrid=thickness=1:[email protected]:height=ih/16,drawgrid=thickness=1:[email protected]:height=ih/4,drawgrid=thickness=1:[email protected]:height=ih/2,split=2[peakL1G][peakR1G];[HeaderG][top1G][minmaxHG][minmax1G][peakLHG][peakL1G][top2G][peakRHG][peakR1G][crestHG][crest1G][phaseHG][phase1G][top3G][nullminmaxHG][nullminmax1G][diffHG][diff1G][top4G][dcoffHG][dcoff1G][top5G][intAHG][intA1G][intBHG][intB1G][top6G]vstack=27[grat];[grat][graph]hstack=2[chart]"
elif [[ "${OUTPUT_TYPE}" == "showwaves" ]] ; then
MIDDLEOPTIONS+=(-vn)
_add_audio_filter "asplit[out0],showwaves=s=1280x720:mode=line:scale=lin,format=gray,negate[out1]"
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-crf 24)
MIDDLEOPTIONS+=(-c:a aac)
MIDDLEOPTIONS+=(-ar 48000)
MIDDLEOPTIONS+=(-map "[out0]")
MIDDLEOPTIONS+=(-map "[out1]")
else
echo "Invalid audio derivative type."
fi
fi
# log process
_prep_ffmpeg_log
if [[ "${CONCATSOURCE}" != "" ]] ; then
FFMPEGINPUT="${CONCATSOURCE}"
fi
# timecode process
TIMECODEOVERLAY=""
if [[ "${INFOBURN}" == "Y" ]] ; then
_get_info_overlay "${SOURCEFILE}"
_add_video_filter "${INFOOVERLAY}"
elif [[ "${TCBURN}" == "Y" ]] ; then
_get_timecode_overlay "${SOURCEFILE}"
_add_video_filter "${TIMECODEOVERLAY}"
elif [[ "${PTSBURN}" == "Y" ]] ; then
_get_timestamp_overlay "${SOURCEFILE}"
_add_video_filter "${TIMECODEOVERLAY}"
fi
# subtitle process
if [[ -n "${SUBTITLE_FILE}" ]] ; then
_get_subtitle_overlay "${SOURCEFILE}"
_add_video_filter "${SUBTITLEOVERLAY}"
fi
# slate process
if [[ "${ADDSLATE}" == "Y" ]] ; then
if [[ "${OUTPUT_TYPE}" != "broadcast" ]] ; then
echo "ADDSLATE is only valid with broadcast derivatives. Please specify -T broadcast."
break
else
_add_video_filter "copy[program_video]"
_add_audio_filter "[1:v:0][2:a:0][3:v:0][4:a:0][5:v:0][6:a:0][7:v:0][8:a:0]concat=n=4:v=1:a=1[slate_v][slate_a];[slate_v]drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=158:textfile=${SLATE_MEDIAID},drawtext=fontsize=80:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=340:textfile=${SLATE_SERIES},drawtext=fontsize=50:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=460:textfile=${SLATE_EPISODE},drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=793:text='VIDEO',drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=831:text='1080i',drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=388:y=869:text='59.94DF',drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=790:y=793:text='AUDIO',drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=790:y=831:textfile=${SLATE_CH1},drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=790:y=869:textfile=${SLATE_CH2},drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=790:y=908:textfile=${SLATE_CH3},drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=790:y=947:textfile=${SLATE_CH4},drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=1151:y=908:text='Duration',drawtext=fontsize=32:fontfile=${fontfile}:fontcolor=white:${fontenable}:x=1151:y=947:textfile=${SLATE_DURATION},drawtext=fontsize=420:fontfile=${fontfile}:fontcolor=white:enable=gte(t\,${COLORBARS_SECS}+${SLATE_SECS})*lt(t\,${COLORBARS_SECS}+${SLATE_SECS}+${COUNTDOWN_SECS}):x=(w-text_w)/2:y=(h-text_h-line_h)/2:text='%{eif\:${COLORBARS_SECS}+${SLATE_SECS}+11-t\:d}',scale=size=hd1080,format=yuv422p,setsar=1/1,setdar=16/9,fps=fps=ntsc[slate_v1];[slate_a]asplit[slate_stereo1][slate_stereo2];[slate_stereo2]aformat=channel_layouts=mono,asplit[slate_mono1][slate_mono2];[9:v:0]format=yuv422p,setsar=1/1,setdar=16/9[end_black];[10:a:0]asplit[end_stereo1][end_stereo2];[end_stereo2]aformat=channel_layouts=mono,asplit[end_mono1][end_mono2];[slate_v1][slate_stereo1][slate_mono1][slate_mono2][program_video][stereo1][mono1][mono2][end_black][end_stereo1][end_mono1][end_mono2]concat=n=3:v=1:a=3[with_slate_video][with_slate_stereo1][with_slate_mono1][with_slate_mono2]"
MIDDLEOPTIONS+=(-map "[with_slate_video]" -map "[with_slate_stereo1]" -map "[with_slate_mono1]" -map "[with_slate_mono2]")
fi
fi
# temporary output set for dvd to allow mpeg -> iso transition
if [[ "${OUTPUT_TYPE}" == "dvd" ]] ; then
OUTPUT_TMP="$OUTPUT"
OUTPUT="${OUTPUT%.iso}.mpeg"
fi
MIDDLEOPTIONS+=(-metadata creation_time=now)
_filter_to_middle_option
_run_critical_event ffmpeg "${INPUTOPTIONS[@]}" "${FFMPEGINPUT[@]}" "${MIDDLEOPTIONS[@]}" "${OUTPUT}"
# DVD VIDEO_TS folder process: chapters every 5 minutes, dvdauthor will ignore chapter markers greater than duration
if [[ "${OUTPUT_TYPE}" == "dvd" ]] ; then
export VIDEO_FORMAT=NTSC
OUTPUT="$OUTPUT_TMP"
_run_critical dvdauthor --title -v "ntsc+${DVDASPECT}" -a ac3+en -c 0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,1:00:00,1:05:00,1:10:00,1:15:00,1:20:00,1:25:00,1:30:00,1:35:00,1:40:00,1:45:00,1:50:00,1:55:00,2:00:00,2:05:00,2:10:00,2:15:00,2:20:00,2:25:00,2:30:00,2:35:00,2:40:00,2:45:00,2:50:00,2:55:00,3:00:00,3:05:00,3:10:00,3:15:00,3:20:00,3:25:00,3:30:00,3:35:00,3:40:00,3:45:00,3:50:00,3:55:00 -f "${OUTPUTDIR}/${MEDIAID%.*}.mpeg" -o "${OUTPUTDIR}/${MEDIAID%.*}/" 2> "${LOGDIR}/dvdauthor_$(_get_iso8601_c)_$(basename ${0})_${VERSION}.txt"
_run rm "${OUTPUTDIR}/${MEDIAID%.*}.mpeg"
_run_critical_event dvdauthor -T -o "${OUTPUTDIR}/${MEDIAID%.*}/"
# Making DVD image file
volname=$(echo "${DVDLABELPREFIX}${MEDIAID}")
_run_critical_event mkisofs -f -dvd-video -udf -V "${volname:0:32}" -v -v -o "${OUTPUT}" "${OUTPUTDIR}/${MEDIAID%.*}" 2> "${LOGDIR}/mkisofs_$(_get_iso8601_c)_$(basename ${0})_${VERSION}.txt"
_run rm -r "${OUTPUTDIR}/${MEDIAID%.*}/"
fi
echo
_summarize_make
if [[ "${OUTPUT_TYPE}" == "broadcast" ]] && [[ -z "${MAKEBROADCAST_DELIVERY_EMAIL_TO}" ]] ; then
_deliver_output "${MAKEBROADCAST_DELIVERY_EMAIL_TO}"
else
_deliver_output "${EMAILADDRESS_DELIVERY}"
fi
# youtube upload process
if [[ "${YOUTUBEUPLOAD}" == "Y" ]] ; then
if [[ "${OUTPUT_TYPE}" != "youtube" ]]; then
echo "YOUTUBEUPLOAD is only valid with youtube (H264) derivatives. Please specify -T youtube."
break
elif [ $(which uploadyoutube) ] ; then
_report -dt "Attempting to run uploadyoutube on ${OUTPUT}"
uploadyoutube "${OUTPUT}"
echo "$(_get_iso8601),${OUTPUT},attempted upload,$?" >> "${HOME}/Desktop/upload.log"
_deliver_output "${MAKEYOUTUBE_DELIVERY_EMAIL_TO}"
else
_report -wt "$(basename "${OUTPUT}") qualified for uploadyoutube but it is not installed."
fi
fi
_log -e
done
unset ADDSLATE
unset YOUTUBEUPLOAD