-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2pass_encode_test.sh
More file actions
executable file
·72 lines (61 loc) · 2.33 KB
/
2pass_encode_test.sh
File metadata and controls
executable file
·72 lines (61 loc) · 2.33 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
#!/bin/bash
set -e
set -x
SOURCE="source"
ENCODED="encoded"
DONE="done"
mkdir -p "$SOURCE" "$ENCODED" "$DONE"
res=("3840:-2" "2560:-2" "1920:-2" "1280:-2" "854:-2" "480:-2")
bitrate=("26000k" "15000k" "7000k" "4000k" "2000k" "1000k")
for INPUT in "$SOURCE"/*; do
[ -e "$INPUT" ] || continue
BASENAME=$(basename "$INPUT")
NAME="${BASENAME%.*}"
OUTDIR="$ENCODED/$NAME"
echo "Encoding $BASENAME"
mkdir -p "$OUTDIR"
for i in ${!res[@]}; do
BUFSIZE=$(( 2 * ${bitrate[i]%k} ))k
ffmpeg -y -i "$INPUT" -vf "scale=${res[i]}" -c:v libx264 \
-b:v ${bitrate[i]} -minrate:v ${bitrate[i]} \
-maxrate:v ${bitrate[i]} -bufsize:v ${BUFSIZE} \
-g 120 -keyint_min 120 \
-force_key_frames "expr:gte(t,n_forced*4)" \
-pass 1 -passlogfile "$OUTDIR/res_$i.log" -an -f mp4 /dev/null
if [ $i -eq 0 ]; then
ffmpeg -y -i "$INPUT" -vf "scale=${res[i]}" -c:v libx264 \
-b:v ${bitrate[i]} -minrate:v ${bitrate[i]} \
-maxrate:v ${bitrate[i]} -bufsize:v ${BUFSIZE} \
-g 120 -keyint_min 120 \
-force_key_frames "expr:gte(t,n_forced*4)" \
-pass 2 -passlogfile "$OUTDIR/res_$i.log" \
-c:a aac -b:a 128k -ac 2 "$OUTDIR/res_$i.mp4"
else
ffmpeg -y -i "$INPUT" -vf "scale=${res[i]}" -c:v libx264 \
-b:v ${bitrate[i]} -minrate:v ${bitrate[i]} \
-maxrate:v ${bitrate[i]} -bufsize:v ${BUFSIZE} \
-g 120 -keyint_min 120 \
-force_key_frames "expr:gte(t,n_forced*4)" \
-pass 2 -passlogfile "$OUTDIR/pass_$i.log" \
-an "$OUTDIR/res_$i.mp4"
fi
rm -f "$OUTDIR/res_$i.log"*
done
DASH_CMD="ffmpeg"
for i in ${!res[@]}; do
DASH_CMD+=" -i $OUTDIR/res_$i.mp4"
done
MAP_ARGS=""
for i in ${!res[@]}; do
MAP_ARGS+=" -map $i:v "
done
MAP_ARGS+=" -map 0:a"
$DASH_CMD $MAP_ARGS -c copy \
-f dash -seg_duration 5 -use_timeline 1 -use_template 1 \
-init_seg_name "init-$NAME-\$RepresentationID\$.mp4" \
-media_seg_name "chunk-$NAME-\$RepresentationID\$-\$Number%05d\$.m4s" \
-adaptation_sets "id=0,streams=v id=1,streams=a" \
"$OUTDIR/$NAME.mpd"
echo "Done Encoding $BASENAME"
mv "$INPUT" "$DONE/"
done