]> git.phdru.name Git - audio-cdr-video.git/blob - video/tc_encode_x264
Initail import
[audio-cdr-video.git] / video / tc_encode_x264
1 #! /bin/sh
2
3 if [ -z "$1" ]; then
4    echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [abitrate=n] [ascale=s] $0 input.avi"
5    exit 1
6 fi
7
8 if [ -z "$vcodec" ]; then
9    vcodec=x264
10 else
11    vcodec="$vcodec"
12 fi
13
14 if [ -z "$vbitrate" ]; then
15    vbitrate=2200
16 else
17    vbitrate="$vbitrate"
18 fi
19
20 if [ -n "$vscale" ]; then
21    vscale="-Z $vscale"
22 fi
23
24 if [ -z "$abitrate" ]; then
25    abitrate=320
26 else
27    abitrate="$abitrate"
28 fi
29
30 if [ -n "$ascale" ]; then
31    ascale="-s $ascale"
32 fi
33
34 if [ "$vcodec" = x264 ]; then
35    vopts="--bitrate=$vbitrate"
36
37 elif [ "$vcodec" = x264-hq ]; then
38    vopts="--bitrate=$vbitrate --8x8dct --ref=2 --bframes=3 --b-pyramid --weightb"
39
40 elif [ "$vcodec" = x264-vhq ]; then
41    vopts="--bitrate=$vbitrate --8x8dct --ref=5 --bframes=3 --b-pyramid --weightb --partitions=all --me=umh"
42
43 else
44    echo "Unknown video codec $vcodec; known codecs are x264[-[v]hq]" >&2
45    exit 1
46 fi
47
48 if [ -z "$pass" ]; then
49    pass=1
50 else
51    pass="$pass"
52 fi
53
54 # Video
55 transcode -i "$1" -x auto,null -y yuv4mpeg,null -k -u 50 $vscale $ascale -o _tmp.y4m || exit 1
56
57 if [ "$pass" -eq 1 ]; then
58    x264 $vopts --progress -o _tmp.mkv           _tmp.y4m || exit 1
59
60 elif [ "$pass" -eq 2 ]; then
61    x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m &&
62    x264 $vopts --progress -o _tmp.mkv  --pass=2 _tmp.y4m || exit 1
63
64 elif [ "$pass" -eq 3 ]; then
65    x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m &&
66    x264 $vopts --progress -o /dev/null --pass=3 _tmp.y4m &&
67    x264 $vopts --progress -o _tmp.mkv  --pass=3 _tmp.y4m || exit 1
68                                        # pass=3 is not a typo!
69
70 else
71    echo "Can only do 1, 2 or 3 passes." >&2
72    exit 1
73 fi
74
75 # Audio
76 transcode -i "$1" -x null,auto -y null,ogg -g 0x0 -b "$abitrate" -m _tmp.ogg &&
77
78 exec mkvmerge -o output.mkv -A _tmp.mkv _tmp.ogg