-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcode-ntsc
executable file
·78 lines (62 loc) · 1.87 KB
/
transcode-ntsc
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
#!/bin/bash
set -eu
if [ $# -eq 0 ]; then cat << EOF
Transcodes an interlaced NTSC video to MKV (x264)
${0} [options] input.mpg [output.mkv]
Options:
-s [HH:[MM:]]SS Starts transcoding from this timecode.
-t [HH:[MM:]]SS Ends transcoding at this timecode.
-x CODEC Uses a hardware-accelerated video codec.
Hardware encoding trades space for extreme speed.
Set "ffmpeg=/path/to/ffmpeg" to use a custom build.
Known hardware codecs:
h264_nvenc
If no output file name is given, it defaults to a similarly named
MKV in the working directory.
Output file size per hour of transcoded video:
x264 (default) ~1GB/hr
h264_nvenc ~1.5GB/hr
EOF
exit 1
fi
ffmpeg=${ffmpeg:-ffmpeg}
StartTime=""
EndTime=""
VideoCodec="libx264"
VideoOpts="-crf 23 -preset veryslow"
while getopts ":s:t:x:" opt; do case $opt in
s) StartTime="-ss ${OPTARG}"
;;
t) EndTime="-t ${OPTARG}"
;;
x) VideoCodec="${OPTARG}"
case $VideoCodec in
h264_nvenc)
# x264 has better bang per bit. try to match x264 crf 23.
# this is ~1.5GB/hr (but it's so fast uwu)
# avg avgq vbr same as x264 slowest(implied 2pass+cabac)
VideoOpts="-b:v 3000k -cq 19 -rc vbr_hq -rc-lookahead 60 -preset slow -profile:v high"
;;
esac
;;
esac done
shift $((OPTIND-1))
Input="${1}"
if [ $# -eq 1 ]; then
Basename=$(basename "${Input}")
Output="${Basename%.*}.mkv"
else
Output="${2}"
fi
$ffmpeg \
$EndTime \
-hwaccel auto \
-i "${Input}" \
-c:a copy \
-vf "yadif" \
-c:v ${VideoCodec} \
${VideoOpts} \
-metadata creation_time="$(date --iso-8601=seconds)" \
-movflags +faststart \
$StartTime \
"${Output}"