annotate DOCS/tech/encoding-tips.txt @ 16205:4183c4585f1d

URL update
author gpoirier
date Fri, 12 Aug 2005 14:14:29 +0000
parents 23237af42335
children 2de4d051dd21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9012
805b19425c19 some URLs
arpi
parents: 8463
diff changeset
1
805b19425c19 some URLs
arpi
parents: 8463
diff changeset
2 Some important URLs:
805b19425c19 some URLs
arpi
parents: 8463
diff changeset
3 ~~~~~~~~~~~~~~~~~~~~
16205
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
4 http://www.mplayerhq.hu/~michael/codec-features.html <- lavc vs. divx5 vs. xvid
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
5 http://www.ee.oulu.fi/~tuukkat/mplayer/tests/rguyom.ath.cx/ <- lavc benchmarks, options
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
6 http://ffdshow.sourceforge.net/tikiwiki/tiki-view_articles.php <- lavc for win32 :)
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
7 http://www.bunkus.org/dvdripping4linux/index.html <- a nice tutorial
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
8 http://forum.zhentarim.net/viewtopic.php?p=237 <- lavc option comparison
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
9 http://www.ee.oulu.fi/~tuukkat/mplayer/tests/readme.html <- series of benchmarks
9012
805b19425c19 some URLs
arpi
parents: 8463
diff changeset
10
11423
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
11
9012
805b19425c19 some URLs
arpi
parents: 8463
diff changeset
12 ================================================================================
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
13
11423
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
14
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
15 FIXING A/V SYNC WHEN ENCODING
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
16
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
17 I know this is a popular topic on the list, so I thought I'd share a
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
18 few comments on my experience fixing a/v sync. As everyone seems to
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
19 know, mencoder unfortunately doesn't have a -delay option. But that
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
20 doesn't mean you can't fix a/v sync. There are a couple ways to still
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
21 do it.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
22
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
23 In example 1, we'll suppose you want to re-encode the audio anyway.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
24 This will be essential if your source audio isn't mp3, e.g. for DVD's
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
25 or nasty avi files with divx/wma audio. This approach makes things
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
26 much easier.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
27
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
28 Step 1: Dump the audio with mplayer -ao pcm -nowaveheader. There are
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
29 various options that can be used to speed this up, most notably -vo
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
30 null, -vc null, and/or -hardframedrop. -benchmark also seemed to help
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
31 in the past. :)
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
32
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
33 Step 2: Figure out what -delay value syncs the audio right in mplayer.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
34 If this number is positive, use a command like the following:
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
35
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
36 dd if=audiodump.wav bs=1764 skip=[delay] | lame -x - out.mp3
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
37
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
38 where [delay] is replaced by your delay amount in hundredths of a
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
39 second (1/10 the value you use with mplayer). Otherwise, if delay is
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
40 negative, use a command like this:
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
41
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
42 ( dd if=/dev/zero bs=1764 skip=[delay] ; cat audiodump.wav ) | lame -x - out.mp3
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
43
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
44 Don't include the minus (-) sign in delay. Also, keep in mind you'll
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
45 have to change the 1764 number and provide additional options to lame
13047
4e613c87c2f5 spelling: big-endian and little-endian
diego
parents: 13022
diff changeset
46 if your audio stream isn't 44100/16bit/little-endian/stereo.
11423
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
47
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
48 Step 3: Use mencoder to remux your new mp3 file with the movie:
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
49
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
50 mencoder -audiofile out.mp3 -oac copy ...
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
51
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
52 You can either copy video as-is (with -ovc copy) or re-encode it at
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
53 the same time you merge in the audio like this.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
54
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
55 Finally, as a variation on this method (makes things a good bit faster
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
56 and doesn't use tons of temporary disk space) you can merge steps 1
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
57 and 2 by making a named pipe called "audiodump.wav" (type mkfifo
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
58 audiodump.wav) and have mplayer write the audio to it at the same time
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
59 you're running lame to encode.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
60
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
61 Now for example 2. This time we won't re-encode audio at all. Just
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
62 dump the mp3 stream from the avi file with mplayer -dumpaudio. Then,
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
63 you have to cut and paste the raw mp3 stream a bit...
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
64
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
65 If delay is negative, things are easier. Just use lame to encode
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
66 silence for the duration of delay, at the same samplerate and
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
67 samplesize used in your avi file. Then, do something like:
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
68
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
69 cat silence.mp3 stream.dump > out.mp3
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
70 mencoder -audiofile out.mp3 -oac copy ...
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
71
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
72 On the other hand, if delay is positive, you'll need to crop off part
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
73 of the mp3 from the beginning. If it's (at least roughly) CBR this is
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
74 easy -- just take off the first (bitrate*delay/8) bytes of the file.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
75 You can use the excellent dd tool, or just your favorite
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
76 binary-friendly text editor to do this. Otherwise, you'll have to
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
77 experiment with cutting off different amounts. You can test with
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
78 mplayer -audiofile before actually spending time remuxing/encoding
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
79 with mencoder to make sure you cut the right amount.
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
80
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
81 I hope this has all been informative. If anyone would like to clean
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
82 this message up a bit and make it into part of the docs, feel free. Of
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
83 course mencoder should eventually just get -delay. :)
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
84
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
85 Rich
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
86
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
87
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
88 ================================================================================
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
89
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
90
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
91 ENCODING QUALITY - OR WHY AUTOMATISM IS BAD.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
92
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
93 Hi everyone.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
94
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
95 Some days ago someone suggested adding some preset options to mencoder.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
96 At that time I replied 'don't do that', and now I decided to elaborate
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
97 on that.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
98
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
99 Warning: this is rather long, and it involves mathematics. But if you
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
100 don't want to bother with either then why are you encoding in the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
101 first place? Go do something different!
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
102
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
103 The good news is: it's all about the bpp (bits per pixel).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
104
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
105 The bad news is: it's not THAT easy ;)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
106
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
107 This mail is about encoding a DVD to MPEG4. It's about the video
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
108 quality, not (primarily) about the audio quality or some other fancy
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
109 things like subtitles.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
110
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
111 The first step is to encode the audio. Why? Well if you encode the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
112 audio prior to the video you'll have to make the video fit onto one
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
113 (or two) CD(s). That way you can use oggenc's quality based encoding
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
114 mode which is much more sophisticated than its ABR based mode.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
115
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
116 After encoding the audio you have a certain amount of space left to
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
117 fill with video. Let's assume the audio takes 60M (no problem with
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
118 Vorbis), and you aim at a 700M CD. This leaves you 640M for the video.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
119 Let's further assume that the video is 100 minutes or 6000 seconds
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
120 long, encoded at 25fps (those nasty NTSC fps values give me
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
121 headaches. Adjust to your needs, of course!). This leaves you with
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
122 a video bitrate of:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
123
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
124 $videosize * 8
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
125 $videobitrate = --------------
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
126 $length * 1000
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
127
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
128 $videosize in bytes, $length in seconds, $videobitrate in kbit/s.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
129 In my example I end up with $videobitrate = 895.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
130
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
131 And now comes the question: how do I chose my encoding parameters
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
132 so that the results will be good? First let's take a look at a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
133 typical mencoder line:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
134
10405
a5785a0b9ee1 -dvd -> dvd:// and -vcd -> vcd://
jonas
parents: 9644
diff changeset
135 mencoder dvd://1 -o /dev/null -oac copy -ovc lavc \
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
136 -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vqmin=2:\
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
137 vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:vpass=1 \
9644
0fe056bdb135 vop -> vf change, small fixes. The Polish documentation should be checked for correctness.
jonas
parents: 9012
diff changeset
138 -vf crop=716:572:2:2,scale=640:480
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
139
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
140 Phew, all those parameters! Which ones should I change? NEVER leave
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
141 out 'vhq'. Never ever. 'vqmin=2' is always good if you aim for sane
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
142 settings - like 'normal length' movies on one CD, 'very long movies'
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
143 on two CDs and so on. vcodec=mpeg4 is mandatory.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
144
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
145 The 'vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01' are parameters
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
146 suggested by D Richard Felker for non-animated movies, and they
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
147 improve quality a bit.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
148
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
149 But the two things that have the most influence on quality are
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
150 vbitate and scale. Why? Because both together tell the codec how
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
151 many bits it may spend on each frame for each bit: and this is
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
152 the 'bpp' value (bits per pixel). It's simply defined as
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
153
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
154 $videobitrate * 1000
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
155 $bpp = -----------------------
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
156 $width * $height * $fps
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
157
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
158 I've attached a small Perl script that calculates the $bpp for
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
159 a movie. You'll have to give it four parameters:
9644
0fe056bdb135 vop -> vf change, small fixes. The Polish documentation should be checked for correctness.
jonas
parents: 9012
diff changeset
160 a) the cropped but unscaled resolution (use '-vf cropdetect'),
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
161 b) the encoded aspect ratio. All DVDs come at 720x576 but contain
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
162 a flag that tells the player wether it should display the DVD at
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
163 an aspect ratio of 4/3 (1.333) or at 16/9 (1.777). Have a look
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
164 at mplayer's output - there's something about 'prescaling'. That's
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
165 what you are looking for.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
166 c) the video bitrate in kbit/s and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
167 d) the fps.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
168
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
169 In my example the command line and calcbpp.pl's output would look
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
170 like this (warning - long lines ahead):
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
171
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
172 mosu@anakin:~$ ./calcbpp.pl 720x440 16/9 896 25
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
173 Prescaled picture: 1023x440, AR 2.33
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
174 720x304, diff 5, new AR 2.37, AR error 1.74% scale=720:304 bpp: 0.164
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
175 704x304, diff -1, new AR 2.32, AR error 0.50% scale=704:304 bpp: 0.167
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
176 688x288, diff 8, new AR 2.39, AR error 2.58% scale=688:288 bpp: 0.181
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
177 672x288, diff 1, new AR 2.33, AR error 0.26% scale=672:288 bpp: 0.185
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
178 656x288, diff -6, new AR 2.28, AR error 2.17% scale=656:288 bpp: 0.190
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
179 640x272, diff 3, new AR 2.35, AR error 1.09% scale=640:272 bpp: 0.206
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
180 624x272, diff -4, new AR 2.29, AR error 1.45% scale=624:272 bpp: 0.211
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
181 608x256, diff 5, new AR 2.38, AR error 2.01% scale=608:256 bpp: 0.230
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
182 592x256, diff -2, new AR 2.31, AR error 0.64% scale=592:256 bpp: 0.236
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
183 576x240, diff 8, new AR 2.40, AR error 3.03% scale=576:240 bpp: 0.259
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
184 560x240, diff 1, new AR 2.33, AR error 0.26% scale=560:240 bpp: 0.267
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
185 544x240, diff -6, new AR 2.27, AR error 2.67% scale=544:240 bpp: 0.275
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
186 528x224, diff 3, new AR 2.36, AR error 1.27% scale=528:224 bpp: 0.303
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
187 512x224, diff -4, new AR 2.29, AR error 1.82% scale=512:224 bpp: 0.312
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
188 496x208, diff 5, new AR 2.38, AR error 2.40% scale=496:208 bpp: 0.347
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
189 480x208, diff -2, new AR 2.31, AR error 0.85% scale=480:208 bpp: 0.359
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
190 464x192, diff 7, new AR 2.42, AR error 3.70% scale=464:192 bpp: 0.402
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
191 448x192, diff 1, new AR 2.33, AR error 0.26% scale=448:192 bpp: 0.417
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
192 432x192, diff -6, new AR 2.25, AR error 3.43% scale=432:192 bpp: 0.432
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
193 416x176, diff 3, new AR 2.36, AR error 1.54% scale=416:176 bpp: 0.490
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
194 400x176, diff -4, new AR 2.27, AR error 2.40% scale=400:176 bpp: 0.509
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
195 384x160, diff 5, new AR 2.40, AR error 3.03% scale=384:160 bpp: 0.583
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
196 368x160, diff -2, new AR 2.30, AR error 1.19% scale=368:160 bpp: 0.609
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
197 352x144, diff 7, new AR 2.44, AR error 4.79% scale=352:144 bpp: 0.707
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
198 336x144, diff 0, new AR 2.33, AR error 0.26% scale=336:144 bpp: 0.741
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
199 320x144, diff -6, new AR 2.22, AR error 4.73% scale=320:144 bpp: 0.778
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
200
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
201 A word for the $bpp. For a fictional movie which is only black and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
202 white: if you have a $bpp of 1 then the movie would be stored
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
203 uncompressed :) For a real life movie with 24bit color depth you
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
204 need compression of course. And the $bpp can be used to make the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
205 decision easier.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
206
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
207 As you can see the resolutions suggested by the script are all
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
208 dividable by 16. This will make the aspect ratio slightly wrong,
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
209 but no one will notice.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
210
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
211 Now if you want to decide which resolution (and scaling parameters)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
212 to chose you can do that by looking at the $bpp:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
213
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
214 < 0.10: don't do it. Please. I beg you!
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
215 < 0.15: It will look bad.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
216 < 0.20: You will notice blocks, but it will look ok.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
217 < 0.25: It will look really good.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
218 > 0.25: It won't really improve visually.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
219 > 0.30: Don't do that either - try a bigger resolution instead.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
220
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
221 Of course these values are not absolutes! For movies with really lots
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
222 of black areas 0.15 may look very good. Action movies with only high
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
223 motion scenes on the other hand may not look perfect at 0.25. But these
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
224 values give you a great idea about which resolution to chose.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
225
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
226 I see a lot of people always using 512 for the width and scaling
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
227 the height accordingly. For my (real-world-)example this would be
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
228 simply a waste of bandwidth. The encoder would probably not even
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
229 need the full bitrate, and the resulting file would be smaller
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
230 than my targetted 700M.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
231
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
232 After encoding you'll do your 'quality check'. First fire up the movie
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
233 and see whether it looks good to you or not. But you can also do a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
234 more 'scientific' analysis. The second Perl script I attached counts
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
235 the quantizers used for the encoding. Simply call it with
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
236
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
237 countquant.pl < divx2pass.log
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
238
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
239 It will print out which quantizer was used how often. If you see that
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
240 e.g. the lowest quantizer (vqmin=2) gets used for > 95% of the frames
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
241 then you can safely increase your picture size.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
242
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
243 > The "counting the quantesizer"-thing could improve the quality of
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
244 > full automated scripts, as I understand ?
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
245
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
246 Yes, the log file analysis can be used be tools to automatically adjust
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
247 the scaling parameters (if you'd do that you'd end up with a three-pass
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
248 encoding for the video only ;)), but it can also provide answers for
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
249 you as a human. From time to time there's a question like 'hey,
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
250 mencoder creates files that are too small! I specified this bitrate and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
251 the resulting file is 50megs short of the target file size!'. The
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
252 reason is probably that the codec already uses the minimum quantizer
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
253 for nearly all frames so it simply does not need more bits. A quick
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
254 glance at the distribution of the quantizers can be enlightening.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
255
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
256 Another thing is that q=2 and q=3 look really good while the 'bigger'
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
257 quantizers really lose quality. So if your distribution shows the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
258 majority of quantizers at 4 and above then you should probably decrease
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
259 the resolution (you'll definitly see block artefacts).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
260
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
261
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
262 Well... Several people will probably disagree with me on certain
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
263 points here, especially when it comes down to hard values (like the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
264 $bpp categories and the percentage of the quantizers used). But
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
265 the idea is still valid.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
266
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
267 And that's why I think that there should NOT be presets in mencoder
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
268 like the presets lame knows. 'Good quality' or 'perfect quality' are
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
269 ALWAYS relative. They always depend on a person's personal preferences.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
270 If you want good quality then spend some time reading and - more
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
271 important - understanding what steps are involved in video encoding.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
272 You cannot do it without mathematics. Oh well, you can, but you'll
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
273 end up with movies that could certainly look better.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
274
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
275 Now please shoot me if you have any complaints ;)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
276
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
277 --
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
278 ==> Ciao, Mosu (Moritz Bunkus)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
279
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
280 ===========
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
281 ANOTHER APPROACH: BITS PER BLOCK:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
282
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
283 > $videobitrate * 1000
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
284 > $bpp = -----------------------
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
285 > $width * $height * $fps
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
286
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
287 Well, I came to similar equation going through different route. Only I
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
288 didn't use bits per pixel, in my case it was bits per block (BPB). The block
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
289 is 16x16 because lots of software depends on video width/height being
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
290 divisable by 16. And because I didn't like this 0.2 bit per pixel, when
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
291 bit is quite atomic ;)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
292
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
293 So the equation was something like:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
294
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
295 bitrate
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
296 bpb = -----------------
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
297 fps * ((width * height) / (16 * 16))
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
298
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
299 (width and height are from destination video size, and bitrate is in
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
300 bits (i.e. 900kbps is 900000))
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
301
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
302 This way it apeared that the minimum bits per block is ~40, very
11271
252fb0cf331a spelling fixes, mostly by <ismail.donmez@boun.edu.tr>
diego
parents: 10432
diff changeset
303 good results are with ~50, and everything above 60 is a waste of bandwidth.
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
304 And what's actually funny is that it was independant of codec used. The
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
305 results were exactly the same, whether I used DIV3 (with tricky nandub's
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
306 magick), ffmpeg odivx, DivX5 on Windows or XviD.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
307
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
308 Surprisingly there is one advantage of using nandub-DIV3 for bitrate
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
309 starved encoding: ringing almost never apears this way.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
310
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
311 But I also found out, that the quality/BPB isn't constant for
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
312 drastically different resolutions. Smaller picture (like MPEG1 sizes)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
313 need more BPB to look good than say typical MPEG2 resolutions.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
314
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
315 Robert
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
316
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
317
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
318 ===========
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
319 DON'T SCALE DOWN TOO MUCH
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
320
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
321 Sometimes I found that encoding to y-scaled only DVD qualty (ie 704 x
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
322 288 for a 2.85 film) gives better visual quality than a scaled-down
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
323 version even if the quantizers are significantly higher than for the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
324 scaled-down version.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
325 Keep in mind that blocs, fuzzy parts and generaly mpeg artefacts in a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
326 704x288 image will be harder to spot in full-screen mode than on a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
327 512x208 image. In fact I've see example where the same movie looks
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
328 better compressed to 704x288 with an average weighted quantizer of
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
329 ~3 than the same movie scaled to 576x240 with an average weighted
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
330 quantizer of 2.4.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
331 Btw, a print of the weighted average quantizer would be nice in
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
332 countquant.pl :)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
333
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
334 Another point in favor of not trying to scale down too much : on hard
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
335 scaled-down movies, the MPEG codec will need to compress relatively
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
336 high frequencies rather than low frequencies and it doesn't like that
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
337 at all. You will see less and less returns while you scale down and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
338 scale down again in desesperate need of some bandwidth :)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
339
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
340 In my experience, don't try to go below a width of 576 without closely
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
341 watching what's going on.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
342
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
343 --
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
344 Rémi
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
345
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
346 ===========
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
347 TIPS FOR ENCODING
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
348
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
349 That being said, with video you have some tradeoffs you can make. Most
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
350 people seem to encode with really basic options, but if you play with
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
351 single coefficient elimination and luma masking settings, you can save lots
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
352 of bits, resulting in lower quantizers, which means less blockiness and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
353 less ugly noise (ringing) around sharp borders. The tradeoff, however, is
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
354 that you'll get some "muddiness" in some parts of the image. Play around
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
355 with the settings and see for yourself. The options I typically use for
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
356 (non-animated) movies are:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
357
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
358 vlelim=-4
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
359 vcelim=9
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
360 lumi_mask=0.05
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
361 dark_mask=0.01
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
362
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
363 If things look too muddy, making the numbers closer to 0. For anime and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
364 other animation, the above recommendations may not be so good.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
365
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
366 Another option that may be useful is allowing four motion vectors per
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
367 macroblock (v4mv). This will increase encoding time quite a bit, and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
368 last I checked it wasn't compatible with B frames. AFAIK, specifying
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
369 v4mv should never reduce quality, but it may prevent some old junky
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
370 versions of DivX from decoding it (can anyone conform?). Another issue
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
371 might be increased cpu time needed for decoding (again, can anyone
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
372 confirm?).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
373
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
374 To get more fair distribution of bits between low-detail and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
375 high-detail scenes, you should probably try increasing vqcomp from the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
376 default (0.5) to something in the range 0.6-0.8.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
377
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
378 Of course you also want to make sure you crop ALL of the black border and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
379 any half-black pixels at the edge of the image, and make sure the final
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
380 image dimensions after cropping and scaling are multiples of 16. Failing to
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
381 do so will drastically reduce quality.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
382
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
383 Finally, if you can't seem to get good results, you can try scaling the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
384 movie down a bit smaller or applying a weak gaussian blur to reduce the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
385 amount of detail.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
386
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
387 Now, my personal success story! I just recently managed to fit a beautiful
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
388 encode of Kundun (well over 2 hours long, but not too many high-motion
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
389 scenes) on one cd at 640x304, with 66 kbit/sec abr ogg audio, using the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
390 options I described above. So, IMHO it's definitely possible to get very
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
391 good results with libavcodec (certainly MUCH better than all the idiot
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
392 "release groups" using DivX3 make), as long as you take some time to play
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
393 around with the options.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
394
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
395
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
396 Rich
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
397
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
398 ============
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
399 ABOUT VLELIM, VCELIM, LUMI_MASK AND DARK_MASK PART I: LUMA & CHROMA
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
400
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
401
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
402 The l/c in vlelim and vcelim stands for luma (brightness plane) and chroma
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
403 (color planes). These are encoded separately in all mpeg-like algorithms.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
404 Anyway, the idea behind these options is (at least from what I understand)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
405 to use some good heuristics to determine when the change in a block is less
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
406 than the threshold you specify, and in such a case, to just encode the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
407 block as "no change". This saves bits and perhaps speeds up encoding. Using
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
408 a negative value for either one means the same thing as the corresponding
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
409 positive value, but the DC coefficient is also considered. Unfortunately
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
410 I'm not familiar enough with the mpeg terminology to know what this means
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
411 (my first guess would be that it's the constant term from the DCT), but it
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
412 probably makes the encoder less likely to apply single coefficient
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
413 elimination in cases where it would look bad. It's presumably recommended
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
414 to use negative values for luma (which is more noticable) and positive for
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
415 chroma.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
416
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
417 The other options -- lumi_mask and dark_mask -- control how the quantizer
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
418 is adjusted for really dark or bright regions of the picture. You're
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
419 probably already at least a bit familiar with the concept of quantizers
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
420 (qscale, lower = more precision, higher quality, but more bits needed to
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
421 encode). What not everyone seems to know is that the quantizer you see
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
422 (e.g. in the 2pass logs) is just an average for the whole frame, and lower
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
423 or higher quantizers may in fact be used in parts of the picture with more
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
424 or less detail. Increasing the values of lumi_mask and dark_mask will cause
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
425 lavc to aggressively increase the quantizer in very dark or very bright
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
426 regions of the picture (which are presumably not as noticable to the human
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
427 eye) in order to save bits for use elsewhere.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
428
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
429 Rich
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
430
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
431 ===================
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
432 ABOUT VLELIM, VCELIM, LUMI_MASK AND DARK_MASK PART II: VQSCALE
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
433
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
434 OK, a quick explanation. The quantizer you set with vqscale=N is the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
435 per-frame quantizer parameter (aka qp). However, with mpeg4 it's
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
436 allowed (and recommended!) for the encoder to vary the quantizer on a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
437 per-macroblock (mb) basis (as I understand it, macroblocks are 16x16
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
438 regions composed of 4 8x8 luma blocks and 2 8x8 chroma blocks, u and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
439 v). To do this, lavc scores each mb with a complexity value and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
440 weights the quantizer accordingly. However, you can control this
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
441 behavior somewhat with scplx_mask, tcplx_mask, dark_mask, and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
442 lumi_mask.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
443
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
444 scplx_mask -- raise quantizer on mb's with lots of spacial complexity.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
445 Spacial complexity is measured by variance of the texture (this is
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
446 just the actual image for I blocks and the difference from the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
447 previous coded frame for P blocks).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
448
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
449 tcplx_mask -- raise quantizer on mb's with lots of temporal
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
450 complexity. Temporal complexity is measured according to motion
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
451 vectors.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
452
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
453 dark_mask -- raise quantizer on very dark mb's.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
454
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
455 lumi_mask -- raise quantizer on very bright mb's.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
456 Somewhere around 0-0.15 is a safe range for these values, IMHO. You
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
457 might try as high as 0.25 or 0.3. You should probably never go over
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
458 0.5 or so.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
459
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
460 Now, about naq. When you adjust the quantizers on a per-mb basis like
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
461 this (called adaptive quantization), you might decrease or (more
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
462 likely) increase the average quantizer used, so that it no longer
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
463 matches the requested average quantizer (qp) for the frame. This will
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
464 result in weird things happening with the bitrate, at least from my
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
465 experience. What naq does is "normalize adaptive quantization". That
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
466 is, after the above masking parameters are applied on a per-mb basis,
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
467 the quantizers of all the blocks are rescaled so that the average
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
468 stays fixed at the desired qp.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
469
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
470 So, if I used vqscale=4 with naq and fairly large values for the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
471 masking parameters, I might be likely to see lots of frames using
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
472 qscale 2,3,4,5,6,7 across different macroblocks as needed, but with
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
473 the average sticking around 4. However, I haven't actually tested such
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
474 a setup yet, so it's just speculation right now.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
475
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
476 Have fun playing around with it.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
477
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
478 Rich
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
479
11423
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
480
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
481 ================================================================================
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
482
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
483
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
484 TIPS FOR ENCODING OLD BLACK & WHITE MOVIES:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
485
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
486 I found myself that 4:3 B&W old movies are very hard to compress well. In
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
487 addition to the 4:3 aspect ratio which eats lots of bits, those movies are
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
488 typically very "noisy", which doesn't help at all. Anyway :
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
489
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
490 > After a few tries I am
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
491 > still a little bit disappointed with the video quality. Since it is a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
492 > "dark" movies, there is a lot of black on the pictures, and on the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
493 > encoded avi I can see a lot of annoying "mpeg squares". I am using
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
494 > avifile codec, but the best I think is to give you the command line I
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
495 > used to encode a preview of the result:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
496
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
497 >
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
498 > First pass:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
499 > mencoder TITLE01-ANGLE1.VOB -oac copy -ovc lavc -lavcopts
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
500 > vcodec=mpeg4:vhq:vpass=1:vbitrate=800:keyint=48 -ofps 23.976 -npp lb
9644
0fe056bdb135 vop -> vf change, small fixes. The Polish documentation should be checked for correctness.
jonas
parents: 9012
diff changeset
501 > -ss 2:00 -endpos 0:30 -vf scale -zoom -xy 640 -o movie.avi
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
502
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
503 1) keyint=48 is way too low. The default value is 250, this is in *frames*
13022
diego
parents: 11423
diff changeset
504 not seconds. Keyframes are significantly larger than P or B frames, so the
diego
parents: 11423
diff changeset
505 less keyframes you have, better the overall movie will be. (huh, like Yoda
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
506 I speak ;). Try keyint=300 or 350. Don't go beyond that if you want
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
507 relatively precise seeking.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
508
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
509 2) you may want to play with vlelim and vcelim options. This can gives you
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
510 a significant "quality" boost. Try one of these couples :
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
511
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
512 vlelim=-2:vcelim=3
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
513 vlelim=-3:vcelim=5
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
514 vlelim=-4:vcelim=7
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
515 (and yes, there's a minus)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
516
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
517 3) crop & rescale the movie before passing it to the codec. First crop the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
518 movie to not encode black bars if there's any. For a 1h40mn movie
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
519 compressed to a 700 MB file, I would try something between 512x384 and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
520 480x320. Don't go below that if you want something relatively sharp when
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
521 viewed fullscreen.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
522
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
523 4) I would recommend using the Ogg Vorbis audio codec with the .ogm
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
524 container format. Ogg Vorbis compress audio better than MP3. On a typical
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
525 old, mono-only audio stream, a 45 kbits/s Vorbis stream is ok. How to
10432
diego
parents: 10405
diff changeset
526 extract & compress an audio stream from a ripped DVD (mplayer dvd://1
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
527 -dumpstream) :
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
528
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
529 rm -f audiodump.pcm ; mkfifo -m 600 audiodump.pcm
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
530 mplayer -quiet -vc null -vo null -aid 128 -ao pcm -nowaveheader stream.dump &
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
531 oggenc --raw --raw-bits=16 --raw-chan=2 --raw-rate=48000 -q 1 -o audio-us.ogg
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
532 +audiodump.pcm &
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
533 wait
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
534
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
535 For a nice set of utilities to manager the .ogm format, see Moritz Bunkus'
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
536 ogmtools (google is your friend).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
537
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
538 5) use the "v4mv" option. This could gives you a few more bits at the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
539 expense of a slightly longer encoding. This is a "lossless" option, I mean
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
540 with this option you don't throw away some video information, it just
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
541 selects a more precise motion estimation method. Be warned that on some
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
542 very un-typical scenes this option may gives you a longer file than
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
543 without, although it's very rare and on a whole film I think it's always a
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
544 win.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
545
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
546 6) you can try the new luminance & darkness masking code. Play
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
547 with the "lumi_mask" and "dark_mask" options. I would recommend using
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
548 something like :
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
549 lumi_mask=0.07:dark_mask=0.10:naq:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
550 lumi_mask=0.10:dark_mask=0.12:naq:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
551 lumi_mask=0.12:dark_mask=0.15:naq
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
552 lumi_mask=0.13:dark_mask=0.16:naq:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
553 Be warned that these options are really experimental and the result
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
554 could be very good or very bad depending on your visualization device
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
555 (computer CRT, TV or TFT screen). Don't push too hard these options.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
556
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
557 > Second pass:
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
558 > the same with vpass=2
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
559
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
560 7) I've found that lavc gives better results when the first pass is done
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
561 with "vqscale=2" instead of a target bitrate. The statistics collected
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
562 seems to be more precise. YMMV.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
563
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
564 > I am new to mencoder, so please tell me any idea you have even if it
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
565 > obvious. I also tried the "gray" option of lavc, to encode B&W only,
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
566 > but strangely it gives me "pink" squares from time to time.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
567
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
568 Yes, I've seen that too. Playing the resulting file with "-lavdopts gray"
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
569 fix the problem but it's not very nice ...
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
570
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
571 > So if you could tell me what option of mencoder or lavc I should be
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
572 > looking at to lower the number of "squares" on the image, it would be
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
573 > great. The version of mencoder i use is 0.90pre8 on a macos x PPC
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
574 > platform. I guess I would have the same problem by encoding anime
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
575 > movies, where there are a lot of region of the image with the same
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
576 > color. So if you managed to solve this problem...
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
577
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
578 You could also try the "mpeg_quant" flag. It selects a different set of
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
579 quantizers and produce somewhat sharper pictures and less blocks on large
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
580 zones with the same or similar luminance, at the expense of some bits.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
581
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
582 > This is completely off topic, but do you know how I can create good
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
583 > subtitles from vobsub subtitles ? I checked the -dumpmpsub option of
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
584 > mplayer, but is there a way to do it really fast (ie without having to
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
585 > play the whole movie) ?
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
586
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
587 I didn't find a way under *nix to produce reasonably good text subtitles
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
588 from vobsubs. OCR *nix softwares seems either not suited to the task, not
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
589 powerful enough or both. I'm extracting the vobsub subtitles and simply use
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
590 them with the .ogm
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
591
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
592 / .avi :
10405
a5785a0b9ee1 -dvd -> dvd:// and -vcd -> vcd://
jonas
parents: 9644
diff changeset
593 1) rip the DVD to harddisk with "mplayer dvd://1 -dumpstream"
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
594 2) mount the DVD and copy the .ifo file
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
595 2) extract all vobsubs to one single file with something like :
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
596
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
597 for f in 0 1 2 3 4 5 6 7 8 9 10 11 ; do \
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
598 mencoder -ovc copy -oac copy -o /dev/null -sid $f -vobsubout sous-titres
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
599 +-vobsuboutindex $f -ifo vts_01_0.ifo stream.dump
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
600 done
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
601
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
602 (and yes, I've a DVD with 12 subtitles)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
603 --
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
604 Rémi
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
605
11423
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
606
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
607 ================================================================================
dffc970f1922 FIXING A/V SYNC WHEN ENCODING, from an old mail by Rich:
diego
parents: 11271
diff changeset
608
8463
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
609
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
610 TIPS FOR SMOKE & CLOUDS
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
611
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
612 Q: I'm trying to encode Dante's Peak and I'm having problems with clouds,
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
613 fog and smoke: They don't look fine (they look very bad if I watch the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
614 movie in TVout). There are some artifacts, white clouds looks as snow
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
615 mountains, there are things likes hip in the colors so one can see frontier
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
616 curves between white and light gray and dark gray ... (I don't know if you
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
617 can understand me, I want to mean that the colors don't change smoothly)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
618 In particular I'm using vqscale=2:vhq:v4mv
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
619
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
620 A: Try adding "vqcomp=0.7:vqblur=0.2:mpeg_quant" to lavcopts.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
621
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
622 Q: I tried your suggestion and it improved the image a little ... but not
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
623 enough. I was playing with different options and I couldn't find the way.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
624 I suppose that the vob is not so good (watching it in TV trough the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
625 computer looks better than my encoding, but it isn't a lot of better).
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
626
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
627 A: Yes, those scenes with qscale=2 looks terrible :-(
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
628
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
629 Try with vqmin=1 in addition to mpeg_quant:vlelim=-4:vcelim=-7 (and maybe
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
630 with "-sws 10 -ssf ls=1" to sharpen a bit the image) and read about vqmin=1
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
631 in DOCS/tech/libavc-options.txt.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
632
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
633 If after the whole movie is encoded you still see the same problem, it will
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
634 means that the second pass didn't picked-up q=1 for this scene. Force q=1
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
635 with the "vrc_override" option.
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
636
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
637 Q: By the way, is there a special difficult in encode clouds or smoke?
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
638
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
639 A: I would say it depends on the sharpness of these clouds / smokes and the
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
640 fact that they are mostly black/white/grey or colored. The codec will do
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
641 the right thing with vqmin=2 for example on a cigarette smoke (sharp) or on
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
642 a red/yellow cloud (explosion, cloud of fire). But may not with a grey and
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
643 very fuzzy cloud like in the chocolat scene. Note that I don't know exactly
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
644 why ;)
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
645
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
646 A = Rémi
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
647
e421b4ab7815 encoding tips - collected from mplayer-users list mailings by
arpi
parents:
diff changeset
648
15015
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
649 ================================================================================
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
650
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
651
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
652 TIPS FOR TWEAKING RATECONTROL
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
653
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
654 (For the purpose of this explanation, consider "2nd pass" to be any beyond
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
655 the 1st. The algorithm is run only on P-frames; I- and B-frames use QPs
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
656 based on the adjacent P. While x264's 2pass ratecontrol is based on lavc's,
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
657 it has diverged somewhat and not all of this is valid for x264.)
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
658
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
659 Consider the default ratecontrol equation in lavc: "tex^qComp".
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
660 At the beginning of the 2nd pass, rc_eq is evaluated for each frame, and
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
661 the result is the number of bits allocated to that frame (multiplied by
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
662 some constant as needed to match the total requested bitrate).
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
663
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
664 "tex" is the complexity of a frame, i.e. the estimated number of bits it
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
665 would take to encode at a given quantizer. (If the 1st pass was CQP and
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
666 not turbo, then we know tex exactly. Otherwise it is calculated by
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
667 multiplying the 1st pass's bits by the QP of that frame. But that's not
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
668 why CQP is potentially good; more on that later.)
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
669 "qComp" is just a constant. It has no effect outside the rc_eq, and is
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
670 directly set by the vqcomp parameter.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
671
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
672 If vqcomp=1, then rc_eq=tex^1=tex, so 2pass allocates to each frame the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
673 number of bits needed to encode them all at the same QP.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
674 If vqcomp=0, then rc_eq=tex^0=1, so 2pass allocates the same number of
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
675 bits to each frame, i.e. CBR. (Actually, this is worse than 1pass CBR in
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
676 terms of quality; CBR can vary within its allowed buffer size, while
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
677 vqcomp=0 tries to make each frame exactly the same size.)
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
678 If vqcomp=0.5, then rc_eq=sqrt(tex), so the allocation is somewhere
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
679 between CBR and CQP. High complexity frames get somewhat lower quality
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
680 than low complexity, but still more bits.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
681
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
682 While the actual selection of a good value of vqcomp is experimental, the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
683 following underlying factors determine the result:
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
684 Arguing towards CQP: You want the movie to be somewhere approaching
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
685 constant quality; oscillating quality is even more annoying than constant
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
686 low quality. (However, constant quality does not mean constant PSNR nor
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
687 constant QP. Details are less noticeable in high-motion scenes, so you can
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
688 get away with somewhat higher QP in high-complexity frames for the same
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
689 perceived quality.)
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
690 Arguing towards CBR: You get more quality per bit if you spend those bits
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
691 in frames where motion compensation works well (which tends to be
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
692 correlated with "tex"): A given artifact may stick around several seconds
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
693 in a low-motion scene, and you only have to fix it in one frame to improve
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
694 the quality of the whole sequence.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
695
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
696 Now for why the 1st pass ratecontrol method matters:
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
697 The number of bits at constant quant is as good a measure of complexity as
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
698 any other simple formula for the purpose of allocating bits. But it's not
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
699 perfect for predicting which QP will produce the desired number of bits.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
700 Bits are approximately inversely proportional to QP, but the exact scaling
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
701 is non-linear, and depends on the amount of detail/noise, the complexity of
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
702 motion, the quality of previous frames, and other stuff not measured by the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
703 ratecontrol. So it predicts best when the QP used for a given frame in the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
704 2nd pass is close to the QP used in the 1st pass. When the prediction is
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
705 wrong, lavc needs to distribute the surplus or deficit of bits among future
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
706 frames, which means that they too deviate from the planned distribution.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
707 Obviously, with vqcomp=1 you can get the 1st pass QPs very close by using
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
708 CQP, and with vqcomp=0 a CBR 1st pass is very close. But with vqcomp=0.5
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
709 it's more ambiguous. The accepted wisdom is that CBR is better for
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
710 vqcomp=0.5, mostly because you then don't have to guess a QP in advance.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
711 But with vqcomp=0.6 or 0.7, the 2nd pass QPs vary less, so a CQP 1st pass
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
712 (with the right QP) will be a better predictor than CBR.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
713
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
714 To make it more confusing, 1pass CBR uses the same rc_eq with a different
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
715 meaning. In CBR, we don't have a real encode to estimate from, so "tex" is
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
716 calculated from the full-pixel precision motion-compensation residual.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
717 While the number of bits allocated to a given frame is decided by the rc_eq
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
718 just like in 2nd pass, the target bitrate is constant (instead of being the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
719 sum of per-frame rc_eq values). So the scaling factor (which is constant in
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
720 2nd pass) now varies in order to keep the local average bitrate near the
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
721 CBR target. So vqcomp does affect CBR, though it only determines the local
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
722 allocation of bits, not the long-term allocation.
23237af42335 Technical explanation of how to use vqcomp, and why, featured by Loren Merritt
gpoirier
parents: 13199
diff changeset
723
16205
4183c4585f1d URL update
gpoirier
parents: 15015
diff changeset
724 --Loren Merritt