-
Notifications
You must be signed in to change notification settings - Fork 0
/
enc.video
executable file
·788 lines (653 loc) · 19.1 KB
/
enc.video
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
#!/bin/sh
set -e -u
error()
{
case $1 in
"
"*) ;;
*) printf '\n' >&2
esac
printf '%s' "$1" >&2
case $1 in
*"
") ;;
*) printf '\n' >&2
esac
exit 1
}
command -v ffmpeg >/dev/null || error "ffmpeg not found in \$PATH!"
badargs()
{
bin="./$(basename "$0")"
syntax="
Syntax:
$bin [options] <profile> <input_file> <output_file>
$bin [options] <profile> <input_file> ... <output_directory>
The container format is guessed by the file extension of the output file.
E.g. \".mp4\" generates an MPEG 4 container file, whereas \".webm\" would
generate a WEBM container, and \".mov\" would create a MOV container.
If output is a directory, the same file name as input will be used, except for
the file extension which will be the default extension for the default
container format of the chosen profile, unless overridden by the \"extension\"
option.
NOTE:
Not all codecs can be used in all container formats!
Options:
NOTE:
Options can be shortened. E.g. \"vol\" and \"volume\" are the same option.
sc[ale]=half|quarter|double|x%|w:h
half - Halves the video resolution.
quarter - Quarters the video resolution.
double - Doubles the video resolution.
x% - Scales the video by x percent (up or down).
w:h - Scales to width (w) and height (h).
Set either one to -1 and it will be calculated by the other
value to maintain the video aspect ratio.
vol[ume]=<p%|max>
Volume can either be in percent (\"90%\"), allowing increasing and
decreasing volume by any amount desired (up to the point where the
output clips), or it can be \"max\" in which case the maximum
amplication is calculated that is possible without causing any
clipping.
ext[ension]=<ext>
Overrides output file extension in case output is a directory,
e.g. \"ext=mp3\". Has no effect if output is a file name.
Valid profile names are:
vlow - Very low quality (H.264/AAC).
low - Low quality (H.264/AAC).
std - Standard quality (H.264/AAC).
high - High quality (H.264/AAC).
vhigh - Very high quality (H.264/AAC).
500k - Limit total bandwidth to 500kbit/s (H.264/AAC).
1m - Limit total bandwidth to 1Mbit/s (H.264/AAC).
2m - Limit total bandwidth to 2Mbit/s (H.264/AAC).
3m - Limit total bandwidth to 2Mbit/s (H.264/AAC).
4m - Limit total bandwidth to 4Mbit/s (H.264/AAC).
6m - Limit total bandwidth to 6Mbit/s (H.264/AAC).
8m - Limit total bandwidth to 8Mbit/s (H.264/AAC).
scrcast - Screencast with very low bitrate (H.264/AAC).
webcast - Web screencast with low bitrate (VP9/Opus).
bug - Screen recording for bug reporting (H.264).
bugwebm - As bug but using VP9 (VP9).
gif - Animated GIF (or APNG).
gifo - Animated GIF (or APNG) w/ optimized palette.
transform - Copy audio/video data unmodified, just rewrite container.
"
error "$syntax"
}
scale=
volume=
outfileExt=
profile=
output=
inCount=0
while [ -z "$output" ]
do
if [ $# -lt 3 ]
then
printf "%s\n" "Too little arguments!" >&2
badargs
fi
case $1 in
"sc="*)
scale=${1#"sc="}
shift
;;
"scale="*)
scale=${1#"scale="}
shift
;;
"vol="*)
volume=${1#"vol="}
shift
;;
"volume="*)
volume=${1#"volume="}
shift
;;
"ext="*)
outfileExt=${1#"ext="}
shift
;;
"extension="*)
outfileExt=${1#"extension="}
shift
;;
*)
profile=$1
shift
inCount=$(( $# - 1 ))
eval "output=\${$#}"
;;
esac
done
if [ $inCount -gt 1 ] && [ ! -d "$output" ]
then
error "Multiple input files are only allowed if output is a directory!"
fi
volarg=
case "$volume" in
"")
# No volume set - fine
;;
"max")
# We'll take care of that later
volume="max"
;;
*"%")
volarg=${volume%"%"}
volarg="volume=$volarg/100"
;;
*)
error "Bad volume value \"$volume\"!"
;;
esac
scarg=
case "$scale" in
"")
# No scale set
;;
*":"*)
scarg="scale=$scale"
# Width and height set
;;
"half")
scarg="scale=0.5*iw:-1"
;;
"quarter")
scarg="scale=0.25*iw:-1"
;;
"double")
scarg="scale=2*iw:-1"
;;
*"%")
scarg=${scale%"%"}
scarg="scale=$scarg/100*iw:-1"
;;
*)
error "Bad scale value \"$scale\"!"
;;
esac
[ -z "$scarg" ] || \
scarg="$scarg:force_original_aspect_ratio=decrease:force_divisible_by=8"
onexit()
{
oldtraps=$(trap)
oldexit=$(echo "$oldtraps" \
| grep "EXIT$" \
| sed -E 's/^trap -- (.*) EXIT$/\1/')
if [ -n "$oldexit" ]
then
# shellcheck disable=SC2064
trap "eval $oldexit ; $1" EXIT
else
# shellcheck disable=SC2064
trap "$1" EXIT
fi
}
encargs=""
decargs=""
twopass=""
hascoder()
{
encfound=$(ffmpeg -encoders 2>/dev/null | grep -E "^ [^ ]+ $1 ")
if [ -n "$encfound" ]
then
return 0
fi
return 1
}
# $1 - bitrate in kbit/s (must be 16 kbit/s or higher)
# ($2) - "stereo" or "mono"; default is "stereo"
# ($3) - force HE/HEv2: "yes" or "no"; default is "no"
activate_aac()
{
if [ "$1" -lt 16 ]
then
echo "AAC bitrate too low!" >&2
exit 1
fi
if [ "${2:-"stereo"}" = "mono" ]
then
encargs="$encargs -ac 1" # Convert audio to mono
else
encargs="$encargs -ac 2" # Convert audio to stereo
fi
encargs="$encargs -b:a ${1}k" # Set bitrate in kbit/s
if [ "$1" -lt 80 ] || [ "${3:-"no"}" = "yes" ]
then
if [ "${2:-"stereo"}" = "mono" ]
then
if hascoder "aac_at"
then
encargs="$encargs -c:a aac_at" # AAC audio
encargs="$encargs -profile:a 28" # Use HEv2 encoding
return
fi
if hascoder "libfdk_aac"
then
encargs="$encargs -c:a libfdk_aac" # AAC audio
encargs="$encargs -profile:a aac_he_v2" # Use HEv2 encoding
return
fi
fi
if hascoder "aac_at"
then
encargs="$encargs -c:a aac_at" # AAC audio
encargs="$encargs -profile:a 4" # Use HE encoding
return
fi
if hascoder "libfdk_aac"
then
encargs="$encargs -c:a libfdk_aac" # AAC audio
encargs="$encargs -profile:a aac_he" # Use HE encoding
return
fi
if [ "${3:-"no"}" = "yes" ]
then
echo "No encoder with HE/HEv2 support found!" >&2
exit 1
fi
# Fallback to non HE/HEv2 if allowed
if hascoder "aac"
then
encargs="$encargs -c:a aac" # AAC audio
encargs="$encargs -aac_coder twoloop" # Tread CPU time for quality
return
fi
fi
if hascoder "aac_at"
then
encargs="$encargs -c:a aac_at" # AAC audio
encargs="$encargs -aac_at_mode abr" # Set ABR mode
return
fi
if hascoder "libfdk_aac"
then
encargs="$encargs -c:a libfdk_aac" # AAC audio
return
fi
if hascoder "aac"
then
encargs="$encargs -c:a aac" # AAC audio
encargs="$encargs -aac_coder twoloop" # Tread CPU time for quality
return
fi
echo "No AAC encoder found!" >&2
exit 1
}
case "$profile" in
"vlow")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 34" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset veryslow" # Treat time for compression
# Audio
activate_aac 96
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"low")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 28" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset slower" # Treat time for compression
# Audio
activate_aac 128
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"std")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 24" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset slow" # Treat time for compression
# Audio
activate_aac 144
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"high")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 21" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset slower" # Treat time for compression
# Audio
activate_aac 160
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"vhigh")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 18" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset veryslow" # Treat time for compression
# Audio
activate_aac 192
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"500k")
# Video
encargs="$encargs -maxrate 500k" # Set max total bitrate
encargs="$encargs -bufsize 3M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 436k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset veryslow" # Treat more time for quality
# Audio
activate_aac 64
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"1m")
# Video
encargs="$encargs -maxrate 1M" # Set max total bitrate
encargs="$encargs -bufsize 2M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 904k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset veryslow" # Treat more time for quality
# Audio
activate_aac 96
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"2m")
# Video
encargs="$encargs -maxrate 2M" # Set max total bitrate
encargs="$encargs -bufsize 2M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 1872k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset slower" # Treat more time for quality
# Audio
activate_aac 128
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"3m")
# Video
encargs="$encargs -maxrate 3M" # Set max total bitrate
encargs="$encargs -bufsize 3M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 2856k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -preset slow" # Treat more time for quality
# Audio
activate_aac 144
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"4m")
# Video
encargs="$encargs -maxrate 4M" # Set max total bitrate
encargs="$encargs -bufsize 4M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 3840k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
# Audio
activate_aac 160
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"6m")
# Video
encargs="$encargs -maxrate 6M" # Set max total bitrate
encargs="$encargs -bufsize 4M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 5808k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
# Audio
activate_aac 192
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"8m")
# Video
encargs="$encargs -maxrate 8M" # Set max total bitrate
encargs="$encargs -bufsize 4M" # Set buffer size
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -b:v 7808k" # Set video bitrate
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
# Audio
activate_aac 192
# Other
twopass=1
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"scrcast")
# Video
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 38" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -tune animation" # Tune for animated large flat areas
encargs="$encargs -preset veryslow" # Treat more time for quality
# Audio
activate_aac 24 mono
# Other
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"webcast")
# Video
encargs="$encargs -c:v vp9" # VP9 video
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 56" # Encode all frames with same quality
encargs="$encargs -tune-content screen" # Tune for screen recording
encargs="$encargs -cpu-used 0" # Trade speed for quality
encargs="$encargs -lag-in-frames 25" # Trade lag for quality
encargs="$encargs -auto-alt-ref 6" # Trade lag for quality
encargs="$encargs -row-mt 1" # Use multiple cores more aggressively
# Audio
encargs="$encargs -c:a libopus" # Opus audio
encargs="$encargs -b:a 24k" # Set bitrate
encargs="$encargs -ar 24000" # Lower sampling rate to 24000 Hz
encargs="$encargs -ac 1" # Convert audio to mono
# Other
[ -z "$outfileExt" ] && outfileExt="webm"
onexit "rm -f opsnr.stt"
;;
"bug")
# Video
decargs="$decargs -an" # Don't even decode audio
encargs="$encargs -c:v h264" # H.264 video
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 38" # Encode all frames with same quality
encargs="$encargs -profile:v high" # Use H.264 high profile
encargs="$encargs -level:v 5.2" # Use level 5.2
encargs="$encargs -tune animation" # Tune for animated large flat areas
encargs="$encargs -preset veryslow" # Treat more time for quality
[ -z "$outfileExt" ] && outfileExt="mp4"
;;
"bugwebm")
# Video
decargs="$decargs -an" # Don't even decode audio
encargs="$encargs -c:v vp9" # VP9 video
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
encargs="$encargs -vsync vfr" # Allow varible frame rate
encargs="$encargs -crf 56" # Encode all frames with same quality
encargs="$encargs -tune-content screen" # Tune for screen recording
encargs="$encargs -cpu-used 0" # Trade speed for quality
encargs="$encargs -lag-in-frames 25" # Trade lag for quality
encargs="$encargs -auto-alt-ref 6" # Trade lag for quality
encargs="$encargs -row-mt 1" # Use multiple cores more aggressively
# Other
[ -z "$outfileExt" ] && outfileExt="webm"
onexit "rm -f opsnr.stt"
;;
"gif")
# Video
decargs="$decargs -an" # Don't even decode audio
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
# Other
[ -z "$outfileExt" ] && outfileExt="gif"
;;
"gifo")
# Video
decargs="$decargs -an" # Don't even decode audio
encargs="$encargs -fpsmax 10" # Limit FPS to 10 or below
# Other
[ -z "$outfileExt" ] && outfileExt="gif"
;;
"transform")
if [ -z "$outfileExt" ]
then
error "Profile \"transform\" requires \"extension\" option!"
fi
if [ -n "$scarg" ]
then
error "Profile \"transform\" does not support \"scale\" option!"
fi
if [ -n "$volarg" ]
then
error "Profile \"transform\" does not support \"volume\" option!"
fi
encargs="$encargs -c:v copy" # Copy video data
encargs="$encargs -c:a copy" # Copy audio data
;;
*)
error "Unknown profile \"$profile\"!"
;;
esac
abspath()
(
path=$1
if [ ! -e "$path" ]; then
return 1
fi
file=
dir="$path"
if [ ! -d "$dir" ]; then
file=$( basename "$dir" )
dir=$( dirname "$dir" )
fi
case "$dir" in
/*) ;;
*) dir="$( pwd )/$dir"
esac
result=$( cd "$dir" && pwd )
if [ -n "$file" ]; then
case "$result" in
*/) ;;
*) result="$result/"
esac
result="$result$file"
fi
printf "%s\n" "$result"
)
basenameWithoutExt()
{
printf '%s' "$( basename "$1" | cut -f1 -d'.' )"
}
calcMaxVolume()
{
printf "%s\n" "==> Analyzing audio, please wait..."
volarg=$(
ffmpeg -i "$1" -filter:a volumedetect \
-f null /dev/null 2>&1 \
| grep max_volume \
| sed 's/.*max_volume: -\{0,1\}\([0-9.]\{1,\}\) dB$/\1/'
)
if [ "$volarg" = "0.0" ]
then
printf "%s\n" "==> Volume already at maximum."
volarg=
else
printf "%s\n" "==> Emphasizing volume by $volarg dB."
volarg="volume=${volarg}dB"
fi
}
while [ $inCount -gt 0 ]
do
printf "\n%s\n" "====> Next File: $1"
[ "$volume" = "max" ] && calcMaxVolume "$1"
if [ -d "$output" ]
then
outfile="$output/$( basenameWithoutExt "$1" ).$outfileExt"
if [ "$(abspath "$1")" = "$(abspath "$outfile")" ]
then
echo "Input file cannot override itself!" >&2
exit 1
fi
else
outfile="$output"
fi
case "$profile" in
"gifo")
tempdir=$(mktemp -d)
onexit "rm -r '$tempdir'"
palette="$tempdir/palette.png"
p1args="-filter_complex \"[0:v] palettegen\""
p2args="-i \"$palette\" -filter_complex \"[0:v][1:v] paletteuse\""
filterargs=
[ -n "$scarg" ] && filterargs="-filter:v \"$scarg\""
eval ffmpeg "$decargs" -i "\"$1\"" \
"$encargs" "$filterargs" "$p1args" "\"$palette"\"
eval ffmpeg "$decargs" -i "\"$1\"" \
"$p2args" "$encargs" "$filterargs" "\"$outfile"\"
;;
*)
filterargs=
[ -n "$volarg" ] && filterargs="-filter:a $volarg"
[ -n "$scarg" ] && filterargs="$filterargs -filter:v \"$scarg\""
if [ -n "$twopass" ]
then
tempdir=$(mktemp -d)
onexit "rm -r '$tempdir'"
passlog="-passlogfile \"$tempdir/2pass.log\""
p1args="-pass 1 $passlog -f null"
p2args="-pass 2 $passlog"
eval ffmpeg "$decargs" -i "\"$1\"" \
"$encargs" "$filterargs" "$p1args" /dev/null
eval ffmpeg "$decargs" -i "\"$1\"" \
"$encargs" "$filterargs" "$p2args" "\"$outfile"\"
else
eval ffmpeg "$decargs" -i "\"$1\"" \
"$encargs $filterargs" "\"$outfile"\"
fi
;;
esac
shift
inCount=$(( inCount - 1 ))
printf "\n\n"
done