comparison DOCS/xml/it/encoding-guide.xml @ 25279:2838dc7a68f3

initial submit for revision... 24% synced with r22753
author ptt
date Wed, 05 Dec 2007 19:06:12 +0000
parents
children 136ee4a91f00
comparison
equal deleted inserted replaced
25278:b037a816be70 25279:2838dc7a68f3
1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- 24% synced with r22753 -->
3 <chapter id="encoding-guide">
4 <title>La codifica con <application>MEncoder</application></title>
5
6 <sect1 id="menc-feat-dvd-mpeg4">
7 <title>Produrre un rip di un film da DVD in un
8 MPEG-4 ("DivX") di alta qualità</title>
9
10 <para>
11 Una domanda frequente è "Come posso generare il rip con la migliore quallità
12 per una dimensione data?". Un'altra domanda è "Come posso fare il rip da DVD
13 migliore in assoluto? Non mi interessa la dimensione del file, voglio solo la
14 più alta qualità."
15 </para>
16
17 <para>
18 L'ultima domanda è perlomeno forse posta malamente. Dopo tutto, se non ti
19 interessa la dimensione del file, perché non ti copi semplicemente l'intero
20 flusso video MPEG-2 dal DVD? Certo, avrai un AVI di 5GB, prendere o lasciare,
21 ma se vuoi la miglior qualità e non ti importa della dimensione, è
22 sicuramente la scelta migliore.
23 </para>
24
25 <para>
26 Invero, la ragione per cui vuoi codificare un DVD in MPEG-4 è proprio perché
27 ti interessa <emphasis role="bold">davvero</emphasis> la dimensione del file.
28 </para>
29
30 <para>
31 E' difficile offrire una ricetta da libro su come generare un rip da DVD in
32 qualità molto alta. Bisogna considerare vari fattori, e dovresti comprendere
33 questi dettagli, altrimenti alla fine probabilmente sarai insoddisfatto del
34 risultato. Più sotto evidenziamo alcuni di questi argomenti e poi passiamo ad
35 esaminare un esempio. Partiamo dal principio che per codificare il video tu
36 stia usando <systemitem class="library">libavcodec</systemitem> anche se la
37 teoria si applica allo stesso modo agli altri codec.
38 </para>
39
40 <para>
41 Se questo ti sembra troppo, dovresti probabilmente usare una delle belle
42 interfacce elencate nella
43 <ulink url="http://www.mplayerhq.hu/design7/projects.html#mencoder_frontends">sezione su MEncoder</ulink>
44 nella pagina dei progetti collegati (related projects).
45 In tal modo riuscirai ad ottenere rip di alta qualità senza pensarci troppo,
46 dato che la maggior parte di questi strumenti sono progettati per prendere
47 decisioni sagge al tuo posto.
48 </para>
49
50 <!-- ********** -->
51
52 <sect2 id="menc-feat-dvd-mpeg4-preparing-encode">
53 <title>Prepararsi alla codifica: identificare il materiale sorgente e la frequenza fotogrammi (framerate)</title>
54
55 <para>
56 Prima ancora di pensare a codificare un film, devi fare alcuni passi
57 preliminari.
58 </para>
59
60 <para>
61 Il primo e più importante passo prima della codifica dovrebbe essere
62 determinare il tipo di contenuto che stai trattando.
63 Se il tuo materiale di partenza arriva da un DVD o da TV in
64 broadcast/via cavo/satellite, sarà salvato in uno dei due formati: NTSC per
65 il Nord America e il Giappone, PAL per l'Europa, etc...
66 E' importante tuttavia comprendere che questo è solo il formato per la
67 trasmissione in televisione, e spesso <emphasis role="bold">non</emphasis>
68 corrisponde al formato originario del film.
69 L'esperienza insegna che il materiale NTSC è molto più difficile da
70 codificare, perché ci sono più elementi da identificare nel sorgente.
71 Per generare una codifica adeguata, devi sapere il formato originario.
72 Il non tenerne conto porterà a molti __flaws__ nella tua codifica, inclusi
73 artefatti orrendi __combing__ (interlacing) e fotogrammi duplicati o addirittura
74 perduti.
75 Oltre ad essere brutti, gli artefatti influenzano negativamente l'efficenza
76 della codifica: otterrai una peggior qualità a parità di bitrate.
77 </para>
78
79
80 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-fps">
81 <title>Identificare la frequenza fotogrammi (framerate) del sorgente</title>
82
83 <para>
84 C'è qui un elenco di tipi comuni di materiale sorgente, dove facilmente si
85 trovano e le loro proprietà:
86 </para>
87
88 <itemizedlist>
89 <listitem><para>
90 <emphasis role="bold">Film standard</emphasis>: prodotti per la visione
91 su schermi da cinema a 24fps.
92 </para></listitem>
93 <listitem><para>
94 <emphasis role="bold">Video PAL</emphasis>: registrati con una videocamera
95 PAL a 50 campi al secondo.
96 Un campo è composto dalle sole linee pari o dispari di un fotogramma.
97 La televisione è stata progettata per aggiornarle alternativamente come un
98 metodo economico di compressione analogica.
99 L'occhio umano teoricamente compensa la cosa, ma una volta che capisci come
100 funziona l'interlacciatura imparerai a vederla anche in TV e non ti piacerà
101 più la TV.
102 Due campi <emphasis role="bold">non</emphasis> fanno un fotogramma intero,
103 poiché sono registrati a 1/50 di secondo di distanza nel tempo e quindi non
104 si allineano a meno che non ci sia movimento alcuno.
105 </para></listitem>
106 <listitem><para>
107 <emphasis role="bold">Video NTSC</emphasis>: registrati con una videocamera
108 NTSC a 60000/1001 campi al secondi, o 60 campi al secondo nell'era precedente
109 al colore.
110 Per il resto sono simili ai PAL.
111 </para></listitem>
112 <listitem><para>
113 <emphasis role="bold">Animazione</emphasis>: solitamente disegnati a 24fps,
114 ma se ne trovano anche in tipologie con frequenza di fotogrammi mista.
115 </para></listitem>
116 <listitem><para>
117 <emphasis role="bold">Computer Graphics (CG)</emphasis>: possono essere con
118 qualsiasi frequenza di fotogrammi, ma alcuni sono più comuni di altri;
119 sono tipici 24 e 30 fotogrammi al secondo per NTSC e 25fps per PAL.
120 </para></listitem>
121 <listitem><para>
122 <emphasis role="bold">Vecchi Film</emphasis>: varie e più basse frequenze di
123 fotogrammi.
124 </para></listitem>
125 </itemizedlist>
126 </sect3>
127
128
129 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-material">
130 <title>Identificare il materiale sorgente</title>
131
132 <para>
133 I film composti da fotogrammi sono indicati come "progressivi", mentre quelli
134 composti da campi indipendenti sono chiamati "interlacciati" o video - anche se
135 quest'ultimo termine è ambiguo.
136 </para>
137
138 <para>
139 Per complicare ulteriormente le cose, alcuni film possono essere un misto di
140 molti dei suddetti.
141 </para>
142
143 <para>
144 La più importante distinzione da farsi tra tutti questi formati è che alcuni
145 sono basati su fotogrammi mentre gli altri sono basati su campi.
146 <emphasis role="bold">Ogniqualvolta</emphasis> un film viene preparato per la
147 visualizzazione in televisione (DVD inclusi), viene convertito in un formato
148 basato su campi.
149 I vari metodi con cui si può fare sono conosciuti nel loro insieme come
150 "telecine", di cui il tristemente famoso "3:2 pulldown" NTSC è una tipologia.
151 A meno che il materiale originale sia anch'esso basato su campi (e con la stessa
152 frequenza di campi) otterrai un filmato in un formato diverso da quello che è
153 in origine.
154 </para>
155
156 <itemizedlist>
157 <title>Ci sono vari tipi usuali di "pulldown":</title>
158 <listitem><para>
159 <emphasis role="bold">Pulldown PAL 2:2</emphasis>: il più bello di tutti.
160 Ciascun fotogramma viene mostrato per la durata di due campi, estraendo le
161 linee pari e dispari e mostrandole alternativamente.
162 Se il materiale di origine è a 24fps questo processo velocizza il filmato
163 del 4%.
164 </para></listitem>
165 <listitem><para>
166 <emphasis role="bold">Pulldown PAL 2:2:2:2:2:2:2:2:2:2:2:3</emphasis>:
167 Ogni dodicesimo fotogramma viene mostrato per la durata di tre campi, invece
168 che solamente per due.
169 Questo evita il problema dell'aumento del 4% di velocità, ma rende il
170 processo molto più difficile da __reversare__.
171 Solitamente viene usato nelle produzioni musicali, dove modificare del 4% la
172 velocità rovinerebbe pesantemente la colonna sonora.
173 </para></listitem>
174 <listitem><para>
175 <emphasis role="bold">Telecine NTSC 3:2</emphasis>: i fotogrammi vengono
176 mostrati alternativamente per la durata di 3 o 2 campi.
177 Questo porta ad una frequenza di campi di 2.5 volte la frequenza orginaria.
178 Il risultato viene anche leggermente rallentato da 60 campi al secondo fino a
179 60000/1001 campi al secondo, per mantenere la frequenza dei campi di NTSC.
180 </para></listitem>
181 <listitem><para>
182 <emphasis role="bold">Pulldown NTSC 2:2</emphasis>: utilizzato per mostrare
183 materiale a 30fps su NTSC.
184 Carino, proprio come il pulldown PAL 2:2.
185 </para></listitem>
186 </itemizedlist>
187
188 <para>
189 Ci sono anche alcuni metodi per convertire tra video NTSC e PAL, ma gli
190 arogmenti relativi non sono obiettivo di questa guida.
191 Se ti trovi di fronte a un film di questo genere e lo vuoi codificare, la tua
192 scelta migliore è cercarne una copia nel formato originale.
193 La conversione tra questi due formati è altamente distruttiva e non può
194 essere __reversed__ in maniera pulita, perciò la tua codifica __soffrirà__
195 molto se eseguita da una sorgente convertita.
196 </para>
197
198 <para>
199 Quando il video viene salvato du un DVD, coppie consecutive di campi sono
200 raggruppati in un fotogramma, anche se non sono pensati per esser mostrati
201 nello stesso momento.
202 Lo standard MPEG-2 usato sui DVD e per la TV digitale fornisce un modo sia per
203 codificare i fotogrammi progressivi originali, che uno per memorizzare
204 nell'intestazione del fotogramma il numero dei campi per cui il fotogramma
205 stesso debba essere mostrato.
206 Se viene usato questo metodo il filmato verrà spesso indicato come
207 "soft telecine", visto che il procedimento indica semplicemente al lettore DVD
208 di applicare il pulldown al film, invece che modificare il film stesso.
209 Questa situazione è decisamente preferibile, dato che può essere facilmente
210 __reversed__ (__actually ignored__) dal condificatore, e dato che mantiene la
211 massima qualità.
212 Tuttavia, molti studi di produzione DVD e di trasmissione non usano tecniche di
213 codifica appropriate, ma al contrario producono filmati con "hard telecine", in
214 cui i campi sono sotanzialmente duplicati nell'MPEG-2 codificato.
215 </para>
216
217 <para>
218 Le modalità per gestire questi casi verranno descritte
219 <link linkend="menc-feat-telecine">più avanti in questa guida</link>.
220 Per adesso ti lasciamo alcune indicazioni su come identificare il tipo di
221 materiale che stai trattando:
222 </para>
223
224 <itemizedlist>
225 <title>Regioni NTSC:</title>
226 <listitem><para>
227 Se <application>MPlayer</application> dice che la frequenza fotogrammi passa
228 a 24000/1001 durante la visione del film e non ritorna come prima, è quasi
229 sicuramente un qualche contenuto progressivo che è stato modificato in
230 "soft telecine".
231 </para></listitem>
232 <listitem><para>
233 Se <application>MPlayer</application> dice che la frequenza fotogrammi va
234 avanti e indietro tra 24000/1001 e 30000/1001 e ogni tanto vedi delle "righe",
235 allora ci sono varie possibilità.
236 Le parti a 24000/1001 fps sono quasi certamente contenuto progressivo, in
237 "soft telecine", ma le parti a 30000/1001 fps possono essere sia contenuto in
238 "hard telecine" a 24000/1001 fps che video NTSC a 60000/1001 campi al secondo.
239 Usa le stesse linee guida dei due casi seguenti per determinare quale.
240 </para></listitem>
241 <listitem><para>
242 Se <application>MPlayer</application> non mostra mai una modifica alla
243 frequenza dei fotogrammi e ogni singolo fotogramma con del movimento appare
244 "rigato", il tuo filmato è video NTSC a 60000/1001 campi al secondo.
245 </para></listitem>
246 <listitem><para>
247 Se <application>MPlayer</application> non mostra mai una modifica alla
248 frequenza dei fotogrammi e due fotogrammi ogni cinque sono "rigati", il tuo
249 film è contenuto a 24000/1001fps in "hard telecine".
250 </para></listitem>
251 </itemizedlist>
252
253 <itemizedlist>
254 <title>Regioni PAL:</title>
255 <listitem><para>
256 Se non vedi mai alcuna "riga", il tuo film è pulldown 2:2.
257 </para></listitem>
258 <listitem><para>
259 Se vedi delle "righe" che vanno e vengono ogni mezzo secondo,
260 allora il tuo film è pulldown 2:2:2:2:2:2:2:2:2:2:2:3.
261 </para></listitem>
262 <listitem><para>
263 Se vedi sempre "righe" durante il movimento, allora il tuo film è video
264 PAL a 50 campi al secondo.
265 </para></listitem>
266 </itemizedlist>
267
268 <note><title>Consiglio:</title>
269 <para>
270 <application>MPlayer</application> può rallentare la riproduzione del film
271 con l'opzione -speed o riprodurlo fotogramma per fotogramma.
272 Prova ad usare <option>-speed</option> 0.2 per guardare molto lentamente il
273 film o premi ripetutamente il tasto "<keycap>.</keycap>" per riprodurre un
274 fotogramma per volta ed identificare la sequenza, se non riesci a vederla a
275 velocità normale.
276 </para>
277 </note>
278 </sect3>
279 </sect2>
280
281 <!-- ********** -->
282
283 <sect2 id="menc-feat-dvd-mpeg4-2pass">
284 <title>Quantizzatore costante vs. multipassaggio</title>
285
286 <para>
287 E' possibile codificare il filmato in un'ampia gamma di qualità.
288 Con i codificatori video moderni e un pelo di compressione pre-codec
289 (ridimensionando e ripulendo), è possibile raggiungere una qualità molto
290 buona in 700 MB, per un film di 90-110 minuti in widescreen.
291 Inoltre tutti i film tranne i più lunghi possono essere codificati con una
292 qualità pressoché perfetta in 1400 MB.
293 </para>
294
295 <para>
296 Ci sono tre approcci per codificare il video: bitrate costante (CBR),
297 quantizzatore costante, e multipassaggio (ABR, o bitrate medio).
298 </para>
299
300 <para>
301 La complessità dei fotogrammi di un filmato, e di conseguenza il numero di
302 bit necessari per comprimerli, può variare molto da una scena ad un'altra.
303 I codificatori video moderni possono adattarsi via via a queste necessità
304 e cambiare il bitrate.
305 In modalità semplici come CBR, tuttavia, i codificatori non sanno il bitrate
306 necessario alle scene venture e perciò non possono stare sopra al bitrate
307 richiesto per lunghi periodi di tempo.
308 Modalità più avanzate, come la codifica in multipassaggio, possono tener
309 conto delle statistiche del passo precedente; questo corregge il problema
310 suddetto.
311 </para>
312
313 <note><title>Nota:</title>
314 <para>
315 La maggior parte dei codec che gestisce la codifica in ABR può usare solo la
316 codifica a due passaggi mentre altri come
317 <systemitem class="library">x264</systemitem>,
318 <systemitem class="library">Xvid</systemitem> e
319 <systemitem class="library">libavcodec</systemitem> gestiscono il
320 multipassaggio, che migliora leggermente la qualità ad ogni passo, anche se
321 tale moglioramento non è più misurabile né visibile veramente oltre il
322 quarto passo o giù di lì.
323 Perciò in questa sezione due passaggi e multipassaggio avranno lo stesso
324 significato.
325 </para>
326 </note>
327
328 <para>
329 In ambedue i modi, il codec video (come
330 <systemitem class="library">libavcodec</systemitem>) spezza il fotogramma video
331 in macroblocchi da 16x16 pixel e poi applica un quantizzatore a ciascun
332 macroblocco. Più basso è il quantizzatore, migliore sarà la qualità e
333 più alto il bitrate.
334 Il metodo usato dal codificatore del filmato per determinare quale quantizzatore
335 utilizzare per un dato macroblocco varia ed è altamente configurabile.
336 (Questa è una semplificazione estrema del vero processo, ma il concetto di base
337 è comodo per capire.)
338 </para>
339
340 <para>
341 Quando specifichi un bitrate constante, il codec video codificherà il video,
342 scartando dettagli tanto quanto è necessario e il meno possibile, in modo da
343 rimanere al di sotto del bitrate voluto. Se non ti interessa davvero la
344 dimensione del file, potresti anche usare CBR e specificare un bitrate
345 infinito. (In pratica, questo significa un valore abbastanza alto da non porre
346 limiti, come 10000Kbit.) Con nessun limite sul bitrate, il risultato è che il
347 codec userà il quantizzatore più basso possibile per ciascun macroblocco
348 (come specificato da <option>vqmin</option> per
349 <systemitem class="library">libavcodec</systemitem>, che è 2 di default).
350 Appena specifichi un bitrate abbastanza basso tale che il codec venga forzato
351 ad utilizzare un quantizzatore più alto, allora stai sicuramente diminuendo la
352 qualità del tuo video.
353 Per evitarlo, dovresti probabilmente ridurre la dimensione del tuo video,
354 seguendo il metodo descritto più avanti in questa guida.
355 In generale dovresti evitare del tutto CBR se ti interessa la qualità.
356 </para>
357
358 <para>
359 Con il quantizzatore costante, il codec utilizza lo stesso quantizzatore per
360 ogni macroblocco, come specificato dall'opzione <option>vqscale</option> (per
361 <systemitem class="library">libavcodec</systemitem>).
362 Se vuoi la più alta qualità possibile di rip, sempre ignorantdo il bitrate,
363 puoi usare <option>vqscale=2</option>.
364 Ciò porterà gli stessi bitrate e PSNR (peak signal-to-noise ratio) come CBR
365 con <option>vbitrate</option>=infinito e <option>vqmin</option> di default a 2.
366 </para>
367
368 <para>
369 Il problema con la quantizzazione costante è che usa il quantizzatore indicato
370 sia che il macroblocco ne abbia bisogno o no. Perciò è possibile che venga
371 usato un quantizzatore più alto su un macroblocco senza sacrificare la
372 qualità visiva. Perché sprecare i bit di un quantizzatore basso che non
373 serve? La tua CPU ha tanti cicli fin quando c'è tempo, ma c'è solo un certo
374 numero di bit sul tuo disco rigido.
375 </para>
376
377 <para>
378 Con una codifica a due passi, il primo codificherà il filmato come se fosse
379 CBR, ma manterrà una registrazione delle caratteristiche di ogni fotogramma.
380 Questi dati sono poi utilizzati durante il secondo passo in modo da effettuare
381 scelte intelligenti su quale quantizzatore usare. Durante le scene con azione
382 veloce o molti dettagliate, verrano usati più probabilmente quantizzatori più
383 alti, e durante scene lente o con pochi dettagli, verranno usati quantizzatori
384 più bassi. Solitamente è molto più importante la quantità di movimento
385 che la quantità di dettagli.
386 </para>
387
388 <para>
389 Se usi <option>vqscale=2</option>, allora stai sprecando dei bit. Se usi
390 <option>vqscale=3</option>, allora non stai ottenendo la miglior qualità.
391 Supponi di rippare un DVD a <option>vqscale=3</option> e che il risultato sia
392 1800Kbit. Se fai una codifica a due passi con <option>vbitrate=1800</option> il
393 video risultante avrà una <emphasis role="bold">qualità superiore</emphasis>
394 a <emphasis role="bold">parità di bitrate</emphasis>.
395 </para>
396
397 <para>
398 Dato che ora sei convinto che i due passaggi siano la strada da percorrere, la
399 vera domanda adesso è quale bitrate usare? La risposta à che non c'è una
400 risposta definitiva. Idealmente vuoi scegliere un bitrate che porti al miglior
401 equilibrio tra qualità e dimensione del file. Tutto ciò varia in dipendenza
402 del video di origine.
403 </para>
404
405 <para>
406 Se la dimensione non è importante, un buon punto di partenza per un rip di
407 qualità molto elevata è intorno a 2000Kbit più o meno 200Kbit.
408 Per video con scene di azione veloce o con molti dettagli, oppure se
409 semplicemente hai l'occhio critico, potresti scegliere 2400 o 2600.
410 Per alcuni DVD potresti non notare alcuna differenza a 1400Kbit. Sperimentare
411 con alcune scene a vari bitrate è una buona idea per farsi un'opinione.
412 </para>
413
414 <para>
415 Se punti a una data dimensione, dovrai calcolare il bitrate in un qualche modo.
416 Prima di farlo, però, devi sapere quanto spazio devi riservare per la traccia
417 (le tracce) audio, per cui devi dapprima fare il
418 <link linkend="menc-feat-dvd-mpeg4-audio">rip di queste</link>.
419 Puoi calcolare il bitrate con l'equazione che segue:
420 <systemitem>bitrate = (dimensione_voluta_in_Mbytes - dimensione_audio_in_Mbytes)
421 * 1024 * 1024 / lunghezza_in_secondi * 8 / 1000</systemitem>
422 Per esempio, per far stare un film di due ore su un CD da 702MB, con 60MB di
423 traccia audio, il bitrate video diventerà:
424 <systemitem>(702 - 60) * 1024 * 1024 / (120*60) * 8 / 1000
425 = 740kbps</systemitem>
426 </para>
427 </sect2>
428
429 <!-- ********** -->
430
431 <sect2 id="menc-feat-dvd-mpeg4-constraints">
432 <title>Vincoli per una codifica efficiente</title>
433
434 <para>
435 A causa della natura del tipo di compressione MPEG, ci sono alcuni vincoli da
436 seguire per avere la massima qualità.
437 L'MPEG divide il video in quadrati da 16x16 chiamati macroblocchi, ciascuno di
438 essi composto da blocchi 4x4 con informazioni sulla luminanza (intensità) e
439 due blocchi da 8x8 a metà risoluzione per la crominanza (colore) (uno per
440 l'asse rosso-ciano e l'altro per l'asse blu-giallo).
441 Anche se la larghezza e l'altezza del tuo filmato non sono multipli di 16 il
442 codificatore userà tanti macroblocchi 16x16 in modo da coprire tutta la
443 superficie dell'immagine, e lo spazio in esubero sarà sprecato.
444 Indi, per migliorare la qualità a una dimensione prefissata è una brutta
445 idea utilizzare dimensioni che non siano multiple di 16.
446 </para>
447
448 <para>
449 La maggior parte dei DVD ha anche alcune con bordi neri sui lati. Lasciarli lì
450 avrà un'influenza <emphasis role="bold">molto</emphasis> negativa sulla
451 qualità in svariati modi.
452 </para>
453
454 <orderedlist>
455 <listitem>
456 <para>
457 Il tipo di compressione MPEG è pesantemente dipendente dalle trasformazioni
458 di dominio frequenti, in particolare la "trasformazione discreta del coseno"
459 (Discrete Cosine Transform (DCT)), che xxièe' simile alla trasformazione di
460 Fourier. Quest'approccio di codifica è efficiente nella rappresentazione di
461 motivi e transizioni delicate, ma trova difficoltà con spigoli più
462 definiti. Per codificarli deve usare molti più bit oppure apparirà un
463 artefatto conosciuto come 'ringing'.
464 </para>
465
466 <para>
467 La trasformazione di frequenza (DCT) prende luogo separatemente in ogni
468 macroblocco (praticamente in ogni blocco) perciò questo problema si applica
469 solo quando lo spigolo definito è dentro a un blocco. Se il bordo nero inizia
470 esattamente sul lato di un multiplo di 16, questo non e' un problema.
471 Tuttavia i bordi neri sui DVD difficilmente sono ben allineati, perciò
472 nella realtà dovrai sempre tagliarli via per evitare questi problemi.
473 </para>
474 </listitem>
475 </orderedlist>
476
477 <para>
478 Oltre alle trasformazioni del dominio di frequenza, il tipo di compressione
479 MPEG usa dei vettori di movimento per rappresetare le variazioni da un
480 fotogramma al successivo. Naturalmente i vettori di movimento funzionano molto
481 meno bene per i nuovi contenuti che arrivano dai bordi dell'immagine, dato che
482 non erano presenti nel fotogramma precedente. Fintanto che l'immagine arriva
483 fino al bordo dell'area codificata, i vettori di movimento non incontrano
484 alcun problema con li contenuto che esce dall'immagine. Tuttavia ci possono
485 esser problemi quando ci sono dei bordi neri:
486 </para>
487
488 <orderedlist continuation="continues">
489 <listitem>
490 <para>
491 Per ogni macroblocco il tipo di compressione MPEG memorizza un vettore, che
492 identifica quale parte del fotogramma precedente debba essere copiata nel
493 macroblocco stesso, come base per predire il fotogramma successivo. Serve
494 codificare solo le differenze restanti. Se un macroblocco oltrepassa il
495 bordo dell'immagine e contiene parte del bordo nero, allora i vettori di
496 movimento provenienti da altre zone dell'immagine ricopriranno il bordo
497 nero. Questo significa che si devono utilizzare molti bit o per riannerire il
498 bordo che è stato ricoperto, oppure (più verosimilmente) un vettore di
499 movimento non sarà proprio usato e tutti i cambiamenti in questo
500 macroblocco dovranno venir esplicitamente codificate. In un modo o nell'altro
501 si ricuce di gran lunga l'efficienza della codifica.
502 </para>
503
504 <para>
505 Inoltre questo problema si applica solo se i bordi neri non sono allinati
506 su limiti di multipli di 16.
507 </para>
508 </listitem>
509
510 <listitem>
511 <para>
512 Immagina infine di avere un macroblocco all'interno dell'immagine, ed un
513 oggetto che passa da questo blocco verso il bordo dell'immagine. La
514 codifica MPEG non può dire "copia la parte che è dentro all'immagine, ma
515 non il bordo nero". Perciò anche il bordo nero vi verrà copiato
516 all'interno, e molti bit saranno sprecati codificando l'immagine che si
517 suppone stia lì.
518 </para>
519
520 <para>
521 Se l'immagine arriva al limite della superficie codificata, l'MPEG ha una
522 particolare ottimizzazione che consta nel copiare ripetutamente i pixel sul
523 bordo dell'immagine quando un vettore di movimento arriva dall'esterno della
524 superficie codificata. Questa funzionalità diventa inutile quando il film
525 ha dei bordi neri. Diversamente dai problemi 1 e 2, allineare i bordi a
526 multipli di 16 in questo caso non aiuta.
527 </para>
528 </listitem>
529
530 <listitem><para>
531 A dispetto del fatto che i bordi siano completamente neri e non cambino mai,
532 c'è perlomeno un piccolo spreco nell'avere più macroblocchi.
533 </para></listitem>
534 </orderedlist>
535
536 <para>
537 Per tutte queste ragioni si consiglia di tagliar via completamente i bordi neri.
538 Inoltre, se c'è una zona di rumore/distorsione sui bordi dell'immagine,
539 tagliarla migliorerà ancora l'efficienza di codifica. I puristi videofili che
540 vogliono mantenere il più possibile l'originale potrebbero obiettare su questo
541 taglio, ma a meno di non codificare a una quantizzazione costante, la qualità
542 guadagnata tagliando sorpasserà di gran lunga la quantità di informazioni
543 perse sui bordi.
544 </para>
545 </sect2>
546
547 <!-- ********** -->
548
549 <sect2 id="menc-feat-dvd-mpeg4-crop">
550 <title>Tagliare e Ridimensionare</title>
551
552 <para>
553 Ricorda dalla sezione precedente che la dimensione finale dell'immagine che
554 codifichi dovrebbe essere un multiplo di 16 (sia in larghezza che altezza).
555 Si può ottenere ciò tagliando, ridimensionando o combinando le due cose.
556 </para>
557
558 <para>
559 Quando tagli, ci sono alcune linee guida che si devono seguire per evitare di
560 rovinare il tuo filmato.
561 Il formato YUV abituale, 4:2:0, memorizza le informazioni sulla crominanza
562 (colore) sottocampionate, per es. la crominanza viene campionata in ogni
563 direzione solo la metà di quanto venga la luminanza (intensità).
564 Osserva questo diagramma, dove L indica i punti di campionamente della
565 luminanza e C quelli della crominanza.
566 </para>
567
568 <informaltable>
569 <?dbhtml table-width="40%" ?>
570 <?dbfo table-width="40%" ?>
571 <tgroup cols="8" align="center">
572 <colspec colnum="1" colname="col1"/>
573 <colspec colnum="2" colname="col2"/>
574 <colspec colnum="3" colname="col3"/>
575 <colspec colnum="4" colname="col4"/>
576 <colspec colnum="5" colname="col5"/>
577 <colspec colnum="6" colname="col6"/>
578 <colspec colnum="7" colname="col7"/>
579 <colspec colnum="8" colname="col8"/>
580 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
581 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
582 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
583 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
584 <tbody>
585 <row>
586 <entry>L</entry>
587 <entry>L</entry>
588 <entry>L</entry>
589 <entry>L</entry>
590 <entry>L</entry>
591 <entry>L</entry>
592 <entry>L</entry>
593 <entry>L</entry>
594 </row>
595 <row>
596 <entry spanname="spa1-2">C</entry>
597 <entry spanname="spa3-4">C</entry>
598 <entry spanname="spa5-6">C</entry>
599 <entry spanname="spa7-8">C</entry>
600 </row>
601 <row>
602 <entry>L</entry>
603 <entry>L</entry>
604 <entry>L</entry>
605 <entry>L</entry>
606 <entry>L</entry>
607 <entry>L</entry>
608 <entry>L</entry>
609 <entry>L</entry>
610 </row>
611 <row>
612 <entry>L</entry>
613 <entry>L</entry>
614 <entry>L</entry>
615 <entry>L</entry>
616 <entry>L</entry>
617 <entry>L</entry>
618 <entry>L</entry>
619 <entry>L</entry>
620 </row>
621 <row>
622 <entry spanname="spa1-2">C</entry>
623 <entry spanname="spa3-4">C</entry>
624 <entry spanname="spa5-6">C</entry>
625 <entry spanname="spa7-8">C</entry>
626 </row>
627 <row>
628 <entry>L</entry>
629 <entry>L</entry>
630 <entry>L</entry>
631 <entry>L</entry>
632 <entry>L</entry>
633 <entry>L</entry>
634 <entry>L</entry>
635 <entry>L</entry>
636 </row>
637 </tbody>
638 </tgroup>
639 </informaltable>
640
641 <para>
642 Come puoi vedere, le righe e le colonne dell'immagine vengono sempre a coppie.
643 Quindi i tuoi valori di spostamento e dimensione <emphasis>devono</emphasis>
644 essere numeri pari.
645 Se non lo sono la crominanza non sarà più allineata correttamente con la
646 luminanza.
647 In teoria è possibile tagliare con uno spostamento dispari, ma richiede che la
648 crominanza venga ricampionata, il che potenzialmente è un'operazione in perdita
649 e non è gestita dal filtro crop.
650 </para>
651
652 <para>
653 Inoltre, il video interlacciato viene campionato come segue:
654 </para>
655
656 <informaltable>
657 <?dbhtml table-width="80%" ?>
658 <?dbfo table-width="80%" ?>
659 <tgroup cols="16" align="center">
660 <colspec colnum="1" colname="col1"/>
661 <colspec colnum="2" colname="col2"/>
662 <colspec colnum="3" colname="col3"/>
663 <colspec colnum="4" colname="col4"/>
664 <colspec colnum="5" colname="col5"/>
665 <colspec colnum="6" colname="col6"/>
666 <colspec colnum="7" colname="col7"/>
667 <colspec colnum="8" colname="col8"/>
668 <colspec colnum="9" colname="col9"/>
669 <colspec colnum="10" colname="col10"/>
670 <colspec colnum="11" colname="col11"/>
671 <colspec colnum="12" colname="col12"/>
672 <colspec colnum="13" colname="col13"/>
673 <colspec colnum="14" colname="col14"/>
674 <colspec colnum="15" colname="col15"/>
675 <colspec colnum="16" colname="col16"/>
676 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
677 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
678 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
679 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
680 <spanspec spanname="spa9-10" namest="col9" nameend="col10"/>
681 <spanspec spanname="spa11-12" namest="col11" nameend="col12"/>
682 <spanspec spanname="spa13-14" namest="col13" nameend="col14"/>
683 <spanspec spanname="spa15-16" namest="col15" nameend="col16"/>
684 <tbody>
685 <row>
686 <entry namest="col1" nameend="col8">Campo superiore</entry>
687 <entry namest="col9" nameend="col16">Campo inferiore</entry>
688 </row>
689 <row>
690 <entry>L</entry>
691 <entry>L</entry>
692 <entry>L</entry>
693 <entry>L</entry>
694 <entry>L</entry>
695 <entry>L</entry>
696 <entry>L</entry>
697 <entry>L</entry>
698 <entry></entry>
699 <entry></entry>
700 <entry></entry>
701 <entry></entry>
702 <entry></entry>
703 <entry></entry>
704 <entry></entry>
705 <entry></entry>
706 </row>
707 <row>
708 <entry spanname="spa1-2">C</entry>
709 <entry spanname="spa3-4">C</entry>
710 <entry spanname="spa5-6">C</entry>
711 <entry spanname="spa7-8">C</entry>
712 <entry></entry>
713 <entry></entry>
714 <entry></entry>
715 <entry></entry>
716 <entry></entry>
717 <entry></entry>
718 <entry></entry>
719 <entry></entry>
720 </row>
721 <row>
722 <entry></entry>
723 <entry></entry>
724 <entry></entry>
725 <entry></entry>
726 <entry></entry>
727 <entry></entry>
728 <entry></entry>
729 <entry></entry>
730 <entry>L</entry>
731 <entry>L</entry>
732 <entry>L</entry>
733 <entry>L</entry>
734 <entry>L</entry>
735 <entry>L</entry>
736 <entry>L</entry>
737 <entry>L</entry>
738 </row>
739 <row>
740 <entry>L</entry>
741 <entry>L</entry>
742 <entry>L</entry>
743 <entry>L</entry>
744 <entry>L</entry>
745 <entry>L</entry>
746 <entry>L</entry>
747 <entry>L</entry>
748 <entry></entry>
749 <entry></entry>
750 <entry></entry>
751 <entry></entry>
752 <entry></entry>
753 <entry></entry>
754 <entry></entry>
755 <entry></entry>
756 </row>
757 <row>
758 <entry></entry>
759 <entry></entry>
760 <entry></entry>
761 <entry></entry>
762 <entry></entry>
763 <entry></entry>
764 <entry></entry>
765 <entry></entry>
766 <entry spanname="spa9-10">C</entry>
767 <entry spanname="spa11-12">C</entry>
768 <entry spanname="spa13-14">C</entry>
769 <entry spanname="spa15-16">C</entry>
770 </row>
771 <row>
772 <entry></entry>
773 <entry></entry>
774 <entry></entry>
775 <entry></entry>
776 <entry></entry>
777 <entry></entry>
778 <entry></entry>
779 <entry></entry>
780 <entry>L</entry>
781 <entry>L</entry>
782 <entry>L</entry>
783 <entry>L</entry>
784 <entry>L</entry>
785 <entry>L</entry>
786 <entry>L</entry>
787 <entry>L</entry>
788 </row>
789 <row>
790 <entry>L</entry>
791 <entry>L</entry>
792 <entry>L</entry>
793 <entry>L</entry>
794 <entry>L</entry>
795 <entry>L</entry>
796 <entry>L</entry>
797 <entry>L</entry>
798 <entry></entry>
799 <entry></entry>
800 <entry></entry>
801 <entry></entry>
802 <entry></entry>
803 <entry></entry>
804 <entry></entry>
805 <entry></entry>
806 </row>
807 <row>
808 <entry spanname="spa1-2">C</entry>
809 <entry spanname="spa3-4">C</entry>
810 <entry spanname="spa5-6">C</entry>
811 <entry spanname="spa7-8">C</entry>
812 <entry></entry>
813 <entry></entry>
814 <entry></entry>
815 <entry></entry>
816 <entry></entry>
817 <entry></entry>
818 <entry></entry>
819 <entry></entry>
820 </row>
821 <row>
822 <entry></entry>
823 <entry></entry>
824 <entry></entry>
825 <entry></entry>
826 <entry></entry>
827 <entry></entry>
828 <entry></entry>
829 <entry></entry>
830 <entry>L</entry>
831 <entry>L</entry>
832 <entry>L</entry>
833 <entry>L</entry>
834 <entry>L</entry>
835 <entry>L</entry>
836 <entry>L</entry>
837 <entry>L</entry>
838 </row>
839 <row>
840 <entry>L</entry>
841 <entry>L</entry>
842 <entry>L</entry>
843 <entry>L</entry>
844 <entry>L</entry>
845 <entry>L</entry>
846 <entry>L</entry>
847 <entry>L</entry>
848 <entry></entry>
849 <entry></entry>
850 <entry></entry>
851 <entry></entry>
852 <entry></entry>
853 <entry></entry>
854 <entry></entry>
855 <entry></entry>
856 </row>
857 <row>
858 <entry></entry>
859 <entry></entry>
860 <entry></entry>
861 <entry></entry>
862 <entry></entry>
863 <entry></entry>
864 <entry></entry>
865 <entry></entry>
866 <entry spanname="spa9-10">C</entry>
867 <entry spanname="spa11-12">C</entry>
868 <entry spanname="spa13-14">C</entry>
869 <entry spanname="spa15-16">C</entry>
870 </row>
871 <row>
872 <entry></entry>
873 <entry></entry>
874 <entry></entry>
875 <entry></entry>
876 <entry></entry>
877 <entry></entry>
878 <entry></entry>
879 <entry></entry>
880 <entry>L</entry>
881 <entry>L</entry>
882 <entry>L</entry>
883 <entry>L</entry>
884 <entry>L</entry>
885 <entry>L</entry>
886 <entry>L</entry>
887 <entry>L</entry>
888 </row>
889 </tbody>
890 </tgroup>
891 </informaltable>
892
893 <para>
894 Come puoi notare, il motivo non si ripete fino a dopo 4 linee.
895 Quindi per il video interlacciato, il tuo spostamento sull'asse y e l'altezza
896 devono essere multipli di 4.
897 </para>
898
899 <para>
900 La risoluzione nativa DVD è 720x480 per NTSC e 720x576 per PAL, ma c'è un
901 flag per l'aspetto che indica se è full-screen (4:3) o wide-screen (16:9).
902 Molti (se non quasi tutti) i DVD in widescreen non sono esattamente 16:9 e
903 possono essere sia 1.85:1 o 2.35:1 (cinescope). Questo significa che nel video
904 ci saranno bordi neri che bisogna tagliare via.
905 </para>
906
907 <para>
908 <application>MPlayer</application> fornisce un filtro che rileva i valori di
909 taglio e fornisce il rettangolo per crop (<option>-vf cropdetect</option>).
910 Esegui <application>MPlayer</application> con <option>-vf cropdetect</option> ed
911 emetterà le impostazioni di taglio per crop al fine di rimuovere i bordi.
912 Dovresti lasciare andare avanti il film abbastanza da ottenere valori di taglio
913 precisi.
914 </para>
915
916 <para>
917 Dopodiché prova con <application>MPlayer</application> i valori ottenuti usando
918 la linea comando emessa da <option>cropdetect</option>, e correggi il
919 rettangolo se e come serve.
920 Il filtro <option>rectangle</option> può esserti di aiuto, dato che ti
921 permette di impostare interattivamente la posizione del rettangolo di taglio
922 sopra al filmato.
923 Ricordati di seguire le linee guida sui multipli in modo da non disallineare
924 i piani di crominanza.
925 </para>
926
927 <para>
928 In talune occasioni, il ridimensionamento può essere indesiderabile.
929 Il ridimensionamento sulla direzione verticale è difficoltoso con video
930 interlacciato e se vuoi mantenere l'interlacciamento, dovresti evitare il
931 ridimensionamento.
932 Se non ridimensionerai, ma vuoi comunque usare dimensioni multiple di 16,
933 dovrai tagliare di più.
934 Evita di tagliare di meno, dato che i bordi neri sono un male per la codifica!
935 </para>
936
937 <para>
938 Dato che MPEG-4 usa macroblocchi 16x16 vorrai esser sicuro che ambedue le
939 dimensioni del video che stai per codificare siano multiple di 16, altrimenti
940 perderai in qualità, soprattutto a bitrate più bassi. Puoi farlo abbassando
941 la larghezza e l'altezza del rettangolo di taglio al multiplo di 16 più vicino.
942 Come detto precedentemente, quando tagli, vorrai aumentare lo scostamento Y
943 della metà della differenza tra la nuova e la vecchia altezza, in modo che il
944 video risultante sia preso dal centro del fotogramma. Inoltre, a causa del modo
945 in cui il video DVD viene campionato, assicurati che lo scostamento sia un
946 numero pari. (Infatti, come regola, non utilizzare mai valori dispari per alcun
947 parametro quando tagli e ridimensioni un video.) Se non ti va di scartare dei
948 pixel in più, potresti piuttosto preferire il ridimensionamento del video.
949 Prenderemo in esame questa situazione più avanti.
950 Puoi in verità lasciare che tutte le considerazioni suddette vengano fatte
951 dal filtro <option>cropdetect</option>, visto che ha un parametro
952 <option>round</option> facoltativo, che è impostato a 16 di default.
953 </para>
954
955 <para>
956 Fai anche attenzione ai pixel "mezzi neri" sui bordi. Assicurati di tagliare
957 anch'essi, altrimenti sprecherai bit più utili altrove.
958 </para>
959
960 <para>
961 Dopo aver detto e fatto tutto ciò, probabilmente avrei un vide i cui pixel
962 non saranno proprio 1.85:1 o 2.35:1, ma piuttosto un valore vicino. Potresti
963 calcolare a mano il nuovo rapporto di aspetto, ma
964 <application>MEncoder</application> ha un'opzione per <systemitem
965 class="library">libavcodec</systemitem> chiamata <option>autoaspect</option>
966 che lo farà per te. Non aumentare assolutamente le dimensioni del video per
967 avere i pixel quadrati, a meno che tu non voglia sprecare il tuo spazio disco.
968 Il ridimensionamento dovrebbe essere eseguito in riproduzione, e per definire
969 la risoluzione giusta il riproduttore userà l'aspetto memorizzato nell'AVI.
970 Sfortunatamente non tutti i riproduttori verificano l'informazione sul rapporto
971 perciò potresti voler comunque effettuare il ridimensionamento.
972 </para>
973 </sect2>
974
975 <!-- ********** -->
976
977 <sect2 id="menc-feat-dvd-mpeg4-resolution-bitrate">
978 <title>Scegliere la risoluzione e il bitrate</title>
979
980 <para>
981 Other parameters such as scaling, cropping, etc. will
982 <emphasis role="bold">not</emphasis> alter the file size unless you
983 change the bitrate as well!.
984 A meno che tu non stia per codificare con quantizzazione costante devi
985 impostare un bitrate.
986 La logica del bitrate è abbastanza semplice.
987 Normalmente il bitrate viene misurato in kilobit (1000 bit) al secondo.
988 La dimensione del filmato sul disco è il bitrate moltiplicato per la durata
989 del filmato, più un piccolo quantitativo in "surplus" (vedi per esempio la
990 sezione sul
991 <link linkend="menc-feat-dvd-mpeg4-muxing-avi-limitations">contenitore AVI</link>).
992 Altri parametri come ridimensionamento, taglio, etc...
993 <emphasis role="bold">non</emphasis> influiscono sulla dimensione del file a
994 meno che tu non cambi anche il bitrate!
995 </para>
996
997 <para>
998 Il bitrate <emphasis role="bold">non</emphasis> è direttamente proporzionale
999 alla risoluzione.
1000 Tanto per capirci, un file 320x240 a 200 kbit/sec non avrà la stessa qualità
1001 dello stesso filmato a 640x480 e 800 kbit/sec!
1002 Ci sono due ragioni per ciò:
1003 <orderedlist>
1004 <listitem><para>
1005 <emphasis role="bold">Percettiva</emphasis>: noti di più gli artefatti MPEG
1006 quando sono più grandi!
1007 Gli artefatti appaiono a livello dei blocchi (8x8).
1008 Il tuo occhio non noterà errori in 4800 piccoli blocchi tanti quanti ne
1009 vedrà in 1200 grossi blocchi (assumendo che tu li stia ridimensionando tutti
1010 e due a schermo intero).
1011 </para></listitem>
1012 <listitem><para>
1013 <emphasis role="bold">Teorica</emphasis> : quando rimpicciolisci un immagine
1014 ma usi la stessa dimensione dei blocchi (8x8) per la trasformazione spaziale
1015 della frequenza, hai più dati nelle bande ad alta frequenza. In parole
1016 povere, ogni pixel contiene più dettagli di quanti ne contenesse prima.
1017 Quindi anche se la tua immagine rimpicciolita contiene 1/4 delle informazioni
1018 sulle direzioni spaziali, potrebbe ancora contenere una gran parte delle
1019 informazioni nel dominio delal frequenza (assumendo che le alte frequenze
1020 siano sotto-utilizzate nell'immagine di origine a 640x480).
1021 </para></listitem>
1022 </orderedlist>
1023 </para>
1024
1025 <para>
1026 Guide precendenti hanno consigliato di scegliere un bitrate e una risoluzione
1027 in base ad un approccio "bit al secondo", ma di solito ciò non è valido a
1028 causa delle ragioni suddette.
1029 Una stima migliore pare essere che il bitrate è proporzionale alla radice
1030 quadrata della risoluzione, per cui 320x240 e 400 kbit/sec sarà
1031 paragonabile a 640x480 a 800 kbit/sec.
1032 Tuttavia ciò non è stato verificato con certezza empirica o teorica.
1033 Inoltre, dato che i filmati hanno diversi livelli di disturbo, dettaglio, angoli
1034 di movimento, etc..., è vano dare consigli generici su bit per lunghezza della
1035 diagonale (analogamente a bit per pixel, usando la radice quadrata).
1036 </para>
1037 <para>
1038 Finora abbiamo parlato della difficoltà nel scegliere un bitrate e una
1039 risoluzione.
1040 </para>
1041
1042
1043 <sect3 id="menc-feat-dvd-mpeg4-resolution-bitrate-compute">
1044 <title>Calcolare la risoluzione</title>
1045
1046 <para>
1047 I passaggi seguenti ti guideranno nel calcolo della risoluzione per la tua
1048 codifica senza distorcere troppo il video, tenendo in considerazione vari tipo
1049 di informazioni riguardo la sorgente video.
1050 Per prima cosa dovresti calcolare il rapporto di aspetto codificato:
1051 <systemitem>ARc = (Wc x (ARa / PRdvd )) / Hc</systemitem>
1052
1053 <itemizedlist>
1054 <title>dove:</title>
1055 <listitem><para>
1056 Wc e Hc sono la larghezza e l'altezza del video tagliato,
1057 </para></listitem>
1058 <listitem><para>
1059 ARa è il rapporto di aspetto mostrato, che di solito è 4/3 o 16/9,
1060 </para></listitem>
1061 <listitem><para>
1062 PRdvd à il rapporto del pixel del DVD che è uguale a 1.25=(720/576) per DVD
1063 PAL e 1.5=(720/480) per DVD NTSC.
1064 </para></listitem>
1065 </itemizedlist>
1066 </para>
1067
1068 <para>
1069 Dopo puoi calcolare la risoluzione X e Y, basandoti su un dato fattore
1070 di qualità di compressione (Compression Quality, CQ):
1071 <systemitem>ResY = INT(SQRT( 1000*Bitrate/25/ARc/CQ )/16) * 16</systemitem>
1072 and
1073 <systemitem>ResX = INT( ResY * ARc / 16) * 16</systemitem>
1074 </para>
1075
1076 <para>
1077 Okay, ma cos'è la CQ?
1078 However, if you have a target size for your movie (1 or 2 CDs for instance),
1079 there is a limited total number of bits that you can spend; therefore it is
1080 necessary to find a good tradeoff between compressibility and quality.
1081 Il CQ rappresenta il numero di bit per pixel e per fotogramma in codifica.
1082 Parlando più semplicemente, più alto è la CQ, più difficilmente si vedranno
1083 codificati degli artefatti.
1084 </para>
1085
1086 <para>
1087 La CQ dipende dal bitrate, dall'efficienza del codec video e dalla risoluzione
1088 del filmato.
1089 Per alzare la CQ, di solito dovrai rimpicciolire il filmato visto che il bitrate
1090 viene calcolato in funzione della dimensione voluta e della lunghezza del
1091 filmato, che sono delle costanti.
1092 Con codec MPEG-4 ASP come <systemitem class="library">Xvid</systemitem> e
1093 <systemitem class="library">libavcodec</systemitem>, una CQ inferiore a 0.18
1094 solitamente genera un'immagine abbastanza squadrettata, perché non ci sono
1095 abbastanza bit per codificare l'informazione di ogni macroblocco. (MPEG4, come
1096 molti altri codec, ragruppa i pixel in blocchi di pixel per comprimere
1097 l'immagine; se non ci sono abbastanza bit, si vedono i bordi dei blocchi.)
1098 E' saggio anche prendere una CQ compresa tra 0.20 e 0.22 per un rip a 1 CD,
1099 e 0.26-0.28 per un rip a 2 CD con impostazioni standard di codifica.
1100 Opzioni più evolute di codifica come quelle qui indicate per
1101 <link linkend="menc-feat-mpeg4-lavc-example-settings"><systemitem class="library">libavcodec</systemitem></link>
1102 e
1103 <link linkend="menc-feat-xvid-example-settings"><systemitem class="library">Xvid</systemitem></link>
1104 dovrebbero permetterti di ottenere la stessa qualità con CQ compresa tra
1105 0.18 e 0.20 per un rip da 1 CD, e da 0.24 a 0.26 per 2 CD.
1106 Con codec MPEG-4 AVC come <systemitem class="library">x264</systemitem>,
1107 puoi usare una CQ che varia da 0.14 a 0.16 con opzioni standard di codifica, e
1108 dovresti riuscire a scendere tra 0.10 e 0.12 con <link linkend="menc-feat-x264-example-settings">impostazioni avanzate di codifica
1109 <systemitem class="library">x264</systemitem></link>.
1110 </para>
1111
1112 <para>
1113 Prendi per favore nota che CQ è solo un valore indicativo, dato che dipende dal
1114 contenuto che viene codificato, una CQ di 0.18 può andar bene per un Bergman,
1115 mentre per un film come Matrix, che contiene molte scene ad alta velocità, no.
1116 D'altro canto è inutile portare la CQ oltre 0.30 dato che sprecherai dei bit
1117 senza avere alcun guadagno visibile in qualità.
1118 Nota anche che come detto precedentemente in questa guida, per video a bassa
1119 risoluzione serve una CQ più alta (in rapporto, per esempio, alla risoluzione
1120 DVD) perché si vedano bene.
1121 </para>
1122 </sect3>
1123 </sect2>
1124
1125 <!-- ********** -->
1126
1127 <sect2 id="menc-feat-dvd-mpeg4-filtering">
1128 <title>Filtraggio</title>
1129
1130 <para>
1131 Imparare come usare i filtri video di <application>MEncoder</application> è
1132 essenziale per produrre delle buone codfiche.
1133 Tutta l'elaborazione video è eseguita attraverso i filtri -- taglio,
1134 ridimensionamento, aggiustamento del colore, rimozione del disturbo, rilevamento
1135 margini, deinterlacciatura, telecine, telecine inverso, e deblocco, solo per
1136 nominarne qualcuno.
1137 Insieme con la vasta gamma di formati di entrata gestiti, la varietà dei
1138 filtri disponibili in <application>MEncoder</application> è uno dei suoi
1139 più grandi vantaggi sugli altri programmi similari.
1140 </para>
1141
1142 <para>
1143 I filtri vengono caricati in catena usando l'opzione -vf:
1144
1145 <screen>-vf filtro1=opzioni,filtro2=opzioni,...</screen>
1146
1147 La maggior parte dei filtri riceve alcune opzioni numeriche separate da due
1148 punti, ma la sintassi per le opzioni cambia da filtro a filtro, indi leggiti la
1149 pagina man per i dettagli sul filtro che desideri usare.
1150 </para>
1151
1152 <para>
1153 I filtri lavorano sul video nell'ordine in cui vengono caricati.
1154 Per esempio la catena seguente:
1155
1156 <screen>-vf crop=688:464:12:4,scale=640:464</screen>
1157
1158 dapprima taglia la zona 688x464 dell'immagine con uno scostamento dall'alto a
1159 sinistra di (12,4), e poi ridimensiona il risultato a 640x464.
1160 </para>
1161
1162 <para>
1163 Taluni filtri devono essere caricati all'inizio o vicino all'inizio della
1164 catena di filtri, in modo da trarre vantaggio dalle informazioni che arrivano
1165 dal decoder video, che potrebbero essere perse o invalidate da altri filtri.
1166 Gli esempi principali sono <option>pp</option> (post elaborazione
1167 (postprocessing), solo quando esegue operazioni di deblock o dering),
1168 <option>spp</option> (un altra post elaborazione per eliminare artefatti MPEG),
1169 <option>pullup</option> (telecine inverso), e <option>softpulldown</option>
1170 (per passare da telecine soft a hard).
1171 </para>
1172
1173 <para>
1174 In generale vorrai filtrare il meno possibile in modo da rimaner fedele alla
1175 sorgente DVD originale. Il taglio è spesso necessario (com detto sopra), ma
1176 evita di ridimensionare il video. Anche se alcune volte si preferisce
1177 rimpicciolire per poter usare quantizzatori più alti, vogliamo evitare ciò:
1178 ricorda che abbiamo sin dall'inizio deciso di investire bit in qualità.
1179 </para>
1180
1181 <para>
1182 In più, non reimpostare la gamma, il contrasto, la luminosità, etc...
1183 Quello che si vede bene sul tuo schermo potrebbe non vedersi bene su altro.
1184 Queste modifiche dovrebbero esser fatte solo durante la riproduzione.
1185 </para>
1186
1187 <para>
1188 Una cosa che voresti però fare è tuttavia far passare il video attraverso un
1189 leggero filtro di rimozione disturbo, come <option>-vf hqdn3d=2:1:2</option>.
1190 Ancora, è una questione di poter meglio utilizzare quei bit: perché sprecarli
1191 codificando disturbo mentre puoi semplicemente aggiungerlo di nuovo durante la
1192 riproduzione? Alzando i parametri per <option>hqdn3d</option> aumenterà
1193 ancora la compressione, ma se aumenti troppo i valori, rischi un degrado pesante
1194 dell'immagine. I valori sopra consigliati (<option>2:1:2</option>) sono
1195 abbastanza conservativi; sentiti libero di sperimentare con valori più alti e
1196 verificare da solo il risultato.
1197 </para>
1198 </sect2>
1199
1200 <!-- ********** -->
1201
1202 <sect2 id="menc-feat-dvd-mpeg4-interlacing">
1203 <title>Interlacciamento e Telecine</title>
1204
1205 <para>
1206 Quasi tutti i film vengono ripresi a 24 fps. Dato che NTSC è 30000/1001 fps,
1207 si devono eseguire alcune elaborazioni affinché questo video a 24 fps sia
1208 letto al giusto framerate NTSC. Il processo è chiamato "3:2 pulldown", meglio
1209 conosciuto come "telecine" (poiché pulldown viene spesso applicato durante il
1210 processo di telecine), e descritto rozzamente, agisce rallentando il film a
1211 24000/1001 fps, e ripetendo ogni quarto fotogramma.
1212 </para>
1213
1214 <para>
1215 Non viene invece eseguita alcuna elaborazione sul video per i DVD PAL, che
1216 girano a 25 fps. (Tecnicamente, PAL può subire il telecine, chiamato
1217 "2:2 pulldown", ma non è usanza abituale.) Il film a 24 fps viene
1218 semplicemente riprodotto a 25 fps. Il risultato è che il filmato è leggermente
1219 più veloce, ma a meno che tu non sia un alieno, probabilmente non noterai la
1220 differenza.
1221 La maggior parte dei DVD PAL hanno audio corretto ai picchi, in modo che quando
1222 siano riprodotti a 25 fps le cose suonino giuste, anche se la traccia audio
1223 (e quindi tutto il filmato) ha un tempo di riproduzione che è il 4% inferiore
1224 ai DVD NTSC.
1225 </para>
1226
1227 <para>
1228 A causa del fatto che il video nei DVD PAL non è stato alterato, non dovrai
1229 preoccuperti molto della frequenza fotogrammi. La sorgente è 25 fps, e il tuo
1230 rip sarà a 25 fps. Tuttavia, se stai codificando un film da DVD NTSC,
1231 potresti dover applicare il telecine inverso.
1232 </para>
1233
1234 <para>
1235 Per film ripresi a 24 fps, il video sul DVD NTSC è o con telecine a 30000/1001,
1236 oppure è progressivo a 24000/1001 fps e destinato a subire il telecine al volo
1237 da un lettore DVD. D'altro canto le serie TV sono solitamente solo
1238 interlacciate, senza telecine. Questa non è una regola ferrea: alcune serie TV
1239 sono interlacciate (come Buffy the Vampire Slayer) mentre alcune sono un misto
1240 di progressivo e interlacciato (come Angel, o 24).
1241 </para>
1242
1243 <para>
1244 Si consiglia vivamente di leggere la sezione su
1245 <link linkend="menc-feat-telecine">Come trattare il telecine e l'interlacciamento nei DVD NTSC</link>
1246 per imparare come gestire le varie possibilità.
1247 </para>
1248
1249 <para>
1250 Ciononostante, se stai principalmente rippando solo film, solitamente ti
1251 troverai di fronte a video a 24 fps progressivo o con telecine, nel qual caso
1252 puoi usare il filtro <option>pullup</option> <option>-vf
1253 pullup,softskip</option>.
1254 </para>
1255 </sect2>
1256
1257 <!-- ********** -->
1258
1259 <sect2 id="menc-feat-dvd-mpeg4-encoding-interlaced">
1260 <title>Codificare video interlacciato</title>
1261
1262 <para>
1263 Se il film che vuoi codificare è interlacciato (video NTSC o PAL) dovrai
1264 scegliere se vuoi de-interlacciare o no.
1265 Se da un lato de-interlacciare renderà il tuo filmato utilizzabile su
1266 schermi a scansione progressiva come monitor di computer o proiettori, porta
1267 con sé un costo: la frequenza dei campi di 50 o 60000/1001 campi al secondo
1268 viene dimezzata a 25 o 30000/1001 fotogrammi al secondo, e circa la metà delle
1269 informazioni nel tuo film saranno perdute, in scene con movimento significativo.
1270 </para>
1271
1272 <para>
1273 Per di più, se stai codificando puntando ad alta qualità di archiviazione.
1274 si consiglia di non de-interlacciare.
1275 Puoi sempre de-interlacciare il film durante la riproduzione attraverso
1276 dispositivi a scansione progressiva.
1277 La potenza dei computer attuali forza per i riproduttori l'utilizzo di un filtro
1278 di de-interlacciamento, che porta un leggero degrado dell'immagine.
1279 Ma i lettori del futuro saranno in grado di simulare lo schermo di una TV,
1280 de-interlacciando a piena frequenza di campi e interpolando 50 o 60000/1001
1281 fotogrammi interi al secondo dal video interlacciato
1282 </para>
1283
1284 <para>
1285 Bisogna porre speciale attenzione quando si lavora con video interlacciato:
1286 </para>
1287
1288 <orderedlist>
1289 <listitem><para>
1290 Altezza e scostamento del taglio devono essere multipli di 4.
1291 </para></listitem>
1292 <listitem><para>
1293 Qualsiasi ridimensionamento verticale va fatto in modalità interlacciata.
1294 </para></listitem>
1295 <listitem><para>
1296 I filtri di post elaborazione e di rimozione disturbo potrebbero non
1297 funzionare come ci si aspetta a meno che tu non ponga particolare attenzione
1298 per farli lavorare su un campo per volta, e possono rovinare il video quando
1299 usati in modo non corretto.
1300 </para></listitem>
1301 </orderedlist>
1302
1303 <para>
1304 Tenendo a mente queste cose, ecco il nostro primo esempio:
1305 <screen>
1306 mencoder <replaceable>capture.avi</replaceable> -mc 0 -oac lavc -ovc lavc -lavcopts \
1307 vcodec=mpeg2video:vbitrate=6000:ilme:ildct:acodec=mp2:abitrate=224
1308 </screen>
1309 Nota le opzioni <option>ilme</option> e <option>ildct</option>.
1310 </para>
1311 </sect2>
1312
1313 <!-- ********** -->
1314
1315 <sect2 id="menc-feat-dvd-mpeg4-av-sync">
1316 <title>Notes on Audio/Video synchronization</title>
1317
1318 <para>
1319 <application>MEncoder</application>'s audio/video synchronization
1320 algorithms were designed with the intention of recovering files with
1321 broken sync.
1322 However, in some cases they can cause unnecessary skipping and duplication of
1323 frames, and possibly slight A/V desync, when used with proper input
1324 (of course, A/V sync issues apply only if you process or copy the
1325 audio track while transcoding the video, which is strongly encouraged).
1326 Therefore, you may have to switch to basic A/V sync with
1327 the <option>-mc 0</option> option, or put this in your
1328 <systemitem>~/.mplayer/mencoder</systemitem> config file, as long as
1329 you are only working with good sources (DVD, TV capture, high quality
1330 MPEG-4 rips, etc) and not broken ASF/RM/MOV files.
1331 </para>
1332
1333 <para>
1334 If you want to further guard against strange frame skips and
1335 duplication, you can use both <option>-mc 0</option> and
1336 <option>-noskip</option>.
1337 This will prevent <emphasis>all</emphasis> A/V sync, and copy frames
1338 one-to-one, so you cannot use it if you will be using any filters that
1339 unpredictably add or drop frames, or if your input file has variable
1340 framerate!
1341 Therefore, using <option>-noskip</option> is not in general recommended.
1342 </para>
1343
1344 <para>
1345 The so-called "three-pass" audio encoding which
1346 <application>MEncoder</application> supports has been reported to cause A/V
1347 desync.
1348 This will definitely happen if it is used in conjunction with certain
1349 filters, therefore, it is now recommended <emphasis>not</emphasis> to
1350 use three-pass audio mode.
1351 This feature is only left for compatibility purposes and for expert
1352 users who understand when it is safe to use and when it is not.
1353 If you have never heard of three-pass mode before, forget that we
1354 even mentioned it!
1355 </para>
1356
1357 <para>
1358 There have also been reports of A/V desync when encoding from stdin
1359 with <application>MEncoder</application>.
1360 Do not do this! Always use a file or CD/DVD/etc device as input.
1361 </para>
1362 </sect2>
1363
1364 <!-- ********** -->
1365
1366 <sect2 id="menc-feat-dvd-mpeg4-codec">
1367 <title>Choosing the video codec</title>
1368
1369 <para>
1370 Which video codec is best to choose depends on several factors,
1371 like size, quality, streamability, usability and popularity, some of
1372 which widely depend on personal taste and technical constraints.
1373 </para>
1374 <itemizedlist>
1375 <listitem>
1376 <para>
1377 <emphasis role="bold">Compression efficiency</emphasis>:
1378 It is quite easy to understand that most newer-generation codecs are
1379 made to increase quality and compression.
1380 Therefore, the authors of this guide and many other people suggest that
1381 you cannot go wrong
1382 <footnote id='fn-menc-feat-dvd-mpeg4-codec-cpu'><para>
1383 Be careful, however: Decoding DVD-resolution MPEG-4 AVC videos
1384 requires a fast machine (i.e. a Pentium 4 over 1.5GHz or a Pentium M
1385 over 1GHz).
1386 </para></footnote>
1387 when choosing MPEG-4 AVC codecs like
1388 <systemitem class="library">x264</systemitem> instead of MPEG-4 ASP codecs
1389 such as <systemitem class="library">libavcodec</systemitem> MPEG-4 or
1390 <systemitem class="library">Xvid</systemitem>.
1391 (Advanced codec developers may be interested in reading Michael
1392 Niedermayer's opinion on
1393 "<ulink url="http://guru.multimedia.cx/?p=10">why MPEG4-ASP sucks</ulink>".)
1394 Likewise, you should get better quality using MPEG-4 ASP than you
1395 would with MPEG-2 codecs.
1396 </para>
1397
1398 <para>
1399 However, newer codecs which are in heavy development can suffer from
1400 bugs which have not yet been noticed and which can ruin an encode.
1401 This is simply the tradeoff for using bleeding-edge technology.
1402 </para>
1403
1404 <para>
1405 What is more, beginning to use a new codec requires that you spend some
1406 time becoming familiar with its options, so that you know what
1407 to adjust to achieve a desired picture quality.
1408 </para>
1409 </listitem>
1410
1411 <listitem><para>
1412 <emphasis role="bold">Hardware compatibility</emphasis>:
1413 It usually takes a long time for standalone video players to begin to
1414 include support for the latest video codecs.
1415 As a result, most only support MPEG-1 (like VCD, XVCD and KVCD), MPEG-2
1416 (like DVD, SVCD and KVCD) and MPEG-4 ASP (like DivX,
1417 <systemitem class="library">libavcodec</systemitem>'s LMP4 and
1418 <systemitem class="library">Xvid</systemitem>)
1419 (Beware: Usually, not all MPEG-4 ASP features are supported).
1420 Please refer to the technical specs of your player (if they are available),
1421 or google around for more information.
1422 </para></listitem>
1423
1424 <listitem>
1425 <para>
1426 <emphasis role="bold">Best quality per encoding time</emphasis>:
1427 Codecs that have been around for some time (such as
1428 <systemitem class="library">libavcodec</systemitem> MPEG-4 and
1429 <systemitem class="library">Xvid</systemitem>) are usually heavily
1430 optimized with all kinds of smart algorithms and SIMD assembly code.
1431 That is why they tend to yield the best quality per encoding time ratio.
1432 However, they may have some very advanced options that, if enabled,
1433 will make the encode really slow for marginal gains.
1434 </para>
1435
1436 <para>
1437 If you are after blazing speed you should stick around the default
1438 settings of the video codec (although you should still try the other
1439 options which are mentioned in other sections of this guide).
1440 </para>
1441
1442 <para>
1443 You may also consider choosing a codec which can do multi-threaded
1444 processing, though this is only useful for users of machines with
1445 several CPUs.
1446 <systemitem class="library">libavcodec</systemitem> MPEG-4 does
1447 allow that, but speed gains are limited, and there is a slight
1448 negative effect on picture quality.
1449 <systemitem class="library">Xvid</systemitem>'s multi-threaded encoding,
1450 activated by the <option>threads</option> option, can be used to
1451 boost encoding speed &mdash; by about 40-60% in typical cases &mdash;
1452 with little if any picture degradation.
1453 <systemitem class="library">x264</systemitem> also allows multi-threaded
1454 encoding, which currently speeds up encoding by 94% per CPU core while
1455 lowering PSNR between 0.005dB and 0.01dB on a typical setup.
1456 </para>
1457 </listitem>
1458
1459 <listitem>
1460 <para>
1461 <emphasis role="bold">Personal taste</emphasis>:
1462 This is where it gets almost irrational: For the same reason that some
1463 hung on to DivX&nbsp;3 for years when newer codecs were already doing wonders,
1464 some folks will prefer <systemitem class="library">Xvid</systemitem>
1465 or <systemitem class="library">libavcodec</systemitem> MPEG-4 over
1466 <systemitem class="library">x264</systemitem>.
1467 </para>
1468 <para>
1469 You should make your own judgement; do not take advice from people who
1470 swear by one codec.
1471 Take a few sample clips from raw sources and compare different
1472 encoding options and codecs to find one that suits you best.
1473 The best codec is the one you master, and the one that looks
1474 best to your eyes on your display
1475 <footnote id='fn-menc-feat-dvd-mpeg4-codec-playback'><para>
1476 The same encode may not look the same on someone else's monitor or
1477 when played back by a different decoder, so future-proof your encodes by
1478 playing them back on different setups.
1479 </para></footnote>!
1480 </para>
1481 </listitem>
1482 </itemizedlist>
1483
1484 <para>
1485 Please refer to the section
1486 <link linkend="menc-feat-selecting-codec">selecting codecs and container formats</link>
1487 to get a list of supported codecs.
1488 </para>
1489 </sect2>
1490
1491 <!-- ********** -->
1492
1493 <sect2 id="menc-feat-dvd-mpeg4-audio">
1494 <title>Audio</title>
1495
1496 <para>
1497 Audio is a much simpler problem to solve: if you care about quality, just
1498 leave it as is.
1499 Even AC-3 5.1 streams are at most 448Kbit/s, and they are worth every bit.
1500 You might be tempted to transcode the audio to high quality Vorbis, but
1501 just because you do not have an A/V receiver for AC-3 pass-through today
1502 does not mean you will not have one tomorrow. Future-proof your DVD rips by
1503 preserving the AC-3 stream.
1504 You can keep the AC-3 stream either by copying it directly into the video
1505 stream <link linkend="menc-feat-mpeg4">during the encoding</link>.
1506 You can also extract the AC-3 stream in order to mux it into containers such
1507 as NUT or Matroska.
1508 <screen>
1509 mplayer <replaceable>source_file.vob</replaceable> -aid 129 -dumpaudio -dumpfile <replaceable>sound.ac3</replaceable>
1510 </screen>
1511 will dump into the file <replaceable>sound.ac3</replaceable> the
1512 audio track number 129 from the file
1513 <replaceable>source_file.vob</replaceable> (NB: DVD VOB files
1514 usually use a different audio numbering,
1515 which means that the VOB audio track 129 is the 2nd audio track of the file).
1516 </para>
1517
1518 <para>
1519 But sometimes you truly have no choice but to further compress the
1520 sound so that more bits can be spent on the video.
1521 Most people choose to compress audio with either MP3 or Vorbis audio codecs.
1522 While the latter is a very space-efficient codec, MP3 is better supported
1523 by hardware players, although this trend is changing.
1524 </para>
1525
1526 <para>
1527 Do <emphasis>not</emphasis> use <option>-nosound</option> when encoding
1528 a file with audio, even if you will be encoding and muxing audio
1529 separately later.
1530 Though it may work in ideal cases, using <option>-nosound</option> is
1531 likely to hide some problems in your encoding command line setting.
1532 In other words, having a soundtrack during your encode assures you that,
1533 provided you do not see messages such as
1534 <quote>Too many audio packets in the buffer</quote>, you will be able
1535 to get proper sync.
1536 </para>
1537
1538 <para>
1539 You need to have <application>MEncoder</application> process the sound.
1540 You can for example copy the orignal soundtrack during the encode with
1541 <option>-oac copy</option> or convert it to a "light" 4 kHz mono WAV
1542 PCM with <option>-oac pcm -channels 1 -srate 4000</option>.
1543 Otherwise, in some cases, it will generate a video file that will not sync
1544 with the audio.
1545 Such cases are when the number of video frames in the source file does
1546 not match up to the total length of audio frames or whenever there
1547 are discontinuities/splices where there are missing or extra audio frames.
1548 The correct way to handle this kind of problem is to insert silence or
1549 cut audio at these points.
1550 However <application>MPlayer</application> cannot do that, so if you
1551 demux the AC-3 audio and encode it with a separate app (or dump it to PCM with
1552 <application>MPlayer</application>), the splices will be left incorrect
1553 and the only way to correct them is to drop/dup video frames at the
1554 splice.
1555 As long as <application>MEncoder</application> sees the audio when it is
1556 encoding the video, it can do this dropping/duping (which is usually OK
1557 since it takes place at full black/scenechange), but if
1558 <application>MEncoder</application> cannot see the audio, it will just
1559 process all frames as-is and they will not fit the final audio stream when
1560 you for example merge your audio and video track into a Matroska file.
1561 </para>
1562
1563 <para>
1564 First of all, you will have to convert the DVD sound into a WAV file that the
1565 audio codec can use as input.
1566 For example:
1567 <screen>
1568 mplayer <replaceable>source_file.vob</replaceable> -ao pcm:file=<replaceable>destination_sound.wav</replaceable> \
1569 -vc dummy -aid 1 -vo null
1570 </screen>
1571 will dump the second audio track from the file
1572 <replaceable>source_file.vob</replaceable> into the file
1573 <replaceable>destination_sound.wav</replaceable>.
1574 You may want to normalize the sound before encoding, as DVD audio tracks
1575 are commonly recorded at low volumes.
1576 You can use the tool <application>normalize</application> for instance,
1577 which is available in most distributions.
1578 If you are using Windows, a tool such as <application>BeSweet</application>
1579 can do the same job.
1580 You will compress in either Vorbis or MP3.
1581 For example:
1582 <screen>oggenc -q1 <replaceable>destination_sound.wav</replaceable></screen>
1583 will encode <replaceable>destination_sound.wav</replaceable> with
1584 the encoding quality 1, which is roughly equivalent to 80Kb/s, and
1585 is the minimum quality at which you should encode if you care about
1586 quality.
1587 Please note that <application>MEncoder</application> currently cannot
1588 mux Vorbis audio tracks
1589 into the output file because it only supports AVI and MPEG
1590 containers as an output, each of which may lead to audio/video
1591 playback synchronization problems with some players when the AVI file
1592 contain VBR audio streams such as Vorbis.
1593 Do not worry, this document will show you how you can do that with third
1594 party programs.
1595 </para>
1596 </sect2>
1597
1598 <!-- ********** -->
1599
1600 <sect2 id="menc-feat-dvd-mpeg4-muxing">
1601 <title>Muxing</title>
1602
1603 <para>
1604 Now that you have encoded your video, you will most likely want
1605 to mux it with one or more audio tracks into a movie container, such
1606 as AVI, MPEG, Matroska or NUT.
1607 <application>MEncoder</application> is currently only able to natively output
1608 audio and video into MPEG and AVI container formats.
1609 for example:
1610 <screen>
1611 mencoder -oac copy -ovc copy -o <replaceable>output_movie.avi</replaceable> \
1612 -audiofile <replaceable>input_audio.mp2</replaceable> <replaceable>input_video.avi</replaceable>
1613 </screen>
1614 This would merge the video file <replaceable>input_video.avi</replaceable>
1615 and the audio file <replaceable>input_audio.mp2</replaceable>
1616 into the AVI file <replaceable>output_movie.avi</replaceable>.
1617 This command works with MPEG-1 layer I, II and III (more commonly known
1618 as MP3) audio, WAV and a few other audio formats too.
1619 </para>
1620
1621 <para>
1622 <application>MEncoder</application> features experimental support for
1623 <systemitem class="library">libavformat</systemitem>, which is a
1624 library from the FFmpeg project that supports muxing and demuxing
1625 a variety of containers.
1626 For example:
1627 <screen>
1628 mencoder -oac copy -ovc copy -o <replaceable>output_movie.asf</replaceable> -audiofile <replaceable>input_audio.mp2</replaceable> \
1629 <replaceable>input_video.avi</replaceable> -of lavf -lavfopts format=asf
1630 </screen>
1631 This will do the same thing as the previous example, except that
1632 the output container will be ASF.
1633 Please note that this support is highly experimental (but getting
1634 better every day), and will only work if you compiled
1635 <application>MPlayer</application> with the support for
1636 <systemitem class="library">libavformat</systemitem> enabled (which
1637 means that a pre-packaged binary version will not work in most cases).
1638 </para>
1639
1640
1641 <sect3 id="menc-feat-dvd-mpeg4-muxing-filter-issues">
1642 <title>Improving muxing and A/V sync reliability</title>
1643
1644 <para>
1645 You may experience some serious A/V sync problems while trying to mux
1646 your video and some audio tracks, where no matter how you adjust the
1647 audio delay, you will never get proper sync.
1648 That may happen when you use some video filters that will drop or
1649 duplicate some frames, like the inverse telecine filters.
1650 It is strongly encouraged to append the <option>harddup</option> video
1651 filter at the end of the filter chain to avoid this kind of problem.
1652 </para>
1653
1654 <para>
1655 Without <option>harddup</option>, if <application>MEncoder</application>
1656 wants to duplicate a frame, it relies on the muxer to put a mark on the
1657 container so that the last frame will be displayed again to maintain
1658 sync while writing no actual frame.
1659 With <option>harddup</option>, <application>MEncoder</application>
1660 will instead just push the last frame displayed again into the filter
1661 chain.
1662 This means that the encoder receives the <emphasis>exact</emphasis>
1663 same frame twice, and compresses it.
1664 This will result in a slightly bigger file, but will not cause problems
1665 when demuxing or remuxing into other container formats.
1666 </para>
1667
1668 <para>
1669 You may also have no choice but to use <option>harddup</option> with
1670 container formats that are not too tightly linked with
1671 <application>MEncoder</application> such as the ones supported through
1672 <systemitem class="library">libavformat</systemitem>, which may not
1673 support frame duplication at the container level.
1674 </para>
1675 </sect3>
1676
1677
1678 <sect3 id="menc-feat-dvd-mpeg4-muxing-avi-limitations">
1679 <title>Limitations of the AVI container</title>
1680
1681 <para>
1682 Although it is the most widely-supported container format after MPEG-1,
1683 AVI also has some major drawbacks.
1684 Perhaps the most obvious is the overhead.
1685 For each chunk of the AVI file, 24 bytes are wasted on headers and index.
1686 This translates into a little over 5 MB per hour, or 1-2.5%
1687 overhead for a 700 MB movie. This may not seem like much, but it could
1688 mean the difference between being able to use 700 kbit/sec video or
1689 714 kbit/sec, and every bit of quality counts.
1690 </para>
1691
1692 <para>
1693 In addition this gross inefficiency, AVI also has the following major
1694 limitations:
1695 </para>
1696
1697 <orderedlist>
1698 <listitem><para>
1699 Only fixed-fps content can be stored. This is particularly limiting
1700 if the original material you want to encode is mixed content, for
1701 example a mix of NTSC video and film material.
1702 Actually there are hacks that can be used to store mixed-framerate
1703 content in AVI, but they increase the (already huge) overhead
1704 fivefold or more and so are not practical.
1705 </para></listitem>
1706 <listitem><para>
1707 Audio in AVI files must be either constant-bitrate (CBR) or
1708 constant-framesize (i.e. all frames decode to the same number of
1709 samples).
1710 Unfortunately, the most efficient codec, Vorbis, does not meet
1711 either of these requirements.
1712 Therefore, if you plan to store your movie in AVI, you will have to
1713 use a less efficient codec such as MP3 or AC-3.
1714 </para></listitem>
1715 </orderedlist>
1716
1717 <para>
1718 Having said all that, <application>MEncoder</application> does not
1719 currently support variable-fps output or Vorbis encoding.
1720 Therefore, you may not see these as limitations if
1721 <application>MEncoder</application> is the
1722 only tool you will be using to produce your encodes.
1723 However, it is possible to use <application>MEncoder</application>
1724 only for video encoding, and then use external tools to encode
1725 audio and mux it into another container format.
1726 </para>
1727 </sect3>
1728
1729
1730 <sect3 id="menc-feat-dvd-mpeg4-muxing-matroska">
1731 <title>Muxing into the Matroska container</title>
1732
1733 <para>
1734 Matroska is a free, open standard container format, aiming
1735 to offer a lot of advanced features, which older containers
1736 like AVI cannot handle.
1737 For example, Matroska supports variable bitrate audio content
1738 (VBR), variable framerates (VFR), chapters, file attachments,
1739 error detection code (EDC) and modern A/V Codecs like "Advanced Audio
1740 Coding" (AAC), "Vorbis" or "MPEG-4 AVC" (H.264), next to nothing
1741 handled by AVI.
1742 </para>
1743
1744 <para>
1745 The tools required to create Matroska files are collectively called
1746 <application>mkvtoolnix</application>, and are available for most
1747 Unix platforms as well as <application>Windows</application>.
1748 Because Matroska is an open standard you may find other
1749 tools that suit you better, but since mkvtoolnix is the most
1750 common, and is supported by the Matroska team itself, we will
1751 only cover its usage.
1752 </para>
1753
1754 <para>
1755 Probably the easiest way to get started with Matroska is to use
1756 <application>MMG</application>, the graphical frontend shipped with
1757 <application>mkvtoolnix</application>, and follow the
1758 <ulink url="http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html">guide to mkvmerge GUI (mmg)</ulink>
1759 </para>
1760
1761 <para>
1762 You may also mux audio and video files using the command line:
1763 <screen>
1764 mkvmerge -o <replaceable>output.mkv</replaceable> <replaceable>input_video.avi</replaceable> <replaceable>input_audio1.mp3</replaceable> <replaceable>input_audio2.ac3</replaceable>
1765 </screen>
1766 This would merge the video file <replaceable>input_video.avi</replaceable>
1767 and the two audio files <replaceable>input_audio1.mp3</replaceable>
1768 and <replaceable>input_audio2.ac3</replaceable> into the Matroska
1769 file <replaceable>output.mkv</replaceable>.
1770 Matroska, as mentioned earlier, is able to do much more than that, like
1771 multiple audio tracks (including fine-tuning of audio/video
1772 synchronization), chapters, subtitles, splitting, etc...
1773 Please refer to the documentation of those applications for
1774 more details.
1775 </para>
1776 </sect3>
1777 </sect2>
1778 </sect1>
1779
1780
1781 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
1782
1783
1784 <sect1 id="menc-feat-telecine">
1785 <title>How to deal with telecine and interlacing within NTSC DVDs</title>
1786
1787 <sect2 id="menc-feat-telecine-intro">
1788 <title>Introduction</title>
1789
1790 <formalpara>
1791 <title>What is telecine?</title>
1792 <para>
1793 If you do not understand much of what is written in this document, read the
1794 <ulink url="http://en.wikipedia.org/wiki/Telecine">Wikipedia entry on telecine</ulink>.
1795 It is an understandable and reasonably comprehensive
1796 description of what telecine is.
1797 </para></formalpara>
1798
1799 <formalpara>
1800 <title>A note about the numbers.</title>
1801 <para>
1802 Many documents, including the guide linked above, refer to the fields
1803 per second value of NTSC video as 59.94 and the corresponding frames
1804 per second values as 29.97 (for telecined and interlaced) and 23.976
1805 (for progressive). For simplicity, some documents even round these
1806 numbers to 60, 30, and 24.
1807 </para></formalpara>
1808
1809 <para>
1810 Strictly speaking, all those numbers are approximations. Black and
1811 white NTSC video was exactly 60 fields per second, but 60000/1001
1812 was later chosen to accomodate color data while remaining compatible
1813 with contemporary black and white televisions. Digital NTSC video
1814 (such as on a DVD) is also 60000/1001 fields per second. From this,
1815 interlaced and telecined video are derived to be 30000/1001 frames
1816 per second; progressive video is 24000/1001 frames per second.
1817 </para>
1818
1819 <para>
1820 Older versions of the <application>MEncoder</application> documentation
1821 and many archived mailing list posts refer to 59.94, 29.97, and 23.976.
1822 All <application>MEncoder</application> documentation has been updated
1823 to use the fractional values, and you should use them too.
1824 </para>
1825
1826 <para>
1827 <option>-ofps 23.976</option> is incorrect.
1828 <option>-ofps 24000/1001</option> should be used instead.
1829 </para>
1830
1831 <formalpara>
1832 <title>How telecine is used.</title>
1833 <para>
1834 All video intended to be displayed on an NTSC
1835 television set must be 60000/1001 fields per second. Made-for-TV movies
1836 and shows are often filmed directly at 60000/1001 fields per second, but
1837 the majority of cinema is filmed at 24 or 24000/1001 frames per
1838 second. When cinematic movie DVDs are mastered, the video is then
1839 converted for television using a process called telecine.
1840 </para></formalpara>
1841
1842 <para>
1843 On a DVD, the video is never actually stored as 60000/1001 fields per
1844 second. For video that was originally 60000/1001, each pair of fields is
1845 combined to form a frame, resulting in 30000/1001 frames per
1846 second. Hardware DVD players then read a flag embedded in the video
1847 stream to determine whether the odd- or even-numbered lines should
1848 form the first field.
1849 </para>
1850
1851 <para>
1852 Usually, 24000/1001 frames per second content stays as it is when
1853 encoded for a DVD, and the DVD player must perform telecining
1854 on-the-fly. Sometimes, however, the video is telecined
1855 <emphasis>before</emphasis> being stored on the DVD; even though it
1856 was originally 24000/1001 frames per second, it becomes 60000/1001 fields per
1857 second. When it is stored on the DVD, pairs of fields are combined to form
1858 30000/1001 frames per second.
1859 </para>
1860
1861 <para>
1862 When looking at individual frames formed from 60000/1001 fields per
1863 second video, telecined or otherwise, interlacing is clearly visible
1864 wherever there is any motion, because one field (say, the
1865 even-numbered lines) represents a moment in time 1/(60000/1001)
1866 seconds later than the other. Playing interlaced video on a computer
1867 looks ugly both because the monitor is higher resolution and because
1868 the video is shown frame-after-frame instead of field-after-field.
1869 </para>
1870
1871 <itemizedlist>
1872 <title>Notes:</title>
1873 <listitem><para>
1874 This section only applies to NTSC DVDs, and not PAL.
1875 </para></listitem>
1876 <listitem><para>
1877 The example <application>MEncoder</application> lines throughout the
1878 document are <emphasis role="bold">not</emphasis> intended for
1879 actual use. They are simply the bare minimum required to encode the
1880 pertaining video category. How to make good DVD rips or fine-tune
1881 <systemitem class="library">libavcodec</systemitem> for maximal
1882 quality is not within the scope of this document.
1883 </para></listitem>
1884 <listitem><para>
1885 There are a couple footnotes specific to this guide, linked like this:
1886 <link linkend="menc-feat-telecine-footnotes">[1]</link>
1887 </para></listitem>
1888 </itemizedlist>
1889 </sect2>
1890
1891 <!-- ********** -->
1892
1893 <sect2 id="menc-feat-telecine-ident">
1894 <title>How to tell what type of video you have</title>
1895
1896 <sect3 id="menc-feat-telecine-ident-progressive">
1897 <title>Progressive</title>
1898
1899 <para>
1900 Progressive video was originally filmed at 24000/1001 fps, and stored
1901 on the DVD without alteration.
1902 </para>
1903
1904 <para>
1905 When you play a progressive DVD in <application>MPlayer</application>,
1906 <application>MPlayer</application> will print the following line as
1907 soon as the movie begins to play:
1908 <screen>
1909 demux_mpg: 24000/1001 fps progressive NTSC content detected, switching framerate.
1910 </screen>
1911 From this point forward, demux_mpg should never say it finds
1912 "30000/1001 fps NTSC content."
1913 </para>
1914
1915 <para>
1916 When you watch progressive video, you should never see any
1917 interlacing. Beware, however, because sometimes there is a tiny bit
1918 of telecine mixed in where you would not expect. I have encountered TV
1919 show DVDs that have one second of telecine at every scene change, or
1920 at seemingly random places. I once watched a DVD that had a
1921 progressive first half, and the second half was telecined. If you
1922 want to be <emphasis>really</emphasis> thorough, you can scan the
1923 entire movie:
1924 <screen>mplayer dvd://1 -nosound -vo null -benchmark</screen>
1925 Using <option>-benchmark</option> makes
1926 <application>MPlayer</application> play the movie as quickly as it
1927 possibly can; still, depending on your hardware, it can take a
1928 while. Every time demux_mpg reports a framerate change, the line
1929 immediately above will show you the time at which the change
1930 occurred.
1931 </para>
1932
1933 <para>
1934 Sometimes progressive video on DVDs is referred to as
1935 "soft-telecine" because it is intended to
1936 be telecined by the DVD player.
1937 </para>
1938 </sect3>
1939
1940
1941 <sect3 id="menc-feat-telecine-ident-telecined">
1942 <title>Telecined</title>
1943
1944 <para>
1945 Telecined video was originally filmed at 24000/1001, but was telecined
1946 <emphasis>before</emphasis> it was written to the DVD.
1947 </para>
1948
1949 <para>
1950 <application>MPlayer</application> does not (ever) report any
1951 framerate changes when it plays telecined video.
1952 </para>
1953
1954 <para>
1955 Watching a telecined video, you will see interlacing artifacts that
1956 seem to "blink": they repeatedly appear and disappear.
1957 You can look closely at this by
1958 <orderedlist>
1959 <listitem><screen>mplayer dvd://1</screen></listitem>
1960 <listitem><para>
1961 Seek to a part with motion.
1962 </para></listitem>
1963 <listitem><para>
1964 Use the <keycap>.</keycap> key to step forward one frame at a time.
1965 </para></listitem>
1966 <listitem><para>
1967 Look at the pattern of interlaced-looking and progressive-looking
1968 frames. If the pattern you see is PPPII,PPPII,PPPII,... then the
1969 video is telecined. If you see some other pattern, then the video
1970 may have been telecined using some non-standard method;
1971 <application>MEncoder</application> cannot losslessly convert
1972 non-standard telecine to progressive. If you do not see any
1973 pattern at all, then it is most likely interlaced.
1974 </para></listitem>
1975 </orderedlist>
1976 </para>
1977
1978 <para>
1979 Sometimes telecined video on DVDs is referred to as
1980 "hard-telecine". Since hard-telecine is already 60000/1001 fields
1981 per second, the DVD player plays the video without any manipulation.
1982 </para>
1983
1984 <para>
1985 Another way to tell if your source is telecined or not is to play
1986 the source with the <option>-vf pullup</option> and <option>-v</option>
1987 command line options to see how <option>pullup</option> matches frames.
1988 If the source is telecined, you should see on the console a 3:2 pattern
1989 with <systemitem>0+.1.+2</systemitem> and <systemitem>0++1</systemitem>
1990 alternating.
1991 This technique has the advantage that you do not need to watch the
1992 source to identify it, which could be useful if you wish to automate
1993 the encoding procedure, or to carry out said procedure remotely via
1994 a slow connection.
1995 </para>
1996 </sect3>
1997
1998
1999 <sect3 id="menc-feat-telecine-ident-interlaced">
2000 <title>Interlaced</title>
2001
2002 <para>
2003 Interlaced video was originally filmed at 60000/1001 fields per second,
2004 and stored on the DVD as 30000/1001 frames per second. The interlacing effect
2005 (often called "combing") is a result of combining pairs of
2006 fields into frames. Each field is supposed to be 1/(60000/1001) seconds apart,
2007 and when they are displayed simultaneously the difference is apparent.
2008 </para>
2009
2010 <para>
2011 As with telecined video, <application>MPlayer</application> should
2012 not ever report any framerate changes when playing interlaced content.
2013 </para>
2014
2015 <para>
2016 When you view an interlaced video closely by frame-stepping with the
2017 <keycap>.</keycap> key, you will see that every single frame is interlaced.
2018 </para>
2019 </sect3>
2020
2021
2022 <sect3 id="menc-feat-telecine-ident-mixedpt">
2023 <title>Mixed progressive and telecine</title>
2024
2025 <para>
2026 All of a "mixed progressive and telecine" video was originally
2027 24000/1001 frames per second, but some parts of it ended up being telecined.
2028 </para>
2029
2030 <para>
2031 When <application>MPlayer</application> plays this category, it will
2032 (often repeatedly) switch back and forth between "30000/1001 fps NTSC"
2033 and "24000/1001 fps progressive NTSC". Watch the bottom of
2034 <application>MPlayer</application>'s output to see these messages.
2035 </para>
2036
2037 <para>
2038 You should check the "30000/1001 fps NTSC" sections to make sure
2039 they are actually telecine, and not just interlaced.
2040 </para>
2041 </sect3>
2042
2043
2044 <sect3 id="menc-feat-telecine-ident-mixedpi">
2045 <title>Mixed progressive and interlaced</title>
2046
2047 <para>
2048 In "mixed progressive and interlaced" content, progressive
2049 and interlaced video have been spliced together.
2050 </para>
2051
2052 <para>
2053 This category looks just like "mixed progressive and telecine",
2054 until you examine the 30000/1001 fps sections and see that they do not have the
2055 telecine pattern.
2056 </para>
2057 </sect3>
2058 </sect2>
2059
2060 <!-- ********** -->
2061
2062 <sect2 id="menc-feat-telecine-encode">
2063 <title>How to encode each category</title>
2064 <para>
2065 As I mentioned in the beginning, example <application>MEncoder</application>
2066 lines below are <emphasis role="bold">not</emphasis> meant to actually be used;
2067 they only demonstrate the minimum parameters to properly encode each category.
2068 </para>
2069
2070
2071 <sect3 id="menc-feat-telecine-encode-progressive">
2072 <title>Progressive</title>
2073 <para>
2074 Progressive video requires no special filtering to encode. The only
2075 parameter you need to be sure to use is <option>-ofps 24000/1001</option>.
2076 Otherwise, <application>MEncoder</application>
2077 will try to encode at 30000/1001 fps and will duplicate frames.
2078 </para>
2079
2080 <para>
2081 <screen>mencoder dvd://1 -oac copy -ovc lavc -ofps 24000/1001</screen>
2082 </para>
2083
2084 <para>
2085 It is often the case, however, that a video that looks progressive
2086 actually has very short parts of telecine mixed in. Unless you are
2087 sure, it is safest to treat the video as
2088 <link linkend="menc-feat-telecine-encode-mixedpt">mixed progressive and telecine</link>.
2089 The performance loss is small
2090 <link linkend="menc-feat-telecine-footnotes">[3]</link>.
2091 </para>
2092 </sect3>
2093
2094
2095 <sect3 id="menc-feat-telecine-encode-telecined">
2096 <title>Telecined</title>
2097
2098 <para>
2099 Telecine can be reversed to retrieve the original 24000/1001 content,
2100 using a process called inverse-telecine.
2101 <application>MPlayer</application> contains several filters to
2102 accomplish this; the best filter, <option>pullup</option>, is described
2103 in the <link linkend="menc-feat-telecine-encode-mixedpt">mixed
2104 progressive and telecine</link> section.
2105 </para>
2106 </sect3>
2107
2108
2109 <sect3 id="menc-feat-telecine-encode-interlaced">
2110 <title>Interlaced</title>
2111
2112 <para>
2113 For most practical cases it is not possible to retrieve a complete
2114 progressive video from interlaced content. The only way to do so
2115 without losing half of the vertical resolution is to double the
2116 framerate and try to "guess" what ought to make up the
2117 corresponding lines for each field (this has drawbacks - see method 3).
2118 </para>
2119
2120 <orderedlist>
2121 <listitem><para>
2122 Encode the video in interlaced form. Normally, interlacing wreaks
2123 havoc with the encoder's ability to compress well, but
2124 <systemitem class="library">libavcodec</systemitem> has two
2125 parameters specifically for dealing with storing interlaced video a
2126 bit better: <option> ildct</option> and <option>ilme</option>. Also,
2127 using <option>mbd=2</option> is strongly recommended
2128 <link linkend="menc-feat-telecine-footnotes">[2] </link> because it
2129 will encode macroblocks as non-interlaced in places where there is
2130 no motion. Note that <option>-ofps</option> is NOT needed here.
2131 <screen>mencoder dvd://1 -oac copy -ovc lavc -lavcopts ildct:ilme:mbd=2</screen>
2132 </para></listitem>
2133 <listitem><para>
2134 Use a deinterlacing filter before encoding. There are several of
2135 these filters available to choose from, each with its own advantages
2136 and disadvantages. Consult <option>mplayer -pphelp</option> and
2137 <option>mplayer -vf help</option> to see what is available
2138 (grep for "deint"), read Michael's Niedermayer
2139 <ulink url="http://guru.multimedia.cx/deinterlacing-filters/">Deinterlacing filters comparison</ulink>,
2140 and search the
2141 <ulink url="http://www.mplayerhq.hu/design7/mailing_lists.html">
2142 MPlayer mailing lists</ulink> to find many discussions about the
2143 various filters.
2144 Again, the framerate is not changing, so no
2145 <option>-ofps</option>. Also, deinterlacing should be done after
2146 cropping <link linkend="menc-feat-telecine-footnotes">[1]</link> and
2147 before scaling.
2148 <screen>mencoder dvd://1 -oac copy -vf yadif -ovc lavc</screen>
2149 </para></listitem>
2150 <listitem><para>
2151 Unfortunately, this option is buggy with
2152 <application>MEncoder</application>; it ought to work well with
2153 <application>MEncoder G2</application>, but that is not here yet. You
2154 might experience crahes. Anyway, the purpose of <option> -vf
2155 tfields</option> is to create a full frame out of each field, which
2156 makes the framerate 60000/1001. The advantage of this approach is that no
2157 data is ever lost; however, since each frame comes from only one
2158 field, the missing lines have to be interpolated somehow. There are
2159 no very good methods of generating the missing data, and so the
2160 result will look a bit similar to when using some deinterlacing
2161 filters. Generating the missing lines creates other issues, as well,
2162 simply because the amount of data doubles. So, higher encoding
2163 bitrates are required to maintain quality, and more CPU power is
2164 used for both encoding and decoding. tfields has several different
2165 options for how to create the missing lines of each frame. If you
2166 use this method, then Reference the manual, and chose whichever
2167 option looks best for your material. Note that when using
2168 <option>tfields</option> you
2169 <emphasis role="bold">have to</emphasis> specify both
2170 <option>-fps</option> and <option>-ofps</option> to be twice the
2171 framerate of your original source.
2172 <screen>
2173 mencoder dvd://1 -oac copy -vf tfields=2 -ovc lavc \
2174 -fps 60000/1001 -ofps 60000/1001<!--
2175 --></screen>
2176 </para></listitem>
2177 <listitem><para>
2178 If you plan on downscaling dramatically, you can extract and encode
2179 only one of the two fields. Of course, you will lose half the vertical
2180 resolution, but if you plan on downscaling to at most 1/2 of the
2181 original, the loss will not matter much. The result will be a
2182 progressive 30000/1001 frames per second file. The procedure is to use
2183 <option>-vf field</option>, then crop
2184 <link linkend="menc-feat-telecine-footnotes">[1]</link> and scale
2185 appropriately. Remember that you will have to adjust the scale to
2186 compensate for the vertical resolution being halved.
2187 <screen>mencoder dvd://1 -oac copy -vf field=0 -ovc lavc</screen>
2188 </para></listitem>
2189 </orderedlist>
2190 </sect3>
2191
2192
2193 <sect3 id="menc-feat-telecine-encode-mixedpt">
2194 <title>Mixed progressive and telecine</title>
2195
2196 <para>
2197 In order to turn mixed progressive and telecine video into entirely
2198 progressive video, the telecined parts have to be
2199 inverse-telecined. There are three ways to accomplish this,
2200 described below. Note that you should
2201 <emphasis role="bold">always</emphasis> inverse-telecine before any
2202 rescaling; unless you really know what you are doing,
2203 inverse-telecine before cropping, too
2204 <link linkend="menc-feat-telecine-footnotes">[1]</link>.
2205 <option>-ofps 24000/1001</option> is needed here because the output video
2206 will be 24000/1001 frames per second.
2207 </para>
2208
2209 <itemizedlist>
2210 <listitem><para>
2211 <option>-vf pullup</option> is designed to inverse-telecine
2212 telecined material while leaving progressive data alone. In order to
2213 work properly, <option>pullup</option> <emphasis role="bold">must</emphasis>
2214 be followed by the <option>softskip</option> filter or
2215 else <application>MEncoder</application> will crash.
2216 <option>pullup</option> is, however, the cleanest and most
2217 accurate method available for encoding both telecine and
2218 "mixed progressive and telecine".
2219 <screen>
2220 mencoder dvd://1 -oac copy -vf pullup,softskip
2221 -ovc lavc -ofps 24000/1001<!--
2222 --></screen>
2223 </para></listitem>
2224 <listitem><para>
2225 An older method
2226 is to, rather than inverse-telecine the telecined parts, telecine
2227 the non-telecined parts and then inverse-telecine the whole
2228 video. Sound confusing? softpulldown is a filter that goes through
2229 a video and makes the entire file telecined. If we follow
2230 softpulldown with either <option>detc</option> or
2231 <option>ivtc</option>, the final result will be entirely
2232 progressive. <option>-ofps 24000/1001</option> is needed.
2233 <screen>
2234 mencoder dvd://1 -oac copy -vf softpulldown,ivtc=1 -ovc lavc -ofps 24000/1001
2235 </screen>
2236 </para></listitem>
2237
2238 <listitem><para>
2239 I have not used <option>-vf filmdint</option> myself, but here is what
2240 D Richard Felker III has to say:
2241
2242 <blockquote><para>It is OK, but IMO it tries to deinterlace rather
2243 than doing inverse telecine too often (much like settop DVD
2244 players &amp; progressive TVs) which gives ugly flickering and
2245 other artifacts. If you are going to use it, you at least need to
2246 spend some time tuning the options and watching the output first
2247 to make sure it is not messing up.
2248 </para></blockquote>
2249 </para></listitem>
2250 </itemizedlist>
2251 </sect3>
2252
2253
2254 <sect3 id="menc-feat-telecine-encode-mixedpi">
2255 <title>Mixed progressive and interlaced</title>
2256
2257 <para>
2258 There are two options for dealing with this category, each of
2259 which is a compromise. You should decide based on the
2260 duration/location of each type.
2261 </para>
2262
2263 <itemizedlist>
2264 <listitem>
2265 <para>
2266 Treat it as progressive. The interlaced parts will look interlaced,
2267 and some of the interlaced fields will have to be dropped, resulting
2268 in a bit of uneven jumpiness. You can use a postprocessing filter if
2269 you want to, but it may slightly degrade the progressive parts.
2270 </para>
2271
2272 <para>
2273 This option should definitely not be used if you want to eventually
2274 display the video on an interlaced device (with a TV card, for
2275 example). If you have interlaced frames in a 24000/1001 frames per
2276 second video, they will be telecined along with the progressive
2277 frames. Half of the interlaced "frames" will be displayed for three
2278 fields' duration (3/(60000/1001) seconds), resulting in a flicking
2279 "jump back in time" effect that looks quite bad. If you
2280 even attempt this, you <emphasis role="bold">must</emphasis> use a
2281 deinterlacing filter like <option>lb</option> or
2282 <option>l5</option>.
2283 </para>
2284
2285 <para>
2286 It may also be a bad idea for progressive display, too. It will drop
2287 pairs of consecutive interlaced fields, resulting in a discontinuity
2288 that can be more visible than with the second method, which shows
2289 some progressive frames twice. 30000/1001 frames per second interlaced
2290 video is already a bit choppy because it really should be shown at
2291 60000/1001 fields per second, so the duplicate frames do not stand out as
2292 much.
2293 </para>
2294
2295 <para>
2296 Either way, it is best to consider your content and how you intend to
2297 display it. If your video is 90% progressive and you never intend to
2298 show it on a TV, you should favor a progressive approach. If it is
2299 only half progressive, you probably want to encode it as if it is all
2300 interlaced.
2301 </para>
2302 </listitem>
2303
2304 <listitem><para>
2305 Treat it as interlaced. Some frames of the progressive parts will
2306 need to be duplicated, resulting in uneven jumpiness. Again,
2307 deinterlacing filters may slightly degrade the progressive parts.
2308 </para></listitem>
2309 </itemizedlist>
2310 </sect3>
2311 </sect2>
2312
2313 <!-- ********** -->
2314
2315 <sect2 id="menc-feat-telecine-footnotes">
2316 <title>Footnotes</title>
2317
2318 <orderedlist>
2319 <listitem>
2320 <formalpara>
2321 <title>About cropping:</title>
2322 <para>
2323 Video data on DVDs are stored in a format called YUV 4:2:0. In YUV
2324 video, luma ("brightness") and chroma ("color")
2325 are stored separately. Because the human eye is somewhat less
2326 sensitive to color than it is to brightness, in a YUV 4:2:0 picture
2327 there is only one chroma pixel for every four luma pixels. In a
2328 progressive picture, each square of four luma pixels (two on each
2329 side) has one common chroma pixel. You must crop progressive YUV
2330 4:2:0 to even resolutions, and use even offsets. For example,
2331 <option>crop=716:380:2:26</option> is OK but
2332 <option>crop=716:380:3:26 </option> is not.
2333 </para>
2334 </formalpara>
2335
2336 <para>
2337 When you are dealing with interlaced YUV 4:2:0, the situation is a
2338 bit more complicated. Instead of every four luma pixels in the
2339 <emphasis>frame</emphasis> sharing a chroma pixel, every four luma
2340 pixels in each <emphasis> field</emphasis> share a chroma
2341 pixel. When fields are interlaced to form a frame, each scanline is
2342 one pixel high. Now, instead of all four luma pixels being in a
2343 square, there are two pixels side-by-side, and the other two pixels
2344 are side-by-side two scanlines down. The two luma pixels in the
2345 intermediate scanline are from the other field, and so share a
2346 different chroma pixel with two luma pixels two scanlines away. All
2347 this confusion makes it necessary to have vertical crop dimensions
2348 and offsets be multiples of four. Horizontal can stay even.
2349 </para>
2350
2351 <para>
2352 For telecined video, I recommend that cropping take place after
2353 inverse telecining. Once the video is progressive you only need to
2354 crop by even numbers. If you really want to gain the slight speedup
2355 that cropping first may offer, you must crop vertically by multiples
2356 of four or else the inverse-telecine filter will not have proper data.
2357 </para>
2358
2359 <para>
2360 For interlaced (not telecined) video, you must always crop
2361 vertically by multiples of four unless you use <option>-vf
2362 field</option> before cropping.
2363 </para>
2364 </listitem>
2365
2366 <listitem><formalpara>
2367 <title>About encoding parameters and quality:</title>
2368 <para>
2369 Just because I recommend <option>mbd=2</option> here does not mean it
2370 should not be used elsewhere. Along with <option>trell</option>,
2371 <option>mbd=2</option> is one of the two
2372 <systemitem class="library">libavcodec</systemitem> options that
2373 increases quality the most, and you should always use at least those
2374 two unless the drop in encoding speed is prohibitive (e.g. realtime
2375 encoding). There are many other options to
2376 <systemitem class="library">libavcodec</systemitem> that increase
2377 encoding quality (and decrease encoding speed) but that is beyond
2378 the scope of this document.
2379 </para>
2380 </formalpara></listitem>
2381
2382 <listitem><formalpara>
2383 <title>About the performance of pullup:</title>
2384 <para>
2385 It is safe to use <option>pullup</option> (along with <option>softskip
2386 </option>) on progressive video, and is usually a good idea unless
2387 the source has been definitively verified to be entirely progressive.
2388 The performace loss is small for most cases. On a bare-minimum encode,
2389 <option>pullup</option> causes <application>MEncoder</application> to
2390 be 50% slower. Adding sound processing and advanced <option>lavcopts
2391 </option> overshadows that difference, bringing the performance
2392 decrease of using <option>pullup</option> down to 2%.
2393 </para>
2394 </formalpara></listitem>
2395 </orderedlist>
2396 </sect2>
2397 </sect1>
2398
2399
2400 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
2401
2402
2403 <sect1 id="menc-feat-enc-libavcodec">
2404 <title>Encoding with the <systemitem class="library">libavcodec</systemitem>
2405 codec family</title>
2406
2407 <para>
2408 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
2409 provides simple encoding to a lot of interesting video and audio formats.
2410 You can encode to the following codecs (more or less up to date):
2411 </para>
2412
2413 <!-- ********** -->
2414
2415 <sect2 id="menc-feat-enc-libavcodec-video-codecs">
2416 <title><systemitem class="library">libavcodec</systemitem>'s
2417 video codecs</title>
2418
2419 <para>
2420 <informaltable frame="all">
2421 <tgroup cols="2">
2422 <thead>
2423 <row><entry>Video codec name</entry><entry>Description</entry></row>
2424 </thead>
2425 <tbody>
2426 <row>
2427 <entry>mjpeg</entry>
2428 <entry>Motion JPEG</entry>
2429 </row>
2430 <row>
2431 <entry>ljpeg</entry>
2432 <entry>lossless JPEG</entry>
2433 </row>
2434 <row>
2435 <entry>jpegls</entry>
2436 <entry>JPEG LS</entry>
2437 </row>
2438 <row>
2439 <entry>targa</entry>
2440 <entry>Targa image</entry>
2441 </row>
2442 <row>
2443 <entry>gif</entry>
2444 <entry>GIF image</entry>
2445 </row>
2446 <row>
2447 <entry>bmp</entry>
2448 <entry>BMP image</entry>
2449 </row>
2450 <row>
2451 <entry>png</entry>
2452 <entry>PNG image</entry>
2453 </row>
2454 <row>
2455 <entry>h261</entry>
2456 <entry>H.261</entry>
2457 </row>
2458 <row>
2459 <entry>h263</entry>
2460 <entry>H.263 </entry>
2461 </row>
2462 <row>
2463 <entry>h263p</entry>
2464 <entry>H.263+</entry>
2465 </row>
2466 <row>
2467 <entry>mpeg4</entry>
2468 <entry>ISO standard MPEG-4 (DivX, Xvid compatible)</entry>
2469 </row>
2470 <row>
2471 <entry>msmpeg4</entry>
2472 <entry>pre-standard MPEG-4 variant by MS, v3 (AKA DivX3)</entry>
2473 </row>
2474 <row>
2475 <entry>msmpeg4v2</entry>
2476 <entry>pre-standard MPEG-4 by MS, v2 (used in old ASF files)</entry>
2477 </row>
2478 <row>
2479 <entry>wmv1</entry>
2480 <entry>Windows Media Video, version 1 (AKA WMV7)</entry>
2481 </row>
2482 <row>
2483 <entry>wmv2</entry>
2484 <entry>Windows Media Video, version 2 (AKA WMV8)</entry>
2485 </row>
2486 <row>
2487 <entry>rv10</entry>
2488 <entry>RealVideo 1.0</entry>
2489 </row>
2490 <row>
2491 <entry>rv20</entry>
2492 <entry>RealVideo 2.0</entry>
2493 </row>
2494 <row>
2495 <entry>mpeg1video</entry>
2496 <entry>MPEG-1 video</entry>
2497 </row>
2498 <row>
2499 <entry>mpeg2video</entry>
2500 <entry>MPEG-2 video</entry>
2501 </row>
2502 <row>
2503 <entry>huffyuv</entry>
2504 <entry>lossless compression</entry>
2505 </row>
2506 <row>
2507 <entry>ffvhuff</entry>
2508 <entry>FFmpeg modified huffyuv lossless</entry>
2509 </row>
2510 <row>
2511 <entry>asv1</entry>
2512 <entry>ASUS Video v1</entry>
2513 </row>
2514 <row>
2515 <entry>asv2</entry>
2516 <entry>ASUS Video v2</entry>
2517 </row>
2518 <row>
2519 <entry>ffv1</entry>
2520 <entry>FFmpeg's lossless video codec</entry>
2521 </row>
2522 <row>
2523 <entry>svq1</entry>
2524 <entry>Sorenson video 1</entry>
2525 </row>
2526 <row>
2527 <entry>flv</entry>
2528 <entry>Sorenson H.263 used in Flash Video</entry>
2529 </row>
2530 <row>
2531 <entry>flashsv</entry>
2532 <entry>Flash Screen Video</entry>
2533 </row>
2534 <row>
2535 <entry>dvvideo</entry>
2536 <entry>Sony Digital Video</entry>
2537 </row>
2538 <row>
2539 <entry>snow</entry>
2540 <entry>FFmpeg's experimental wavelet-based codec</entry>
2541 </row>
2542 <row>
2543 <entry>zbmv</entry>
2544 <entry>Zip Blocks Motion Video</entry>
2545 </row>
2546 </tbody>
2547 </tgroup>
2548 </informaltable>
2549
2550 The first column contains the codec names that should be passed after the
2551 <literal>vcodec</literal> config,
2552 like: <option>-lavcopts vcodec=msmpeg4</option>
2553 </para>
2554
2555 <informalexample><para>
2556 An example with MJPEG compression:
2557 <screen>
2558 mencoder dvd://2 -o <replaceable>title2.avi</replaceable> -ovc lavc -lavcopts vcodec=mjpeg -oac copy
2559 </screen>
2560 </para></informalexample>
2561 </sect2>
2562
2563 <!-- ********** -->
2564
2565 <sect2 id="menc-feat-enc-libavcodec-audio-codecs">
2566 <title><systemitem class="library">libavcodec</systemitem>'s
2567 audio codecs</title>
2568
2569 <para>
2570 <informaltable frame="all">
2571 <tgroup cols="2">
2572 <thead>
2573 <row><entry>Audio codec name</entry><entry>Description</entry></row>
2574 </thead>
2575 <tbody>
2576 <row>
2577 <entry>mp2</entry>
2578 <entry>MPEG Layer 2</entry>
2579 </row>
2580 <row>
2581 <entry>ac3</entry>
2582 <entry>AC-3, AKA Dolby Digital</entry>
2583 </row>
2584 <row>
2585 <entry>adpcm_ima_wav</entry>
2586 <entry>IMA adaptive PCM (4 bits per sample, 4:1 compression)</entry>
2587 </row>
2588 <row>
2589 <entry>sonic</entry>
2590 <entry>experimental FFmpeg lossy codec</entry>
2591 </row>
2592 <row>
2593 <entry>sonicls</entry>
2594 <entry>experimental FFmpeg lossless codec</entry>
2595 </row>
2596 <row>
2597 <entry>vorbis</entry>
2598 <entry>Xiph Ogg Vorbis codec</entry>
2599 </row>
2600 <row>
2601 <entry>wmav1</entry>
2602 <entry>Windows Media Audio v1 codec</entry>
2603 </row>
2604 <row>
2605 <entry>wmav2</entry>
2606 <entry>Windows Media Audio v2 codec</entry>
2607 </row>
2608 </tbody>
2609 </tgroup>
2610 </informaltable>
2611
2612 The first column contains the codec names that should be passed after the
2613 <literal>acodec</literal> option, like: <option>-lavcopts acodec=ac3</option>
2614 </para>
2615
2616 <informalexample><para>
2617 An example with AC-3 compression:
2618 <screen>
2619 mencoder dvd://2 -o <replaceable>title2.avi</replaceable> -oac lavc -lavcopts acodec=ac3 -ovc copy
2620 </screen>
2621 </para></informalexample>
2622
2623 <para>
2624 Contrary to <systemitem class="library">libavcodec</systemitem>'s video
2625 codecs, its audio codecs do not make a wise usage of the bits they are
2626 given as they lack some minimal psychoacoustic model (if at all)
2627 which most other codec implementations feature.
2628 However, note that all these audio codecs are very fast and work
2629 out-of-the-box everywhere <application>MEncoder</application> has been
2630 compiled with <systemitem class="library">libavcodec</systemitem> (which
2631 is the case most of time), and do not depend on external libraries.
2632 </para>
2633 </sect2>
2634
2635 <!-- ********** -->
2636
2637 <sect2 id="menc-feat-dvd-mpeg4-lavc-encoding-options">
2638 <title>Encoding options of libavcodec</title>
2639
2640 <para>
2641 Ideally, you would probably want to be able to just tell the encoder to switch
2642 into "high quality" mode and move on.
2643 That would probably be nice, but unfortunately hard to implement as different
2644 encoding options yield different quality results depending on the source
2645 material. That is because compression depends on the visual properties of the
2646 video in question.
2647 For example, anime and live action have very different properties and
2648 thus require different options to obtain optimum encoding.
2649 The good news is that some options should never be left out, like
2650 <option>mbd=2</option>, <option>trell</option>, and <option>v4mv</option>.
2651 See below for a detailed description of common encoding options.
2652 </para>
2653
2654 <itemizedlist>
2655 <title>Options to adjust:</title>
2656 <listitem><para>
2657 <emphasis role="bold">vmax_b_frames</emphasis>: 1 or 2 is good, depending on
2658 the movie.
2659 Note that if you need to have your encode be decodable by DivX5, you
2660 need to activate closed GOP support, using
2661 <systemitem class="library">libavcodec</systemitem>'s <option>cgop</option>
2662 option, but you need to deactivate scene detection, which
2663 is not a good idea as it will hurt encode efficiency a bit.
2664 </para></listitem>
2665 <listitem><para>
2666 <emphasis role="bold">vb_strategy=1</emphasis>: helps in high-motion scenes.
2667 On some videos, vmax_b_frames may hurt quality, but vmax_b_frames=2 along
2668 with vb_strategy=1 helps.
2669 </para></listitem>
2670 <listitem><para>
2671 <emphasis role="bold">dia</emphasis>: motion search range. Bigger is better
2672 and slower.
2673 Negative values are a completely different scale.
2674 Good values are -1 for a fast encode, or 2-4 for slower.
2675 </para></listitem>
2676 <listitem><para>
2677 <emphasis role="bold">predia</emphasis>: motion search pre-pass.
2678 Not as important as dia. Good values are 1 (default) to 4. Requires preme=2
2679 to really be useful.
2680 </para></listitem>
2681 <listitem><para>
2682 <emphasis role="bold">cmp, subcmp, precmp</emphasis>: Comparison function for
2683 motion estimation.
2684 Experiment with values of 0 (default), 2 (hadamard), 3 (dct), and 6 (rate
2685 distortion).
2686 0 is fastest, and sufficient for precmp.
2687 For cmp and subcmp, 2 is good for anime, and 3 is good for live action.
2688 6 may or may not be slightly better, but is slow.
2689 </para></listitem>
2690 <listitem><para>
2691 <emphasis role="bold">last_pred</emphasis>: Number of motion predictors to
2692 take from the previous frame.
2693 1-3 or so help at little speed cost.
2694 Higher values are slow for no extra gain.
2695 </para></listitem>
2696 <listitem><para>
2697 <emphasis role="bold">cbp, mv0</emphasis>: Controls the selection of
2698 macroblocks. Small speed cost for small quality gain.
2699 </para></listitem>
2700 <listitem><para>
2701 <emphasis role="bold">qprd</emphasis>: adaptive quantization based on the
2702 macroblock's complexity.
2703 May help or hurt depending on the video and other options.
2704 This can cause artifacts unless you set vqmax to some reasonably small value
2705 (6 is good, maybe as low as 4); vqmin=1 should also help.
2706 </para></listitem>
2707 <listitem><para>
2708 <emphasis role="bold">qns</emphasis>: very slow, especially when combined
2709 with qprd.
2710 This option will make the encoder minimize noise due to compression
2711 artifacts instead of making the encoded video strictly match the source.
2712 Do not use this unless you have already tweaked everything else as far as it
2713 will go and the results still are not good enough.
2714 </para></listitem>
2715 <listitem><para>
2716 <emphasis role="bold">vqcomp</emphasis>: Tweak ratecontrol.
2717 What values are good depends on the movie.
2718 You can safely leave this alone if you want.
2719 Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts
2720 them on high-complexity scenes (default: 0.5, range: 0-1. recommended range:
2721 0.5-0.7).
2722 </para></listitem>
2723 <listitem><para>
2724 <emphasis role="bold">vlelim, vcelim</emphasis>: Sets the single coefficient
2725 elimination threshold for luminance and chroma planes.
2726 These are encoded separately in all MPEG-like algorithms.
2727 The idea behind these options is to use some good heuristics to determine
2728 when the change in a block is less than the threshold you specify, and in
2729 such a case, to just encode the block as "no change".
2730 This saves bits and perhaps speeds up encoding. vlelim=-4 and vcelim=9
2731 seem to be good for live movies, but seem not to help with anime;
2732 when encoding animation, you should probably leave them unchanged.
2733 </para></listitem>
2734 <listitem><para>
2735 <emphasis role="bold">qpel</emphasis>: Quarter pixel motion estimation.
2736 MPEG-4 uses half pixel precision for its motion search by default,
2737 therefore this option comes with an overhead as more information will be
2738 stored in the encoded file.
2739 The compression gain/loss depends on the movie, but it is usually not very
2740 effective on anime.
2741 qpel always incurs a significant cost in CPU decode time (+25% in
2742 practice).
2743 </para></listitem>
2744 <listitem><para>
2745 <emphasis role="bold">psnr</emphasis>: does not affect the actual encoding,
2746 but writes a log file giving the type/size/quality of each frame, and
2747 prints a summary of PSNR (Peak Signal to Noise Ratio) at the end.
2748 </para></listitem>
2749 </itemizedlist>
2750
2751 <itemizedlist>
2752 <title>Options not recommended to play with:</title>
2753 <listitem><para>
2754 <emphasis role="bold">vme</emphasis>: The default is best.
2755 </para></listitem>
2756 <listitem><para>
2757 <emphasis role="bold">lumi_mask, dark_mask</emphasis>: Psychovisual adaptive
2758 quantization.
2759 You do not want to play with those options if you care about quality.
2760 Reasonable values may be effective in your case, but be warned this is very
2761 subjective.
2762 </para></listitem>
2763 <listitem><para>
2764 <emphasis role="bold">scplx_mask</emphasis>: Tries to prevent blocky
2765 artifacts, but postprocessing is better.
2766 </para></listitem>
2767 </itemizedlist>
2768 </sect2>
2769
2770 <!-- ********** -->
2771
2772 <sect2 id="menc-feat-mpeg4-lavc-example-settings">
2773 <title>Encoding setting examples</title>
2774
2775 <para>
2776 The following settings are examples of different encoding
2777 option combinations that affect the speed vs quality tradeoff
2778 at the same target bitrate.
2779 </para>
2780
2781 <para>
2782 All the encoding settings were tested on a 720x448 @30000/1001 fps
2783 video sample, the target bitrate was 900kbps, and the machine was an
2784 AMD-64 3400+ at 2400 MHz in 64 bits mode.
2785 Each encoding setting features the measured encoding speed (in
2786 frames per second) and the PSNR loss (in dB) compared to the "very
2787 high quality" setting.
2788 Please understand that depending on your source, your machine type
2789 and development advancements, you may get very different results.
2790 </para>
2791
2792 <para>
2793 <informaltable frame="all">
2794 <tgroup cols="4">
2795 <thead>
2796 <row>
2797 <entry>Description</entry>
2798 <entry>Encoding options</entry>
2799 <entry>speed (in fps)</entry>
2800 <entry>Relative PSNR loss (in dB)</entry>
2801 </row>
2802 </thead>
2803 <tbody>
2804 <row>
2805 <entry>Very high quality</entry>
2806 <entry><option>vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2</option></entry>
2807 <entry>6fps</entry>
2808 <entry>0dB</entry>
2809 </row>
2810 <row>
2811 <entry>High quality</entry>
2812 <entry><option>vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo</option></entry>
2813 <entry>15fps</entry>
2814 <entry>-0.5dB</entry>
2815 </row>
2816 <row>
2817 <entry>Fast</entry>
2818 <entry><option>vcodec=mpeg4:mbd=2:trell:v4mv:turbo</option></entry>
2819 <entry>42fps</entry>
2820 <entry>-0.74dB</entry>
2821 </row>
2822 <row>
2823 <entry>Realtime</entry>
2824 <entry><option>vcodec=mpeg4:mbd=2:turbo</option></entry>
2825 <entry>54fps</entry>
2826 <entry>-1.21dB</entry>
2827 </row>
2828 </tbody>
2829 </tgroup>
2830 </informaltable>
2831 </para>
2832 </sect2>
2833
2834 <!-- ********** -->
2835
2836 <sect2 id="custommatrices">
2837 <title>Custom inter/intra matrices</title>
2838
2839 <para>
2840 With this feature of
2841 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
2842 you are able to set custom inter (I-frames/keyframes) and intra
2843 (P-frames/predicted frames) matrices. It is supported by many of the codecs:
2844 <systemitem>mpeg1video</systemitem> and <systemitem>mpeg2video</systemitem>
2845 are reported as working.
2846 </para>
2847
2848 <para>
2849 A typical usage of this feature is to set the matrices preferred by the
2850 <ulink url="http://www.kvcd.net/">KVCD</ulink> specifications.
2851 </para>
2852
2853 <para>
2854 The <emphasis role="bold">KVCD "Notch" Quantization Matrix:</emphasis>
2855 </para>
2856
2857 <para>
2858 Intra:
2859 <screen>
2860 8 9 12 22 26 27 29 34
2861 9 10 14 26 27 29 34 37
2862 12 14 18 27 29 34 37 38
2863 22 26 27 31 36 37 38 40
2864 26 27 29 36 39 38 40 48
2865 27 29 34 37 38 40 48 58
2866 29 34 37 38 40 48 58 69
2867 34 37 38 40 48 58 69 79
2868 </screen>
2869
2870 Inter:
2871 <screen>
2872 16 18 20 22 24 26 28 30
2873 18 20 22 24 26 28 30 32
2874 20 22 24 26 28 30 32 34
2875 22 24 26 30 32 32 34 36
2876 24 26 28 32 34 34 36 38
2877 26 28 30 32 34 36 38 40
2878 28 30 32 34 36 38 42 42
2879 30 32 34 36 38 40 42 44
2880 </screen>
2881 </para>
2882
2883 <para>
2884 Usage:
2885 <screen>
2886 mencoder <replaceable>input.avi</replaceable> -o <replaceable>output.avi</replaceable> -oac copy -ovc lavc \
2887 -lavcopts inter_matrix=...:intra_matrix=...
2888 </screen>
2889 </para>
2890
2891 <para>
2892 <screen>
2893 mencoder <replaceable>input.avi</replaceable> -ovc lavc -lavcopts \
2894 vcodec=mpeg2video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,\
2895 12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,\
2896 29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79\
2897 :inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,\
2898 28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,\
2899 36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -oac copy -o svcd.mpg
2900 </screen>
2901 </para>
2902 </sect2>
2903
2904 <!-- ********** -->
2905
2906 <sect2 id="menc-feat-dvd-mpeg4-example">
2907 <title>Example</title>
2908
2909 <para>
2910 So, you have just bought your shiny new copy of Harry Potter and the Chamber
2911 of Secrets (widescreen edition, of course), and you want to rip this DVD
2912 so that you can add it to your Home Theatre PC. This is a region 1 DVD,
2913 so it is NTSC. The example below will still apply to PAL, except you will
2914 omit <option>-ofps 24000/1001</option> (because the output framerate is the
2915 same as the input framerate), and of course the crop dimensions will be
2916 different.
2917 </para>
2918
2919 <para>
2920 After running <option>mplayer dvd://1</option>, we follow the process
2921 detailed in the section <link linkend="menc-feat-telecine">How to deal
2922 with telecine and interlacing in NTSC DVDs</link> and discover that it is
2923 24000/1001 fps progressive video, which means that we need not use an inverse
2924 telecine filter, such as <option>pullup</option> or
2925 <option>filmdint</option>.
2926 </para>
2927
2928 <para id="menc-feat-dvd-mpeg4-example-crop">
2929 Next, we want to determine the appropriate crop rectangle, so we use the
2930 cropdetect filter:
2931 <screen>mplayer dvd://1 -vf cropdetect</screen>
2932 Make sure you seek to a fully filled frame (such as a bright scene,
2933 past the opening credits and logos), and
2934 you will see in <application>MPlayer</application>'s console output:
2935 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen>
2936 We then play the movie back with this filter to test its correctness:
2937 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen>
2938 And we see that it looks perfectly fine. Next, we ensure the width and
2939 height are a multiple of 16. The width is fine, however the height is
2940 not. Since we did not fail 7th grade math, we know that the nearest
2941 multiple of 16 lower than 362 is 352.
2942 </para>
2943
2944 <para>
2945 We could just use <option>crop=720:352:0:58</option>, but it would be nice
2946 to take a little off the top and a little off the bottom so that we
2947 retain the center. We have shrunk the height by 10 pixels, but we do not
2948 want to increase the y-offset by 5-pixels since that is an odd number and
2949 will adversely affect quality. Instead, we will increase the y-offset by
2950 4 pixels:
2951 <screen>mplayer dvd://1 -vf crop=720:352:0:62</screen>
2952 Another reason to shave pixels from both the top and the bottom is that we
2953 ensure we have eliminated any half-black pixels if they exist. Note that if
2954 your video is telecined, make sure the <option>pullup</option> filter (or
2955 whichever inverse telecine filter you decide to use) appears in the filter
2956 chain before you crop. If it is interlaced, deinterlace before cropping.
2957 (If you choose to preserve the interlaced video, then make sure your
2958 vertical crop offset is a multiple of 4.)
2959 </para>
2960
2961 <para>
2962 If you are really concerned about losing those 10 pixels, you might
2963 prefer instead to scale the dimensions down to the nearest multiple of 16.
2964 The filter chain would look like:
2965 <screen>-vf crop=720:362:0:58,scale=720:352</screen>
2966 Scaling the video down like this will mean that some small amount of
2967 detail is lost, though it probably will not be perceptible. Scaling up will
2968 result in lower quality (unless you increase the bitrate). Cropping
2969 discards those pixels altogether. It is a tradeoff that you will want to
2970 consider for each circumstance. For example, if the DVD video was made
2971 for television, you might want to avoid vertical scaling, since the line
2972 sampling corresponds to the way the content was originally recorded.
2973 </para>
2974
2975 <para>
2976 On inspection, we see that our movie has a fair bit of action and high
2977 amounts of detail, so we pick 2400Kbit for our bitrate.
2978 </para>
2979
2980 <para>
2981 We are now ready to do the two pass encode. Pass one:
2982 <screen>
2983 mencoder dvd://1 -ofps 24000/1001 -oac copy -o <replaceable>Harry_Potter_2.avi</replaceable> -ovc lavc \
2984 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:autoaspect:vpass=1 \
2985 -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2
2986 </screen>
2987 And pass two is the same, except that we specify <option>vpass=2</option>:
2988 <screen>
2989 mencoder dvd://1 -ofps 24000/1001 -oac copy -o <replaceable>Harry_Potter_2.avi</replaceable> -ovc lavc \
2990 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:autoaspect:vpass=2 \
2991 -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2
2992 </screen>
2993 </para>
2994
2995 <para>
2996 The options <option>v4mv:mbd=2:trell</option> will greatly increase the
2997 quality at the expense of encoding time. There is little reason to leave
2998 these options out when the primary goal is quality. The options
2999 <option>cmp=3:subcmp=3</option> select a comparison function that
3000 yields higher quality than the defaults. You might try experimenting with
3001 this parameter (refer to the man page for the possible values) as
3002 different functions can have a large impact on quality depending on the
3003 source material. For example, if you find
3004 <systemitem class="library">libavcodec</systemitem> produces too much
3005 blocky artifacting, you could try selecting the experimental NSSE as
3006 comparison function via <option>*cmp=10</option>.
3007 </para>
3008
3009 <para>
3010 For this movie, the resulting AVI will be 138 minutes long and nearly
3011 3GB. And because you said that file size does not matter, this is a
3012 perfectly acceptable size. However, if you had wanted it smaller, you
3013 could try a lower bitrate. Increasing bitrates have diminishing
3014 returns, so while we might clearly see an improvement from 1800Kbit to
3015 2000Kbit, it might not be so noticeable above 2000Kbit. Feel
3016 free to experiment until you are happy.
3017 </para>
3018
3019 <para>
3020 Because we passed the source video through a denoise filter, you may want
3021 to add some of it back during playback. This, along with the
3022 <option>spp</option> post-processing filter, drastically improves the
3023 perception of quality and helps eliminate blocky artifacts in the video.
3024 With <application>MPlayer</application>'s <option>autoq</option> option,
3025 you can vary the amount of post-processing done by the spp filter
3026 depending on available CPU. Also, at this point, you may want to apply
3027 gamma and/or color correction to best suit your display. For example:
3028 <screen>
3029 mplayer <replaceable>Harry_Potter_2.avi</replaceable> -vf spp,noise=9ah:5ah,eq2=1.2 -autoq 3
3030 </screen>
3031 </para>
3032 </sect2>
3033 </sect1>
3034
3035
3036 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
3037
3038
3039 <sect1 id="menc-feat-xvid">
3040 <title>Encoding with the <systemitem class="library">Xvid</systemitem>
3041 codec</title>
3042
3043 <para>
3044 <systemitem class="library">Xvid</systemitem> is a free library for
3045 encoding MPEG-4 ASP video streams.
3046 Before starting to encode, you need to <link linkend="xvid">
3047 set up <application>MEncoder</application> to support it</link>.
3048 </para>
3049
3050 <para>
3051 This guide mainly aims at featuring the same kind of information
3052 as x264's encoding guide.
3053 Therefore, please begin by reading
3054 <link linkend="menc-feat-x264-encoding-options-intro">the first part</link>
3055 of that guide.
3056 </para>
3057
3058 <!-- ********** -->
3059
3060 <sect2 id="menc-feat-xvid-intro">
3061 <title>What options should I use to get the best results?</title>
3062
3063 <para>
3064 Please begin by reviewing the
3065 <systemitem class="library">Xvid</systemitem> section of
3066 <application>MPlayer</application>'s man page.
3067 This section is intended to be a supplement to the man page.
3068 </para>
3069
3070 <para>
3071 The Xvid default settings are already a good tradeoff between
3072 speed and quality, therefore you can safely stick to them if
3073 the following section puzzles you.
3074 </para>
3075 </sect2>
3076
3077 <!-- ********** -->
3078
3079 <sect2 id="menc-feat-xvid-encoding-options">
3080 <title>Encoding options of <systemitem class="library">Xvid</systemitem></title>
3081
3082 <itemizedlist>
3083 <listitem><para>
3084 <emphasis role="bold">vhq</emphasis>
3085 This setting affects the macroblock decision algorithm, where the
3086 higher the setting, the wiser the decision.
3087 The default setting may be safely used for every encode, while
3088 higher settings always help PSNR but are significantly slower.
3089 Please note that a better PSNR does not necessarily mean
3090 that the picture will look better, but tells you that it is
3091 closer to the original.
3092 Turning it off will noticeably speed up encoding; if speed is
3093 critical for you, the tradeoff may be worth it.
3094 </para></listitem>
3095 <listitem><para>
3096 <emphasis role="bold">bvhq</emphasis>
3097 This does the same job as vhq, but does it on B-frames.
3098 It has a negligible impact on speed, and slightly improves quality
3099 (around +0.1dB PSNR).
3100 </para></listitem>
3101 <listitem><para>
3102 <emphasis role="bold">max_bframes</emphasis>
3103 A higher number of consecutive allowed B-frames usually improves
3104 compressibility, although it may also lead to more blocking artifacts.
3105 The default setting is a good tradeoff between compressibility and
3106 quality, but you may increase it up to 3 if you are bitrate-starved.
3107 You may also decrease it to 1 or 0 if you are aiming at perfect
3108 quality, though in that case you should make sure your
3109 target bitrate is high enough to ensure that the encoder does not
3110 have to increase quantizers to reach it.
3111 </para></listitem>
3112 <listitem><para>
3113 <emphasis role="bold">bf_threshold</emphasis>
3114 This controls the B-frame sensitivity of the encoder, where a higher
3115 value leads to more B-frames being used (and vice versa).
3116 This setting is to be used together with <option>max_bframes</option>;
3117 if you are bitrate-starved, you should increase both
3118 <option>max_bframes</option> and <option>bf_threshold</option>,
3119 while you may increase <option>max_bframes</option> and reduce
3120 <option>bf_threshold</option> so that the encoder may use more
3121 B-frames in places that only <emphasis role="bold">really</emphasis>
3122 need them.
3123 A low number of <option>max_bframes</option> and a high value of
3124 <option>bf_threshold</option> is probably not a wise choice as it
3125 will force the encoder to put B-frames in places that would not
3126 benefit from them, therefore reducing visual quality.
3127 However, if you need to be compatible with standalone players that
3128 only support old DivX profiles (which only supports up to 1
3129 consecutive B-frame), this would be your only way to
3130 increase compressibility through using B-frames.
3131 </para></listitem>
3132 <listitem><para>
3133 <emphasis role="bold">trellis</emphasis>
3134 Optimizes the quantization process to get an optimal tradeoff
3135 between PSNR and bitrate, which allows significant bit saving.
3136 These bits will in return be spent elsewhere on the video,
3137 raising overall visual quality.
3138 You should always leave it on as its impact on quality is huge.
3139 Even if you are looking for speed, do not disable it until you
3140 have turned down <option>vhq</option> and all other more
3141 CPU-hungry options to the minimum.
3142 </para></listitem>
3143 <listitem><para>
3144 <emphasis role="bold">hq_ac</emphasis>
3145 Activates a better coefficient cost estimation method, which slightly
3146 reduces filesize by around 0.15 to 0.19% (which corresponds to less
3147 than 0.01dB PSNR increase), while having a negligible impact on speed.
3148 It is therefore recommended to always leave it on.
3149 </para></listitem>
3150 <listitem><para>
3151 <emphasis role="bold">cartoon</emphasis>
3152 Designed to better encode cartoon content, and has no impact on
3153 speed as it just tunes the mode decision heuristics for this type
3154 of content.
3155 </para></listitem>
3156 <listitem>
3157 <para>
3158 <emphasis role="bold">me_quality</emphasis>
3159 This setting is to control the precision of the motion estimation.
3160 The higher <option>me_quality</option>, the more
3161 precise the estimation of the original motion will be, and the
3162 better the resulting clip will capture the original motion.
3163 </para>
3164 <para>
3165 The default setting is best in all cases;
3166 thus it is not recommended to turn it down unless you are
3167 really looking for speed, as all the bits saved by a good motion
3168 estimation would be spent elsewhere, raising overall quality.
3169 Therefore, do not go any lower than 5, and even that only as a last
3170 resort.
3171 </para>
3172 </listitem>
3173 <listitem><para>
3174 <emphasis role="bold">chroma_me</emphasis>
3175 Improves motion estimation by also taking the chroma (color)
3176 information into account, whereas <option>me_quality</option>
3177 alone only uses luma (grayscale).
3178 This slows down encoding by 5-10% but improves visual quality
3179 quite a bit by reducing blocking effects and reduces filesize by
3180 around 1.3%.
3181 If you are looking for speed, you should disable this option before
3182 starting to consider reducing <option>me_quality</option>.
3183 </para></listitem>
3184 <listitem><para>
3185 <emphasis role="bold">chroma_opt</emphasis>
3186 Is intended to increase chroma image quality around pure
3187 white/black edges, rather than improving compression.
3188 This can help to reduce the "red stairs" effect.
3189 </para></listitem>
3190 <listitem><para>
3191 <emphasis role="bold">lumi_mask</emphasis>
3192 Tries to give less bitrate to part of the picture that the
3193 human eye cannot see very well, which should allow the encoder
3194 to spend the saved bits on more important parts of the picture.
3195 The quality of the encode yielded by this option highly depends
3196 on personal preferences and on the type and monitor settings
3197 used to watch it (typically, it will not look as good if it is
3198 bright or if it is a TFT monitor).
3199 </para></listitem>
3200 <listitem>
3201 <para>
3202 <emphasis role="bold">qpel</emphasis>
3203 Raise the number of candidate motion vectors by increasing
3204 the precision of the motion estimation from halfpel to
3205 quarterpel.
3206 The idea is to find better motion vectors which will in return
3207 reduce bitrate (hence increasing quality).
3208 However, motion vectors with quarterpel precision require a
3209 few extra bits to code, but the candidate vectors do not always
3210 give (much) better results.
3211 Quite often, the codec still spends bits on the extra precision,
3212 but little or no extra quality is gained in return.
3213 Unfortunately, there is no way to foresee the possible gains of
3214 <option>qpel</option>, so you need to actually encode with and
3215 without it to know for sure.
3216 </para>
3217 <para>
3218 <option>qpel</option> can be almost double encoding time, and
3219 requires as much as 25% more processing power to decode.
3220 It is not supported by all standalone players.
3221 </para>
3222 </listitem>
3223 <listitem><para>
3224 <emphasis role="bold">gmc</emphasis>
3225 Tries to save bits on panning scenes by using a single motion
3226 vector for the whole frame.
3227 This almost always raises PSNR, but significantly slows down
3228 encoding (as well as decoding).
3229 Therefore, you should only use it when you have turned
3230 <option>vhq</option> to the maximum.
3231 <systemitem class="library">Xvid</systemitem>'s GMC is more
3232 sophisticated than DivX's, but is only supported by few
3233 standalone players.
3234 </para></listitem>
3235 </itemizedlist>
3236 </sect2>
3237
3238 <!-- ********** -->
3239
3240 <sect2 id="menc-feat-xvid-encoding-profiles">
3241 <title>Encoding profiles</title>
3242
3243 <para>
3244 Xvid supports encoding profiles through the <option>profile</option> option,
3245 which are used to impose restrictions on the properties of the Xvid video
3246 stream such that it will be playable on anything which supports the
3247 chosen profile.
3248 The restrictions relate to resolutions, bitrates and certain MPEG-4
3249 features.
3250 The following table shows what each profile supports.
3251 </para>
3252
3253 <informaltable>
3254 <tgroup cols="16" align="center">
3255 <colspec colnum="1" colname="col1"/>
3256 <colspec colnum="2" colname="col2"/>
3257 <colspec colnum="3" colname="col3"/>
3258 <colspec colnum="4" colname="col4"/>
3259 <colspec colnum="5" colname="col5"/>
3260 <colspec colnum="6" colname="col6"/>
3261 <colspec colnum="7" colname="col7"/>
3262 <colspec colnum="8" colname="col8"/>
3263 <colspec colnum="9" colname="col9"/>
3264 <colspec colnum="10" colname="col10"/>
3265 <colspec colnum="11" colname="col11"/>
3266 <colspec colnum="12" colname="col12"/>
3267 <colspec colnum="13" colname="col13"/>
3268 <colspec colnum="14" colname="col14"/>
3269 <colspec colnum="15" colname="col15"/>
3270 <colspec colnum="16" colname="col16"/>
3271 <colspec colnum="17" colname="col17"/>
3272 <spanspec spanname="spa2-5" namest="col2" nameend="col5"/>
3273 <spanspec spanname="spa6-11" namest="col6" nameend="col11"/>
3274 <spanspec spanname="spa12-17" namest="col12" nameend="col17"/>
3275 <tbody>
3276 <row>
3277 <entry></entry>
3278 <entry spanname="spa2-5">Simple</entry>
3279 <entry spanname="spa6-11">Advanced Simple</entry>
3280 <entry spanname="spa12-17">DivX</entry>
3281 </row>
3282 <row>
3283 <entry>Profile name</entry>
3284 <entry>0</entry>
3285 <entry>1</entry>
3286 <entry>2</entry>
3287 <entry>3</entry>
3288 <entry>0</entry>
3289 <entry>1</entry>
3290 <entry>2</entry>
3291 <entry>3</entry>
3292 <entry>4</entry>
3293 <entry>5</entry>
3294 <entry>Handheld</entry>
3295 <entry>Portable NTSC</entry>
3296 <entry>Portable PAL</entry>
3297 <entry>Home Theater NTSC</entry>
3298 <entry>Home Theater PAL</entry>
3299 <entry>HDTV</entry>
3300 </row>
3301 <row>
3302 <entry>Width [pixels]</entry>
3303 <entry>176</entry>
3304 <entry>176</entry>
3305 <entry>352</entry>
3306 <entry>352</entry>
3307 <entry>176</entry>
3308 <entry>176</entry>
3309 <entry>352</entry>
3310 <entry>352</entry>
3311 <entry>352</entry>
3312 <entry>720</entry>
3313 <entry>176</entry>
3314 <entry>352</entry>
3315 <entry>352</entry>
3316 <entry>720</entry>
3317 <entry>720</entry>
3318 <entry>1280</entry>
3319 </row>
3320 <row>
3321 <entry>Height [pixels]</entry>
3322 <entry>144</entry>
3323 <entry>144</entry>
3324 <entry>288</entry>
3325 <entry>288</entry>
3326 <entry>144</entry>
3327 <entry>144</entry>
3328 <entry>288</entry>
3329 <entry>288</entry>
3330 <entry>576</entry>
3331 <entry>576</entry>
3332 <entry>144</entry>
3333 <entry>240</entry>
3334 <entry>288</entry>
3335 <entry>480</entry>
3336 <entry>576</entry>
3337 <entry>720</entry>
3338 </row>
3339 <row>
3340 <entry>Frame rate [fps]</entry>
3341 <entry>15</entry>
3342 <entry>15</entry>
3343 <entry>15</entry>
3344 <entry>15</entry>
3345 <entry>30</entry>
3346 <entry>30</entry>
3347 <entry>15</entry>
3348 <entry>30</entry>
3349 <entry>30</entry>
3350 <entry>30</entry>
3351 <entry>15</entry>
3352 <entry>30</entry>
3353 <entry>25</entry>
3354 <entry>30</entry>
3355 <entry>25</entry>
3356 <entry>30</entry>
3357 </row>
3358 <row>
3359 <entry>Max average bitrate [kbps]</entry>
3360 <entry>64</entry>
3361 <entry>64</entry>
3362 <entry>128</entry>
3363 <entry>384</entry>
3364 <entry>128</entry>
3365 <entry>128</entry>
3366 <entry>384</entry>
3367 <entry>768</entry>
3368 <entry>3000</entry>
3369 <entry>8000</entry>
3370 <entry>537.6</entry>
3371 <entry>4854</entry>
3372 <entry>4854</entry>
3373 <entry>4854</entry>
3374 <entry>4854</entry>
3375 <entry>9708.4</entry>
3376 </row>
3377 <row>
3378 <entry>Peak average bitrate over 3 secs [kbps]</entry>
3379 <entry></entry>
3380 <entry></entry>
3381 <entry></entry>
3382 <entry></entry>
3383 <entry></entry>
3384 <entry></entry>
3385 <entry></entry>
3386 <entry></entry>
3387 <entry></entry>
3388 <entry></entry>
3389 <entry>800</entry>
3390 <entry>8000</entry>
3391 <entry>8000</entry>
3392 <entry>8000</entry>
3393 <entry>8000</entry>
3394 <entry>16000</entry>
3395 </row>
3396 <row>
3397 <entry>Max. B-frames</entry>
3398 <entry>0</entry>
3399 <entry>0</entry>
3400 <entry>0</entry>
3401 <entry>0</entry>
3402 <entry></entry>
3403 <entry></entry>
3404 <entry></entry>
3405 <entry></entry>
3406 <entry></entry>
3407 <entry></entry>
3408 <entry>0</entry>
3409 <entry>1</entry>
3410 <entry>1</entry>
3411 <entry>1</entry>
3412 <entry>1</entry>
3413 <entry>2</entry>
3414 </row>
3415 <row>
3416 <entry>MPEG quantization</entry>
3417 <entry></entry>
3418 <entry></entry>
3419 <entry></entry>
3420 <entry></entry>
3421 <entry>X</entry>
3422 <entry>X</entry>
3423 <entry>X</entry>
3424 <entry>X</entry>
3425 <entry>X</entry>
3426 <entry>X</entry>
3427 <entry></entry>
3428 <entry></entry>
3429 <entry></entry>
3430 <entry></entry>
3431 <entry></entry>
3432 <entry></entry>
3433 </row>
3434 <row>
3435 <entry>Adaptive quantization</entry>
3436 <entry></entry>
3437 <entry></entry>
3438 <entry></entry>
3439 <entry></entry>
3440 <entry>X</entry>
3441 <entry>X</entry>
3442 <entry>X</entry>
3443 <entry>X</entry>
3444 <entry>X</entry>
3445 <entry>X</entry>
3446 <entry>X</entry>
3447 <entry>X</entry>
3448 <entry>X</entry>
3449 <entry>X</entry>
3450 <entry>X</entry>
3451 <entry>X</entry>
3452 </row>
3453 <row>
3454 <entry>Interlaced encoding</entry>
3455 <entry></entry>
3456 <entry></entry>
3457 <entry></entry>
3458 <entry></entry>
3459 <entry>X</entry>
3460 <entry>X</entry>
3461 <entry>X</entry>
3462 <entry>X</entry>
3463 <entry>X</entry>
3464 <entry>X</entry>
3465 <entry></entry>
3466 <entry></entry>
3467 <entry></entry>
3468 <entry>X</entry>
3469 <entry>X</entry>
3470 <entry>X</entry>
3471 </row>
3472 <row>
3473 <entry>Quaterpixel</entry>
3474 <entry></entry>
3475 <entry></entry>
3476 <entry></entry>
3477 <entry></entry>
3478 <entry>X</entry>
3479 <entry>X</entry>
3480 <entry>X</entry>
3481 <entry>X</entry>
3482 <entry>X</entry>
3483 <entry>X</entry>
3484 <entry></entry>
3485 <entry></entry>
3486 <entry></entry>
3487 <entry></entry>
3488 <entry></entry>
3489 <entry></entry>
3490 </row>
3491 <row>
3492 <entry>Global motion compensation</entry>
3493 <entry></entry>
3494 <entry></entry>
3495 <entry></entry>
3496 <entry></entry>
3497 <entry>X</entry>
3498 <entry>X</entry>
3499 <entry>X</entry>
3500 <entry>X</entry>
3501 <entry>X</entry>
3502 <entry>X</entry>
3503 <entry></entry>
3504 <entry></entry>
3505 <entry></entry>
3506 <entry></entry>
3507 <entry></entry>
3508 <entry></entry>
3509 </row>
3510 </tbody>
3511 </tgroup>
3512 </informaltable>
3513 </sect2>
3514
3515 <!-- ********** -->
3516
3517 <sect2 id="menc-feat-xvid-example-settings">
3518 <title>Encoding setting examples</title>
3519
3520 <para>
3521 The following settings are examples of different encoding
3522 option combinations that affect the speed vs quality tradeoff
3523 at the same target bitrate.
3524 </para>
3525
3526 <para>
3527 All the encoding settings were tested on a 720x448 @30000/1001 fps
3528 video sample, the target bitrate was 900kbps, and the machine was an
3529 AMD-64 3400+ at 2400 MHz in 64 bits mode.
3530 Each encoding setting features the measured encoding speed (in
3531 frames per second) and the PSNR loss (in dB) compared to the "very
3532 high quality" setting.
3533 Please understand that depending on your source, your machine type
3534 and development advancements, you may get very different results.
3535 </para>
3536
3537 <informaltable frame="all">
3538 <tgroup cols="4">
3539 <thead>
3540 <row><entry>Description</entry><entry>Encoding options</entry><entry>speed (in fps)</entry><entry>Relative PSNR loss (in dB)</entry></row>
3541 </thead>
3542 <tbody>
3543 <row>
3544 <entry>Very high quality</entry>
3545 <entry><option>chroma_opt:vhq=4:bvhq=1:quant_type=mpeg</option></entry>
3546 <entry>16fps</entry>
3547 <entry>0dB</entry>
3548 </row>
3549 <row>
3550 <entry>High quality</entry>
3551 <entry><option>vhq=2:bvhq=1:chroma_opt:quant_type=mpeg</option></entry>
3552 <entry>18fps</entry>
3553 <entry>-0.1dB</entry>
3554 </row>
3555 <row>
3556 <entry>Fast</entry>
3557 <entry><option>turbo:vhq=0</option></entry>
3558 <entry>28fps</entry>
3559 <entry>-0.69dB</entry>
3560 </row>
3561 <row>
3562 <entry>Realtime</entry>
3563 <entry><option>turbo:nochroma_me:notrellis:max_bframes=0:vhq=0</option></entry>
3564 <entry>38fps</entry>
3565 <entry>-1.48dB</entry>
3566 </row>
3567 </tbody>
3568 </tgroup>
3569 </informaltable>
3570 </sect2>
3571 </sect1>
3572
3573
3574 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
3575
3576
3577 <sect1 id="menc-feat-x264">
3578 <title>Encoding with the
3579 <systemitem class="library">x264</systemitem> codec</title>
3580
3581 <para>
3582 <systemitem class="library">x264</systemitem> is a free library for
3583 encoding H.264/AVC video streams.
3584 Before starting to encode, you need to
3585 <link linkend="codec-x264-encode">set up <application>MEncoder</application> to support it</link>.
3586 </para>
3587
3588 <!-- ********** -->
3589
3590 <sect2 id="menc-feat-x264-encoding-options">
3591 <title>Encoding options of x264</title>
3592
3593 <para>
3594 Please begin by reviewing the
3595 <systemitem class="library">x264</systemitem> section of
3596 <application>MPlayer</application>'s man page.
3597 This section is intended to be a supplement to the man page.
3598 Here you will find quick hints about which options are most
3599 likely to interest most people. The man page is more terse,
3600 but also more exhaustive, and it sometimes offers much better
3601 technical detail.
3602 </para>
3603
3604
3605 <sect3 id="menc-feat-x264-encoding-options-intro">
3606 <title>Introduction</title>
3607
3608 <para>
3609 This guide considers two major categories of encoding options:
3610 </para>
3611
3612 <orderedlist>
3613 <listitem><para>
3614 Options which mainly trade off encoding time vs. quality
3615 </para></listitem>
3616 <listitem><para>
3617 Options which may be useful for fulfilling various personal
3618 preferences and special requirements
3619 </para></listitem>
3620 </orderedlist>
3621
3622 <para>
3623 Ultimately, only you can decide which options are best for your
3624 purposes. The decision for the first class of options is the simplest:
3625 you only have to decide whether you think the quality differences
3626 justify the speed differences. For the second class of options,
3627 preferences may be far more subjective, and more factors may be
3628 involved. Note that some of the "personal preferences and special
3629 requirements" options can still have large impacts on speed or quality,
3630 but that is not what they are primarily useful for. A couple of the
3631 "personal preference" options may even cause changes that look better
3632 to some people, but look worse to others.
3633 </para>
3634
3635 <para>
3636 Before continuing, you need to understand that this guide uses only one
3637 quality metric: global PSNR.
3638 For a brief explanation of what PSNR is, see
3639 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>.
3640 Global PSNR is the last PSNR number reported when you include
3641 the <option>psnr</option> option in <option>x264encopts</option>.
3642 Any time you read a claim about PSNR, one of the assumptions
3643 behind the claim is that equal bitrates are used.
3644 </para>
3645
3646 <para>
3647 Nearly all of this guide's comments assume you are using two pass.
3648 When comparing options, there are two major reasons for using
3649 two pass encoding.
3650 First, using two pass often gains around 1dB PSNR, which is a
3651 very big difference.
3652 Secondly, testing options by doing direct quality comparisons
3653 with one pass encodes introduces a major confounding
3654 factor: bitrate often varies significantly with each encode.
3655 It is not always easy to tell whether quality changes are due
3656 mainly to changed options, or if they mostly reflect essentially
3657 random differences in the achieved bitrate.
3658 </para>
3659 </sect3>
3660
3661
3662 <sect3 id="menc-feat-x264-encoding-options-speedvquality">
3663 <title>Options which primarily affect speed and quality</title>
3664
3665 <itemizedlist>
3666 <listitem>
3667 <para>
3668 <emphasis role="bold">subq</emphasis>:
3669 Of the options which allow you to trade off speed for quality,
3670 <option>subq</option> and <option>frameref</option> (see below) are usually
3671 by far the most important.
3672 If you are interested in tweaking either speed or quality, these
3673 are the first options you should consider.
3674 On the speed dimension, the <option>frameref</option> and
3675 <option>subq</option> options interact with each other fairly
3676 strongly.
3677 Experience shows that, with one reference frame,
3678 <option>subq=5</option> (the default setting) takes about 35% more time than
3679 <option>subq=1</option>.
3680 With 6 reference frames, the penalty grows to over 60%.
3681 <option>subq</option>'s effect on PSNR seems fairly constant
3682 regardless of the number of reference frames.
3683 Typically, <option>subq=5</option> achieves 0.2-0.5 dB higher global
3684 PSNR in comparison <option>subq=1</option>.
3685 This is usually enough to be visible.
3686 </para>
3687 <para>
3688 <option>subq=6</option> is slower and yields better quality at a reasonable
3689 cost.
3690 In comparison to <option>subq=5</option>, it usually gains 0.1-0.4 dB
3691 global PSNR with speed costs varying from 25%-100%.
3692 Unlike other levels of <option>subq</option>, the behavior of
3693 <option>subq=6</option> does not depend much on <option>frameref</option>
3694 and <option>me</option>. Instead, the effectiveness of <option>subq=6
3695 </option> depends mostly upon the number of B-frames used. In normal
3696 usage, this means <option>subq=6</option> has a large impact on both speed
3697 and quality in complex, high motion scenes, but it may not have much effect
3698 in low-motion scenes. Note that it is still recommended to always set
3699 <option>bframes</option> to something other than zero (see below).
3700 </para>
3701 <para>
3702 <option>subq=7</option> is the slowest, highest quality mode.
3703 In comparison to <option>subq=6</option>, it usually gains 0.01-0.05 dB
3704 global PSNR with speed costs varying from 15%-33%.
3705 Since the tradeoff encoding time vs. quality is quite low, you should
3706 only use it if you are after every bit saving and if encoding time is
3707 not an issue.
3708 </para>
3709 </listitem>
3710 <listitem>
3711 <para>
3712 <emphasis role="bold">frameref</emphasis>:
3713 <option>frameref</option> is set to 1 by default, but this
3714 should not be taken to imply that it is reasonable to set it to 1.
3715 Merely raising <option>frameref</option> to 2 gains around
3716 0.15dB PSNR with a 5-10% speed penalty; this seems like a good tradeoff.
3717 <option>frameref=3</option> gains around 0.25dB PSNR over
3718 <option>frameref=1</option>, which should be a visible difference.
3719 <option>frameref=3</option> is around 15% slower than
3720 <option>frameref=1</option>.
3721 Unfortunately, diminishing returns set in rapidly.
3722 <option>frameref=6</option> can be expected to gain only
3723 0.05-0.1 dB over <option>frameref=3</option> at an additional
3724 15% speed penalty.
3725 Above <option>frameref=6</option>, the quality gains are
3726 usually very small (although you should keep in mind throughout
3727 this whole discussion that it can vary quite a lot depending on your source).
3728 In a fairly typical case, <option>frameref=12</option>
3729 will improve global PSNR by a tiny 0.02dB over
3730 <option>frameref=6</option>, at a speed cost of 15%-20%.
3731 At such high <option>frameref</option> values, the only really
3732 good thing that can be said is that increasing it even further will
3733 almost certainly never <emphasis role="bold">harm</emphasis>
3734 PSNR, but the additional quality benefits are barely even
3735 measurable, let alone perceptible.
3736 </para>
3737 <note><title>Note:</title>
3738 <para>
3739 Raising <option>frameref</option> to unnecessarily high values
3740 <emphasis role="bold">can</emphasis> and
3741 <emphasis role="bold">usually does</emphasis>
3742 hurt coding efficiency if you turn CABAC off.
3743 With CABAC on (the default behavior), the possibility of setting
3744 <option>frameref</option> "too high" currently seems too remote
3745 to even worry about, and in the future, optimizations may remove
3746 the possibility altogether.
3747 </para></note>
3748 <para>
3749 If you care about speed, a reasonable compromise is to use low
3750 <option>subq</option> and <option>frameref</option> values on
3751 the first pass, and then raise them on the second pass.
3752 Typically, this has a negligible negative effect on the final
3753 quality: You will probably lose well under 0.1dB PSNR, which
3754 should be much too small of a difference to see.
3755 However, different values of <option>frameref</option> can
3756 occasionally affect frametype decision.
3757 Most likely, these are rare outlying cases, but if you want to
3758 be pretty sure, consider whether your video has either
3759 fullscreen repetitive flashing patterns or very large temporary
3760 occlusions which might force an I-frame.
3761 Adjust the first-pass <option>frameref</option> so it is large
3762 enough to contain the duration of the flashing cycle (or occlusion).
3763 For example, if the scene flashes back and forth between two images
3764 over a duration of three frames, set the first pass
3765 <option>frameref</option> to 3 or higher.
3766 This issue is probably extremely rare in live action video material,
3767 but it does sometimes come up in video game captures.
3768 </para>
3769 </listitem>
3770 <listitem>
3771 <para>
3772 <emphasis role="bold">me</emphasis>:
3773 This option is for choosing the motion estimation search method.
3774 Altering this option provides a straightforward quality-vs-speed
3775 tradeoff. <option>me=dia</option> is only a few percent faster than
3776 the default search, at a cost of under 0.1dB global PSNR. The
3777 default setting (<option>me=hex</option>) is a reasonable tradeoff
3778 between speed and quality. <option>me=umh</option> gains a little under
3779 0.1dB global PSNR, with a speed penalty that varies depending on
3780 <option>frameref</option>. At high values of
3781 <option>frameref</option> (e.g. 12 or so), <option>me=umh</option>
3782 is about 40% slower than the default <option> me=hex</option>. With
3783 <option>frameref=3</option>, the speed penalty incurred drops to
3784 25%-30%.
3785 </para>
3786 <para>
3787 <option>me=esa</option> uses an exhaustive search that is too slow for
3788 practical use.
3789 </para>
3790 </listitem>
3791 <listitem><para>
3792 <emphasis role="bold">partitions=all</emphasis>:
3793 This option enables the use of 8x4, 4x8 and 4x4 subpartitions in
3794 predicted macroblocks (in addition to the default partitions).
3795 Enabling it results in a fairly consistent
3796 10%-15% loss of speed. This option is rather useless in source
3797 containing only low motion, however in some high-motion source,
3798 particularly source with lots of small moving objects, gains of
3799 about 0.1dB can be expected.
3800 </para></listitem>
3801 <listitem>
3802 <para>
3803 <emphasis role="bold">bframes</emphasis>:
3804 If you are used to encoding with other codecs, you may have found
3805 that B-frames are not always useful.
3806 In H.264, this has changed: there are new techniques and block
3807 types that are possible in B-frames.
3808 Usually, even a naive B-frame choice algorithm can have a
3809 significant PSNR benefit.
3810 It is interesting to note that using B-frames usually speeds up
3811 the second pass somewhat, and may also speed up a single
3812 pass encode if adaptive B-frame decision is turned off.
3813 </para>
3814 <para>
3815 With adaptive B-frame decision turned off
3816 (<option>x264encopts</option>'s <option>nob_adapt</option>),
3817 the optimal value for this setting is usually no more than
3818 <option>bframes=1</option>, or else high-motion scenes can suffer.
3819 With adaptive B-frame decision on (the default behavior), it is
3820 safe to use higher values; the encoder will reduce the use of
3821 B-frames in scenes where they would hurt compression.
3822 The encoder rarely chooses to use more than 3 or 4 B-frames;
3823 setting this option any higher will have little effect.
3824 </para>
3825 </listitem>
3826 <listitem>
3827 <para>
3828 <emphasis role="bold">b_adapt</emphasis>:
3829 Note: This is on by default.
3830 </para>
3831 <para>
3832 With this option enabled, the encoder will use a reasonably fast
3833 decision process to reduce the number of B-frames used in scenes that
3834 might not benefit from them as much.
3835 You can use <option>b_bias</option> to tweak how B-frame-happy
3836 the encoder is.
3837 The speed penalty of adaptive B-frames is currently rather modest,
3838 but so is the potential quality gain.
3839 It usually does not hurt, however.
3840 Note that this only affects speed and frametype decision on the
3841 first pass.
3842 <option>b_adapt</option> and <option>b_bias</option> have no
3843 effect on subsequent passes.
3844 </para>
3845 </listitem>
3846 <listitem><para>
3847 <emphasis role="bold">b_pyramid</emphasis>:
3848 You might as well enable this option if you are using >=2 B-frames;
3849 as the man page says, you get a little quality improvement at no
3850 speed cost.
3851 Note that these videos cannot be read by libavcodec-based decoders
3852 older than about March 5, 2005.
3853 </para></listitem>
3854 <listitem>
3855 <para>
3856 <emphasis role="bold">weight_b</emphasis>:
3857 In typical cases, there is not much gain with this option.
3858 However, in crossfades or fade-to-black scenes, weighted
3859 prediction gives rather large bitrate savings.
3860 In MPEG-4 ASP, a fade-to-black is usually best coded as a series
3861 of expensive I-frames; using weighted prediction in B-frames
3862 makes it possible to turn at least some of these into much smaller
3863 B-frames.
3864 Encoding time cost is minimal, as no extra decisions need to be made.
3865 Also, contrary to what some people seem to guess, the decoder
3866 CPU requirements are not much affected by weighted prediction,
3867 all else being equal.
3868 </para>
3869 <para>
3870 Unfortunately, the current adaptive B-frame decision algorithm
3871 has a strong tendency to avoid B-frames during fades.
3872 Until this changes, it may be a good idea to add
3873 <option>nob_adapt</option> to your x264encopts, if you expect
3874 fades to have a large effect in your particular video
3875 clip.
3876 </para>
3877 </listitem>
3878 <listitem id="menc-feat-x264-encoding-options-speedvquality-threads">
3879 <para>
3880 <emphasis role="bold">threads</emphasis>:
3881 This option allows to spawn threads to encode in parallel on multiple CPUs.
3882 You can manually select the number of threads to be created or, better, set
3883 <option>threads=auto</option> and let
3884 <systemitem class="library">x264</systemitem> detect how many CPUs are
3885 available and pick an appropriate number of threads.
3886 If you have a multi-processor machine, you should really consider using it
3887 as it can to increase encoding speed linearly with the number of CPU cores
3888 (about 94% per CPU core), with very little quality reduction (about 0.005dB
3889 for dual processor, about 0.01dB for a quad processor machine).
3890 </para>
3891 </listitem>
3892 </itemizedlist>
3893 </sect3>
3894
3895
3896 <sect3 id="menc-feat-x264-encoding-options-misc-preferences">
3897 <title>Options pertaining to miscellaneous preferences</title>
3898
3899 <itemizedlist>
3900 <listitem>
3901 <para>
3902 <emphasis role="bold">Two pass encoding</emphasis>:
3903 Above, it was suggested to always use two pass encoding, but there
3904 are still reasons for not using it. For instance, if you are capturing
3905 live TV and encoding in realtime, you are forced to use single-pass.
3906 Also, one pass is obviously faster than two passes; if you use the
3907 exact same set of options on both passes, two pass encoding is almost
3908 twice as slow.
3909 </para>
3910 <para>
3911 Still, there are very good reasons for using two pass encoding. For
3912 one thing, single pass ratecontrol is not psychic, and it often makes
3913 unreasonable choices because it cannot see the big picture. For example,
3914 suppose you have a two minute long video consisting of two distinct
3915 halves. The first half is a very high-motion scene lasting 60 seconds
3916 which, in isolation, requires about 2500kbps in order to look decent.
3917 Immediately following it is a much less demanding 60-second scene
3918 that looks good at 300kbps. Suppose you ask for 1400kbps on the theory
3919 that this is enough to accomodate both scenes. Single pass ratecontrol
3920 will make a couple of "mistakes" in such a case. First of all, it
3921 will target 1400kbps in both segments. The first segment may end up
3922 heavily overquantized, causing it to look unacceptably and unreasonably
3923 blocky. The second segment will be heavily underquantized; it may look
3924 perfect, but the bitrate cost of that perfection will be completely
3925 unreasonable. What is even harder to avoid is the problem at the
3926 transition between the two scenes. The first seconds of the low motion
3927 half will be hugely over-quantized, because the ratecontrol is still
3928 expecting the kind of bitrate requirements it met in the first half
3929 of the video. This "error period" of heavily over-quantized low motion
3930 will look jarringly bad, and will actually use less than the 300kbps
3931 it would have taken to make it look decent. There are ways to
3932 mitigate the pitfalls of single-pass encoding, but they may tend to
3933 increase bitrate misprediction.
3934 </para>
3935 <para>
3936 Multipass ratecontrol can offer huge advantages over a single pass.
3937 Using the statistics gathered from the first pass encode, the encoder
3938 can estimate, with reasonable accuracy, the "cost" (in bits) of
3939 encoding any given frame, at any given quantizer. This allows for
3940 a much more rational, better planned allocation of bits between the
3941 expensive (high-motion) and cheap (low-motion) scenes. See
3942 <option>qcomp</option> below for some ideas on how to tweak this
3943 allocation to your liking.
3944 </para>
3945 <para>
3946 Moreover, two passes need not take twice as long as one pass. You can
3947 tweak the options in the first pass for higher speed and lower quality.
3948 If you choose your options well, you can get a very fast first pass.
3949 The resulting quality in the second pass will be slightly lower because size
3950 prediction is less accurate, but the quality difference is normally much
3951 too small to be visible. Try, for example, adding
3952 <option>subq=1:frameref=1</option> to the first pass
3953 <option>x264encopts</option>. Then, on the second pass, use slower,
3954 higher-quality options:
3955 <option>subq=6:frameref=15:partitions=all:me=umh</option>
3956 </para>
3957 </listitem>
3958 <listitem><para>
3959 <emphasis role="bold">Three pass encoding</emphasis>?
3960 x264 offers the ability to make an arbitrary number of consecutive
3961 passes. If you specify <option>pass=1</option> on the first pass,
3962 then use <option>pass=3</option> on a subsequent pass, the subsequent
3963 pass will both read the statistics from the previous pass, and write
3964 its own statistics. An additional pass following this one will have
3965 a very good base from which to make highly accurate predictions of
3966 framesizes at a chosen quantizer. In practice, the overall quality
3967 gain from this is usually close to zero, and quite possibly a third
3968 pass will result in slightly worse global PSNR than the pass before
3969 it. In typical usage, three passes help if you get either bad bitrate
3970 prediction or bad looking scene transitions when using only two passes.
3971 This is somewhat likely to happen on extremely short clips. There are
3972 also a few special cases in which three (or more) passes are handy
3973 for advanced users, but for brevity, this guide omits discussing those
3974 special cases.
3975 </para></listitem>
3976 <listitem><para>
3977 <emphasis role="bold">qcomp</emphasis>:
3978 <option>qcomp</option> trades off the number of bits allocated
3979 to "expensive" high-motion versus "cheap" low-motion frames. At
3980 one extreme, <option>qcomp=0</option> aims for true constant
3981 bitrate. Typically this would make high-motion scenes look completely
3982 awful, while low-motion scenes would probably look absolutely
3983 perfect, but would also use many times more bitrate than they
3984 would need in order to look merely excellent. At the other extreme,
3985 <option>qcomp=1</option> achieves nearly constant quantization parameter
3986 (QP). Constant QP does not look bad, but most people think it is more
3987 reasonable to shave some bitrate off of the extremely expensive scenes
3988 (where the loss of quality is not as noticeable) and reallocate it to
3989 the scenes that are easier to encode at excellent quality.
3990 <option>qcomp</option> is set to 0.6 by default, which may be slightly
3991 low for many peoples' taste (0.7-0.8 are also commonly used).
3992 </para></listitem>
3993 <listitem><para>
3994 <emphasis role="bold">keyint</emphasis>:
3995 <option>keyint</option> is solely for trading off file seekability against
3996 coding efficiency. By default, <option>keyint</option> is set to 250. In
3997 25fps material, this guarantees the ability to seek to within 10 seconds
3998 precision. If you think it would be important and useful to be able to
3999 seek within 5 seconds of precision, set <option>keyint=125</option>;
4000 this will hurt quality/bitrate slightly. If you care only about quality
4001 and not about seekability, you can set it to much higher values
4002 (understanding that there are diminishing returns which may become
4003 vanishingly low, or even zero). The video stream will still have seekable
4004 points as long as there are some scene changes.
4005 </para></listitem>
4006 <listitem>
4007 <para>
4008 <emphasis role="bold">deblock</emphasis>:
4009 This topic is going to be a bit controversial.
4010 </para>
4011 <para>
4012 H.264 defines a simple deblocking procedure on I-blocks that uses
4013 pre-set strengths and thresholds depending on the QP of the block
4014 in question.
4015 By default, high QP blocks are filtered heavily, and low QP blocks
4016 are not deblocked at all.
4017 The pre-set strengths defined by the standard are well-chosen and
4018 the odds are very good that they are PSNR-optimal for whatever
4019 video you are trying to encode.
4020 The <option>deblock</option> allow you to specify offsets to the preset
4021 deblocking thresholds.
4022 </para>
4023 <para>
4024 Many people seem to think it is a good idea to lower the deblocking
4025 filter strength by large amounts (say, -3).
4026 This is however almost never a good idea, and in most cases,
4027 people who are doing this do not understand very well how
4028 deblocking works by default.
4029 </para>
4030 <para>
4031 The first and most important thing to know about the in-loop
4032 deblocking filter is that the default thresholds are almost always
4033 PSNR-optimal.
4034 In the rare cases that they are not optimal, the ideal offset is
4035 plus or minus 1.
4036 Adjusting deblocking parameters by a larger amount is almost
4037 guaranteed to hurt PSNR.
4038 Strengthening the filter will smear more details; weakening the
4039 filter will increase the appearance of blockiness.
4040 </para>
4041 <para>
4042 It is definitely a bad idea to lower the deblocking thresholds if
4043 your source is mainly low in spacial complexity (i.e., not a lot
4044 of detail or noise).
4045 The in-loop filter does a rather excellent job of concealing
4046 the artifacts that occur.
4047 If the source is high in spacial complexity, however, artifacts
4048 are less noticeable.
4049 This is because the ringing tends to look like detail or noise.
4050 Human visual perception easily notices when detail is removed,
4051 but it does not so easily notice when the noise is wrongly
4052 represented.
4053 When it comes to subjective quality, noise and detail are somewhat
4054 interchangeable.
4055 By lowering the deblocking filter strength, you are most likely
4056 increasing error by adding ringing artifacts, but the eye does
4057 not notice because it confuses the artifacts with detail.
4058 </para>
4059 <para>
4060 This <emphasis role="bold">still</emphasis> does not justify
4061 lowering the deblocking filter strength, however.
4062 You can generally get better quality noise from postprocessing.
4063 If your H.264 encodes look too blurry or smeared, try playing with
4064 <option>-vf noise</option> when you play your encoded movie.
4065 <option>-vf noise=8a:4a</option> should conceal most mild
4066 artifacting.
4067 It will almost certainly look better than the results you
4068 would have gotten just by fiddling with the deblocking filter.
4069 </para>
4070 </listitem>
4071 </itemizedlist>
4072 </sect3>
4073 </sect2>
4074
4075 <!-- ********** -->
4076
4077 <sect2 id="menc-feat-x264-example-settings">
4078 <title>Encoding setting examples</title>
4079
4080 <para>
4081 The following settings are examples of different encoding
4082 option combinations that affect the speed vs quality tradeoff
4083 at the same target bitrate.
4084 </para>
4085
4086 <para>
4087 All the encoding settings were tested on a 720x448 @30000/1001 fps
4088 video sample, the target bitrate was 900kbps, and the machine was an
4089 AMD-64 3400+ at 2400 MHz in 64 bits mode.
4090 Each encoding setting features the measured encoding speed (in
4091 frames per second) and the PSNR loss (in dB) compared to the "very
4092 high quality" setting.
4093 Please understand that depending on your source, your machine type
4094 and development advancements, you may get very different results.
4095 </para>
4096
4097 <informaltable frame="all">
4098 <tgroup cols="4">
4099 <thead>
4100 <row>
4101 <entry>Description</entry>
4102 <entry>Encoding options</entry>
4103 <entry>speed (in fps)</entry>
4104 <entry>Relative PSNR loss (in dB)</entry>
4105 </row>
4106 </thead>
4107 <tbody>
4108 <row>
4109 <entry>Very high quality</entry>
4110 <entry><option>subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b</option></entry>
4111 <entry>6fps</entry>
4112 <entry>0dB</entry>
4113 </row>
4114 <row>
4115 <entry>High quality</entry>
4116 <entry><option>subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b</option></entry>
4117 <entry>13fps</entry>
4118 <entry>-0.89dB</entry>
4119 </row>
4120 <row>
4121 <entry>Fast</entry>
4122 <entry><option>subq=4:bframes=2:b_pyramid:weight_b</option></entry>
4123 <entry>17fps</entry>
4124 <entry>-1.48dB</entry>
4125 </row>
4126 </tbody>
4127 </tgroup>
4128 </informaltable>
4129 </sect2>
4130 </sect1>
4131
4132
4133 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4134
4135
4136 <sect1 id="menc-feat-video-for-windows">
4137 <title>
4138 Encoding with the <systemitem class="library">Video For Windows</systemitem>
4139 codec family
4140 </title>
4141
4142 <para>
4143 Video for Windows provides simple encoding by means of binary video codecs.
4144 You can encode with the following codecs (if you have more, please tell us!)
4145 </para>
4146
4147 <para>
4148 Note that support for this is very experimental and some codecs may not work
4149 correctly. Some codecs will only work in certain colorspaces, try
4150 <option>-vf format=bgr24</option> and <option>-vf format=yuy2</option>
4151 if a codec fails or gives wrong output.
4152 </para>
4153
4154 <!-- ********** -->
4155
4156 <sect2 id="menc-feat-enc-vfw-video-codecs">
4157 <title>Video for Windows supported codecs</title>
4158
4159 <para>
4160 <informaltable frame="all">
4161 <tgroup cols="4">
4162 <thead>
4163 <row>
4164 <entry>Video codec file name</entry>
4165 <entry>Description (FourCC)</entry>
4166 <entry>md5sum</entry>
4167 <entry>Comment</entry>
4168 </row>
4169 </thead>
4170 <tbody>
4171 <row>
4172 <entry>aslcodec_vfw.dll</entry>
4173 <entry>Alparysoft lossless codec vfw (ASLC)</entry>
4174 <entry>608af234a6ea4d90cdc7246af5f3f29a</entry>
4175 <entry></entry>
4176 </row>
4177 <row>
4178 <entry>avimszh.dll</entry>
4179 <entry>AVImszh (MSZH)</entry>
4180 <entry>253118fe1eedea04a95ed6e5f4c28878</entry>
4181 <entry>needs <option>-vf format</option></entry>
4182 </row>
4183 <row>
4184 <entry>avizlib.dll</entry>
4185 <entry>AVIzlib (ZLIB)</entry>
4186 <entry>2f1cc76bbcf6d77d40d0e23392fa8eda</entry>
4187 <entry></entry>
4188 </row>
4189 <row>
4190 <entry>divx.dll</entry>
4191 <entry>DivX4Windows-VFW</entry>
4192 <entry>acf35b2fc004a89c829531555d73f1e6</entry>
4193 <entry></entry>
4194 </row>
4195 <row>
4196 <entry>huffyuv.dll</entry>
4197 <entry>HuffYUV (lossless) (HFYU)</entry>
4198 <entry>b74695b50230be4a6ef2c4293a58ac3b</entry>
4199 <entry></entry>
4200 </row>
4201 <row>
4202 <entry>iccvid.dll</entry>
4203 <entry>Cinepak Video (cvid)</entry>
4204 <entry>cb3b7ee47ba7dbb3d23d34e274895133</entry>
4205 <entry></entry>
4206 </row>
4207 <row>
4208 <entry>icmw_32.dll</entry>
4209 <entry>Motion Wavelets (MWV1)</entry>
4210 <entry>c9618a8fc73ce219ba918e3e09e227f2</entry>
4211 <entry></entry>
4212 </row>
4213 <row>
4214 <entry>jp2avi.dll</entry>
4215 <entry>ImagePower MJPEG2000 (IPJ2)</entry>
4216 <entry>d860a11766da0d0ea064672c6833768b</entry>
4217 <entry><option>-vf flip</option></entry>
4218 </row>
4219 <row>
4220 <entry>m3jp2k32.dll</entry>
4221 <entry>Morgan MJPEG2000 (MJ2C)</entry>
4222 <entry>f3c174edcbaef7cb947d6357cdfde7ff</entry>
4223 <entry></entry>
4224 </row>
4225 <row>
4226 <entry>m3jpeg32.dll</entry>
4227 <entry>Morgan Motion JPEG Codec (MJPG)</entry>
4228 <entry>1cd13fff5960aa2aae43790242c323b1</entry>
4229 <entry></entry>
4230 </row>
4231 <row>
4232 <entry>mpg4c32.dll</entry>
4233 <entry>Microsoft MPEG-4 v1/v2</entry>
4234 <entry>b5791ea23f33010d37ab8314681f1256</entry>
4235 <entry></entry>
4236 </row>
4237 <row>
4238 <entry>tsccvid.dll</entry>
4239 <entry>TechSmith Camtasia Screen Codec (TSCC)</entry>
4240 <entry>8230d8560c41d444f249802a2700d1d5</entry>
4241 <entry>shareware error on windows</entry>
4242 </row>
4243 <row>
4244 <entry>vp31vfw.dll</entry>
4245 <entry>On2 Open Source VP3 Codec (VP31)</entry>
4246 <entry>845f3590ea489e2e45e876ab107ee7d2</entry>
4247 <entry></entry>
4248 </row>
4249 <row>
4250 <entry>vp4vfw.dll</entry>
4251 <entry>On2 VP4 Personal Codec (VP40)</entry>
4252 <entry>fc5480a482ccc594c2898dcc4188b58f</entry>
4253 <entry></entry>
4254 </row>
4255 <row>
4256 <entry>vp6vfw.dll</entry>
4257 <entry>On2 VP6 Personal Codec (VP60)</entry>
4258 <entry>04d635a364243013898fd09484f913fb</entry>
4259 <entry></entry>
4260 </row>
4261 <row>
4262 <entry>vp7vfw.dll</entry>
4263 <entry>On2 VP7 Personal Codec (VP70)</entry>
4264 <entry>cb4cc3d4ea7c94a35f1d81c3d750bc8d</entry>
4265 <entry>wrong FourCC?</entry>
4266 </row>
4267 <row>
4268 <entry>ViVD2.dll</entry>
4269 <entry>SoftMedia ViVD V2 codec VfW (GXVE)</entry>
4270 <entry>a7b4bf5cac630bb9262c3f80d8a773a1</entry>
4271 <entry></entry>
4272 </row>
4273 <row>
4274 <entry>msulvc06.DLL</entry>
4275 <entry>MSU Lossless codec (MSUD)</entry>
4276 <entry>294bf9288f2f127bb86f00bfcc9ccdda</entry>
4277 <entry>
4278 Decodable by <application>Window Media Player</application>,
4279 not <application>MPlayer</application> (yet).
4280 </entry>
4281 </row>
4282 <row>
4283 <entry>camcodec.dll</entry>
4284 <entry>CamStudio lossless video codec (CSCD)</entry>
4285 <entry>0efe97ce08bb0e40162ab15ef3b45615</entry>
4286 <entry>sf.net/projects/camstudio</entry>
4287 </row>
4288 </tbody>
4289 </tgroup>
4290 </informaltable>
4291
4292 The first column contains the codec names that should be passed after the
4293 <literal>codec</literal> parameter,
4294 like: <option>-xvfwopts codec=divx.dll</option>
4295 The FourCC code used by each codec is given in the parentheses.
4296 </para>
4297
4298 <informalexample>
4299 <para>
4300 An example to convert an ISO DVD trailer to a VP6 flash video file
4301 using compdata bitrate settings:
4302 <screen>
4303 mencoder -dvd-device <replaceable>zeiram.iso</replaceable> dvd://7 -o <replaceable>trailer.flv</replaceable> \
4304 -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=onepass.mcf -oac mp3lame \
4305 -lameopts cbr:br=64 -af lavcresample=22050 -vf yadif,scale=320:240,flip \
4306 -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames
4307 </screen>
4308 </para>
4309 </informalexample>
4310 </sect2>
4311
4312 <sect2 id="menc-feat-video-for-windows-bitrate-settings">
4313 <title>Using vfw2menc to create a codec settings file.</title>
4314
4315 <para>
4316 To encode with the Video for Windows codecs, you will need to set bitrate
4317 and other options. This is known to work on x86 on both *NIX and Windows.
4318 </para>
4319 <para>
4320 First you must build the <application>vfw2menc</application> program.
4321 It is located in the <filename class="directory">TOOLS</filename> subdirectory
4322 of the MPlayer source tree.
4323 To build on Linux, this can be done using <application>Wine</application>:
4324 <screen>winegcc vfw2menc.c -o vfw2menc -lwinmm -lole32</screen>
4325
4326 To build on Windows in <application>MinGW</application> or
4327 <application>Cygwin</application> use:
4328 <screen>gcc vfw2menc.c -o vfw2menc.exe -lwinmm -lole32</screen>
4329
4330 To build on <application>MSVC</application> you will need getopt.
4331 Getopt can be found in the original <application>vfw2menc</application>
4332 archive available at:
4333 The <ulink url="http://oss.netfarm.it/mplayer-win32.php">MPlayer on win32</ulink> project.
4334 </para>
4335 <informalexample>
4336 <para>
4337 Below is an example with the VP6 codec.
4338 <screen>
4339 vfw2menc -f VP62 -d vp6vfw.dll -s firstpass.mcf
4340 </screen>
4341 This will open the VP6 codec dialog window.
4342 Repeat this step for the second pass
4343 and use <option>-s <replaceable>secondpass.mcf</replaceable></option>.
4344 </para>
4345 </informalexample>
4346 <para>
4347 Windows users can use
4348 <option>-xvfwopts codec=vp6vfw.dll:compdata=dialog</option> to have
4349 the codec dialog display before encoding starts.
4350 </para>
4351 </sect2>
4352 </sect1>
4353
4354
4355 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4356
4357
4358 <sect1 id="menc-feat-quicktime-7">
4359 <title>Using <application>MEncoder</application> to create
4360 <application>QuickTime</application>-compatible files</title>
4361
4362
4363 <sect2 id="menc-feat-quicktime-7-why-use-it">
4364 <title>Why would one want to produce <application>QuickTime</application>-compatible Files?</title>
4365
4366 <para>
4367 There are several reasons why producing
4368 <application>QuickTime</application>-compatible files can be desirable.
4369 </para>
4370 <itemizedlist>
4371 <listitem><para>
4372 You want any computer illiterate to be able to watch your encode on
4373 any major platform (Windows, Mac OS X, Unices &hellip;).
4374 </para></listitem>
4375 <listitem><para>
4376 <application>QuickTime</application> is able to take advantage of more
4377 hardware and software acceleration features of Mac OS X than
4378 platform-independent players like <application>MPlayer</application>
4379 or <application>VLC</application>.
4380 That means that your encodes have a chance to be played smoothly by older
4381 G4-powered machines.
4382 </para></listitem>
4383 <listitem><para>
4384 <application>QuickTime</application> 7 supports the next-generation codec H.264,
4385 which yields significantly better picture quality than previous codec
4386 generations (MPEG-2, MPEG-4 &hellip;).
4387 </para></listitem>
4388 </itemizedlist>
4389 </sect2>
4390
4391 <sect2 id="menc-feat-quicktime-7-constraints">
4392 <title><application>QuickTime</application> 7 limitations</title>
4393
4394 <para>
4395 <application>QuickTime</application> 7 supports H.264 video and AAC audio,
4396 but it does not support them muxed in the AVI container format.
4397 However, you can use <application>MEncoder</application> to encode
4398 the video and audio, and then use an external program such as
4399 <application>mp4creator</application> (part of the
4400 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>)
4401 to remux the video and audio tracks into an MP4 container.
4402 </para>
4403
4404 <para>
4405 <application>QuickTime</application>'s support for H.264 is limited,
4406 so you will need to drop some advanced features.
4407 If you encode your video with features that
4408 <application>QuickTime</application> 7 does not support,
4409 <application>QuickTime</application>-based players will show you a pretty
4410 white screen instead of your expected video.
4411 </para>
4412
4413 <itemizedlist>
4414 <listitem><para>
4415 <emphasis role="bold">B-frames</emphasis>:
4416 <application>QuickTime</application> 7 supports a maximum of 1 B-frame, i.e.
4417 <option>-x264encopts bframes=1</option>. This means that
4418 <option>b_pyramid</option> and <option>weight_b</option> will have no
4419 effect, since they require <option>bframes</option> to be greater than 1.
4420 </para></listitem>
4421 <listitem><para>
4422 <emphasis role="bold">Macroblocks</emphasis>:
4423 <application>QuickTime</application> 7 does not support 8x8 DCT macroblocks.
4424 This option (<option>8x8dct</option>) is off by default, so just be sure
4425 not to explicitly enable it. This also means that the <option>i8x8</option>
4426 option will have no effect, since it requires <option>8x8dct</option>.
4427 </para></listitem>
4428 <listitem><para>
4429 <emphasis role="bold">Aspect ratio</emphasis>:
4430 <application>QuickTime</application> 7 does not support SAR (sample
4431 aspect ratio) information in MPEG-4 files; it assumes that SAR=1. Read
4432 <link linkend="menc-feat-quicktime-7-scale">the section on scaling</link>
4433 for a workaround.
4434 </para></listitem>
4435 </itemizedlist>
4436
4437 </sect2>
4438
4439 <sect2 id="menc-feat-quicktime-7-crop">
4440 <title>Cropping</title>
4441 <para>
4442 Suppose you want to rip your freshly bought copy of "The Chronicles of
4443 Narnia". Your DVD is region 1,
4444 which means it is NTSC. The example below would still apply to PAL,
4445 except you would omit <option>-ofps 24000/1001</option> and use slightly
4446 different <option>crop</option> and <option>scale</option> dimensions.
4447 </para>
4448
4449 <para>
4450 After running <option>mplayer dvd://1</option>, you follow the process
4451 detailed in the section <link linkend="menc-feat-telecine">How to deal
4452 with telecine and interlacing in NTSC DVDs</link> and discover that it is
4453 24000/1001 fps progressive video. This simplifies the process somewhat,
4454 since you do not need to use an inverse telecine filter such as
4455 <option>pullup</option> or a deinterlacing filter such as
4456 <option>yadif</option>.
4457 </para>
4458
4459 <para>
4460 Next, you need to crop out the black bars from the top and bottom of the
4461 video, as detailed in <link linkend="menc-feat-dvd-mpeg4-example-crop">this</link>
4462 previous section.
4463 </para>
4464
4465 </sect2>
4466
4467 <sect2 id="menc-feat-quicktime-7-scale">
4468 <title>Scaling</title>
4469
4470 <para>
4471 The next step is truly heartbreaking.
4472 <application>QuickTime</application> 7 does not support MPEG-4 videos
4473 with a sample aspect ratio other than 1, so you will need to upscale
4474 (which wastes a lot of disk space) or downscale (which loses some
4475 details of the source) the video to square pixels.
4476 Either way you do it, this is highly inefficient, but simply cannot
4477 be avoided if you want your video to be playable by
4478 <application>QuickTime</application> 7.
4479 <application>MEncoder</application> can apply the appropriate upscaling
4480 or downscaling by specifying respectively <option>-vf scale=-10:-1</option>
4481 or <option>-vf scale=-1:-10</option>.
4482 This will scale your video to the correct width for the cropped height,
4483 rounded to the closest multiple of 16 for optimal compression.
4484 Remember that if you are cropping, you should crop first, then scale:
4485
4486 <screen>-vf crop=720:352:0:62,scale=-10:-1</screen>
4487 </para>
4488
4489 </sect2>
4490
4491 <sect2 id="menc-feat-quicktime-7-avsync">
4492 <title>A/V sync</title>
4493
4494 <para>
4495 Because you will be remuxing into a different container, you should
4496 always use the <option>harddup</option> option to ensure that duplicated
4497 frames are actually duplicated in the video output. Without this option,
4498 <application>MEncoder</application> will simply put a marker in the video
4499 stream that a frame was duplicated, and rely on the client software to
4500 show the same frame twice. Unfortunately, this "soft duplication" does
4501 not survive remuxing, so the audio would slowly lose sync with the video.
4502 </para>
4503
4504 <para>
4505 The final filter chain looks like this:
4506 <screen>-vf crop=720:352:0:62,scale=-10:-1,harddup</screen>
4507 </para>
4508
4509 </sect2>
4510
4511 <sect2 id="menc-feat-quicktime-7-bitrate">
4512 <title>Bitrate</title>
4513
4514 <para>
4515 As always, the selection of bitrate is a matter of the technical properties
4516 of the source, as explained
4517 <link linkend="menc-feat-dvd-mpeg4-resolution-bitrate">here</link>, as
4518 well as a matter of taste.
4519 This movie has a fair bit of action and lots of detail, but H.264 video
4520 looks good at much lower bitrates than XviD or other MPEG-4 codecs.
4521 After much experimentation, the author of this guide chose to encode
4522 this movie at 900kbps, and thought that it looked very good.
4523 You may decrease bitrate if you need to save more space, or increase
4524 it if you need to improve quality.
4525 </para>
4526
4527 </sect2>
4528
4529 <sect2 id="menc-feat-quicktime-7-example">
4530 <title>Encoding example</title>
4531
4532 <para>
4533 You are now ready to encode the video. Since you care about
4534 quality, of course you will be doing a two-pass encode. To shave off
4535 some encoding time, you can specify the <option>turbo</option> option
4536 on the first pass; this reduces <option>subq</option> and
4537 <option>frameref</option> to 1. To save some disk space, you can
4538 use the <option>ss</option> option to strip off the first few seconds
4539 of the video. (I found that this particular movie has 32 seconds of
4540 credits and logos.) <option>bframes</option> can be 0 or 1.
4541 The other options are documented in <link
4542 linkend="menc-feat-x264-encoding-options-speedvquality">Encoding with
4543 the <systemitem class="library">x264</systemitem> codec</link> and
4544 the man page.
4545
4546 <screen>mencoder dvd://1 -o /dev/null -ss 32 -ovc x264 \
4547 -x264encopts pass=1:turbo:bitrate=900:bframes=1:\
4548 me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
4549 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4550 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 \
4551 -ofps 24000/1001</screen>
4552
4553 If you have a multi-processor machine, don't miss the opportunity to
4554 dramatically speed-up encoding by enabling
4555 <link linkend="menc-feat-x264-encoding-options-speedvquality-threads">
4556 <systemitem class="library">x264</systemitem>'s multi-threading mode</link>
4557 by adding <option>threads=auto</option> to your <option>x264encopts</option>
4558 command-line.
4559 </para>
4560
4561 <para>
4562 The second pass is the same, except that you specify the output file
4563 and set <option>pass=2</option>.
4564
4565 <screen>mencoder dvd://1 <emphasis role="bold">-o narnia.avi</emphasis> -ss 32 -ovc x264 \
4566 -x264encopts <emphasis role="bold">pass=2</emphasis>:turbo:bitrate=900:frameref=5:bframes=1:\
4567 me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
4568 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4569 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 \
4570 -ofps 24000/1001</screen>
4571 </para>
4572
4573 <para>
4574 The resulting AVI should play perfectly in
4575 <application>MPlayer</application>, but of course
4576 <application>QuickTime</application> can not play it because it does
4577 not support H.264 muxed in AVI.
4578 So the next step is to remux the video into an MP4 container.
4579 </para>
4580 </sect2>
4581
4582 <sect2 id="menc-feat-quicktime-7-remux">
4583 <title>Remuxing as MP4</title>
4584
4585 <para>
4586 There are several ways to remux AVI files to MP4. You can use
4587 <application>mp4creator</application>, which is part of the
4588 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>.
4589 </para>
4590
4591 <para>
4592 First, demux the AVI into separate audio and video streams using
4593 <application>MPlayer</application>.
4594
4595 <screen>mplayer narnia.avi -dumpaudio -dumpfile narnia.aac
4596 mplayer narnia.avi -dumpvideo -dumpfile narnia.h264</screen>
4597
4598 The filenames are important; <application>mp4creator</application>
4599 requires that AAC audio streams be named <systemitem>.aac</systemitem>
4600 and H.264 video streams be named <systemitem>.h264</systemitem>.
4601 </para>
4602
4603 <para>
4604 Now use <application>mp4creator</application> to create a new
4605 MP4 file out of the audio and video streams.
4606
4607 <screen>mp4creator -create=narnia.aac narnia.mp4
4608 mp4creator -create=narnia.h264 -rate=23.976 narnia.mp4</screen>
4609
4610 Unlike the encoding step, you must specify the framerate as a
4611 decimal (such as 23.976), not a fraction (such as 24000/1001).
4612 </para>
4613
4614 <para>
4615 This <systemitem>narnia.mp4</systemitem> file should now be playable
4616 with any <application>QuickTime</application> 7 application, such as
4617 <application>QuickTime Player</application> or
4618 <application>iTunes</application>. If you are planning to view the
4619 video in a web browser with the <application>QuickTime</application>
4620 plugin, you should also hint the movie so that the
4621 <application>QuickTime</application> plugin can start playing it
4622 while it is still downloading. <application>mp4creator</application>
4623 can create these hint tracks:
4624
4625 <screen>mp4creator -hint=1 narnia.mp4
4626 mp4creator -hint=2 narnia.mp4
4627 mp4creator -optimize narnia.mp4</screen>
4628
4629 You can check the final result to ensure that the hint tracks were
4630 created successfully:
4631
4632 <screen>mp4creator -list narnia.mp4</screen>
4633
4634 You should see a list of tracks: 1 audio, 1 video, and 2 hint tracks.
4635
4636 <screen>Track Type Info
4637 1 audio MPEG-4 AAC LC, 8548.714 secs, 190 kbps, 48000 Hz
4638 2 video H264 Main@5.1, 8549.132 secs, 899 kbps, 848x352 @ 23.976001 fps
4639 3 hint Payload mpeg4-generic for track 1
4640 4 hint Payload H264 for track 2
4641 </screen>
4642 </para>
4643
4644 </sect2>
4645
4646 <sect2 id="menc-feat-quicktime-7-metadata">
4647 <title>Adding metadata tags</title>
4648
4649 <para>
4650 If you want to add tags to your video that show up in iTunes, you can use
4651 <ulink url="http://atomicparsley.sourceforge.net/">AtomicParsley</ulink>.
4652
4653 <screen>AtomicParsley narnia.mp4 --metaEnema --title "The Chronicles of Narnia" --year 2005 --stik Movie --freefree --overWrite</screen>
4654
4655 The <option>--metaEnema</option> option removes any existing metadata
4656 (<application>mp4creator</application> inserts its name in the
4657 "encoding tool" tag), and <option>--freefree</option> reclaims the
4658 space from the deleted metadata.
4659 The <option>--stik</option> option sets the type of video (such as Movie
4660 or TV Show), which iTunes uses to group related video files.
4661 The <option>--overWrite</option> option overwrites the original file;
4662 without it, <application>AtomicParsley</application> creates a new
4663 auto-named file in the same directory and leaves the original file
4664 untouched.
4665 </para>
4666
4667 </sect2>
4668
4669 </sect1>
4670
4671
4672 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4673
4674
4675 <sect1 id="menc-feat-vcd-dvd">
4676 <title>Using <application>MEncoder</application>
4677 to create VCD/SVCD/DVD-compliant files</title>
4678
4679 <sect2 id="menc-feat-vcd-dvd-constraints">
4680 <title>Format Constraints</title>
4681
4682 <para>
4683 <application>MEncoder</application> is capable of creating VCD, SCVD
4684 and DVD format MPEG files using the
4685 <systemitem class="library">libavcodec</systemitem> library.
4686 These files can then be used in conjunction with
4687 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>
4688 or
4689 <ulink url="http://dvdauthor.sourceforge.net/">dvdauthor</ulink>
4690 to create discs that will play on a standard set-top player.
4691 </para>
4692
4693 <para>
4694 The DVD, SVCD, and VCD formats are subject to heavy constraints.
4695 Only a small selection of encoded picture sizes and aspect ratios are
4696 available.
4697 If your movie does not already meet these requirements, you may have
4698 to scale, crop or add black borders to the picture to make it
4699 compliant.
4700 </para>
4701
4702
4703 <sect3 id="menc-feat-vcd-dvd-constraints-resolution">
4704 <title>Format Constraints</title>
4705
4706 <informaltable frame="all">
4707 <tgroup cols="9">
4708 <thead>
4709 <row>
4710 <entry>Format</entry>
4711 <entry>Resolution</entry>
4712 <entry>V. Codec</entry>
4713 <entry>V. Bitrate</entry>
4714 <entry>Sample Rate</entry>
4715 <entry>A. Codec</entry>
4716 <entry>A. Bitrate</entry>
4717 <entry>FPS</entry>
4718 <entry>Aspect</entry>
4719 </row>
4720 </thead>
4721 <tbody>
4722 <row>
4723 <entry>NTSC DVD</entry>
4724 <entry>720x480, 704x480, 352x480, 352x240</entry>
4725 <entry>MPEG-2</entry>
4726 <entry>9800 kbps</entry>
4727 <entry>48000 Hz</entry>
4728 <entry>AC-3,PCM</entry>
4729 <entry>1536 kbps (max)</entry>
4730 <entry>30000/1001, 24000/1001</entry>
4731 <entry>4:3, 16:9 (only for 720x480)</entry>
4732 </row>
4733 <row>
4734 <entry>NTSC DVD</entry>
4735 <entry>352x240<footnote id='fn-rare-resolutions'><para>
4736 These resolutions are rarely used for DVDs because
4737 they are fairly low quality.</para></footnote></entry>
4738 <entry>MPEG-1</entry>
4739 <entry>1856 kbps</entry>
4740 <entry>48000 Hz</entry>
4741 <entry>AC-3,PCM</entry>
4742 <entry>1536 kbps (max)</entry>
4743 <entry>30000/1001, 24000/1001</entry>
4744 <entry>4:3, 16:9</entry>
4745 </row>
4746 <row>
4747 <entry>NTSC SVCD</entry>
4748 <entry>480x480</entry>
4749 <entry>MPEG-2</entry>
4750 <entry>2600 kbps</entry>
4751 <entry>44100 Hz</entry>
4752 <entry>MP2</entry>
4753 <entry>384 kbps (max)</entry>
4754 <entry>30000/1001</entry>
4755 <entry>4:3</entry>
4756 </row>
4757 <row>
4758 <entry>NTSC VCD</entry>
4759 <entry>352x240</entry>
4760 <entry>MPEG-1</entry>
4761 <entry>1150 kbps</entry>
4762 <entry>44100 Hz</entry>
4763 <entry>MP2</entry>
4764 <entry>224 kbps</entry>
4765 <entry>24000/1001, 30000/1001</entry>
4766 <entry>4:3</entry>
4767 </row>
4768 <row>
4769 <entry>PAL DVD</entry>
4770 <entry>720x576, 704x576, 352x576, 352x288</entry>
4771 <entry>MPEG-2</entry>
4772 <entry>9800 kbps</entry>
4773 <entry>48000 Hz</entry>
4774 <entry>MP2,AC-3,PCM</entry>
4775 <entry>1536 kbps (max)</entry>
4776 <entry>25</entry>
4777 <entry>4:3, 16:9 (only for 720x576)</entry>
4778 </row>
4779 <row>
4780 <entry>PAL DVD</entry>
4781 <entry>352x288<footnoteref linkend='fn-rare-resolutions'/></entry>
4782 <entry>MPEG-1</entry>
4783 <entry>1856 kbps</entry>
4784 <entry>48000 Hz</entry>
4785 <entry>MP2,AC-3,PCM</entry>
4786 <entry>1536 kbps (max)</entry>
4787 <entry>25</entry>
4788 <entry>4:3, 16:9</entry>
4789 </row>
4790 <row>
4791 <entry>PAL SVCD</entry>
4792 <entry>480x576</entry>
4793 <entry>MPEG-2</entry>
4794 <entry>2600 kbps</entry>
4795 <entry>44100 Hz</entry>
4796 <entry>MP2</entry>
4797 <entry>384 kbps (max)</entry>
4798 <entry>25</entry>
4799 <entry>4:3</entry>
4800 </row>
4801 <row>
4802 <entry>PAL VCD</entry>
4803 <entry>352x288</entry>
4804 <entry>MPEG-1</entry>
4805 <entry>1152 kbps</entry>
4806 <entry>44100 Hz</entry>
4807 <entry>MP2</entry>
4808 <entry>224 kbps</entry>
4809 <entry>25</entry>
4810 <entry>4:3</entry>
4811 </row>
4812 </tbody>
4813 </tgroup>
4814 </informaltable>
4815
4816 <para>
4817 If your movie has 2.35:1 aspect (most recent action movies), you will
4818 have to add black borders or crop the movie down to 16:9 to make a DVD or VCD.
4819 If you add black borders, try to align them at 16-pixel boundaries in
4820 order to minimize the impact on encoding performance.
4821 Thankfully DVD has sufficiently excessive bitrate that you do not have
4822 to worry too much about encoding efficiency, but SVCD and VCD are
4823 highly bitrate-starved and require effort to obtain acceptable quality.
4824 </para>
4825 </sect3>
4826
4827
4828 <sect3 id="menc-feat-vcd-dvd-constraints-gop">
4829 <title>GOP Size Constraints</title>
4830
4831 <para>
4832 DVD, VCD, and SVCD also constrain you to relatively low
4833 GOP (Group of Pictures) sizes.
4834 For 30 fps material the largest allowed GOP size is 18.
4835 For 25 or 24 fps, the maximum is 15.
4836 The GOP size is set using the <option>keyint</option> option.
4837 </para>
4838 </sect3>
4839
4840
4841 <sect3 id="menc-feat-vcd-dvd-constraints-bitrate">
4842 <title>Bitrate Constraints</title>
4843
4844 <para>
4845 VCD video is required to be CBR at 1152 kbps.
4846 This highly limiting constraint also comes along with an extremly low vbv
4847 buffer size of 327 kilobits.
4848 SVCD allows varying video bitrates up to 2500 kbps, and a somewhat less
4849 restrictive vbv buffer size of 917 kilobits is allowed.
4850 DVD video bitrates may range anywhere up to 9800 kbps (though typical
4851 bitrates are about half that), and the vbv buffer size is 1835 kilobits.
4852 </para>
4853 </sect3>
4854 </sect2>
4855
4856 <!-- ********** -->
4857
4858 <sect2 id="menc-feat-vcd-dvd-output">
4859 <title>Output Options</title>
4860
4861 <para>
4862 <application>MEncoder</application> has options to control the output
4863 format.
4864 Using these options we can instruct it to create the correct type of
4865 file.
4866 </para>
4867
4868 <para>
4869 The options for VCD and SVCD are called xvcd and xsvcd, because they
4870 are extended formats.
4871 They are not strictly compliant, mainly because the output does not
4872 contain scan offsets.
4873 If you need to generate an SVCD image, you should pass the output file to
4874 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>.
4875 </para>
4876
4877 <para>
4878 VCD:
4879 <screen>-of mpeg -mpegopts format=xvcd</screen>
4880 </para>
4881
4882 <para>
4883 SVCD:
4884 <screen>-of mpeg -mpegopts format=xsvcd</screen>
4885 </para>
4886
4887 <para>
4888 DVD (with timestamps on every frame, if possible):
4889 <screen>-of mpeg -mpegopts format=dvd:tsaf</screen>
4890 </para>
4891
4892 <para>
4893 DVD with NTSC Pullup:
4894 <screen>-of mpeg -mpegopts format=dvd:tsaf:telecine -ofps 24000/1001</screen>
4895 This allows 24000/1001 fps progressive content to be encoded at 30000/1001
4896 fps whilst maintaing DVD-compliance.
4897 </para>
4898
4899
4900 <sect3 id="menc-feat-vcd-dvd-output-aspect">
4901 <title>Aspect Ratio</title>
4902
4903 <para>
4904 The aspect argument of <option>-lavcopts</option> is used to encode
4905 the aspect ratio of the file.
4906 During playback the aspect ratio is used to restore the video to the
4907 correct size.
4908 </para>
4909
4910 <para>
4911 16:9 or "Widescreen"
4912 <screen>-lavcopts aspect=16/9</screen>
4913 </para>
4914
4915 <para>
4916 4:3 or "Fullscreen"
4917 <screen>-lavcopts aspect=4/3</screen>
4918 </para>
4919
4920 <para>
4921 2.35:1 or "Cinemascope" NTSC
4922 <screen>-vf scale=720:368,expand=720:480 -lavcopts aspect=16/9</screen>
4923 To calculate the correct scaling size, use the expanded NTSC width of
4924 854/2.35 = 368
4925 </para>
4926
4927 <para>
4928 2.35:1 or "Cinemascope" PAL
4929 <screen>-vf scale=720:432,expand=720:576 -lavcopts aspect=16/9</screen>
4930 To calculate the correct scaling size, use the expanded PAL width of
4931 1024/2.35 = 432
4932 </para>
4933 </sect3>
4934
4935
4936 <sect3 id="menc-feat-vcd-dvd-a-v-sync">
4937 <title>Maintaining A/V sync</title>
4938
4939 <para>
4940 In order to maintain audio/video synchronization throughout the encode,
4941 <application>MEncoder</application> has to drop or duplicate frames.
4942 This works rather well when muxing into an AVI file, but is almost
4943 guaranteed to fail to maintain A/V sync with other muxers such as MPEG.
4944 This is why it is necessary to append the
4945 <option>harddup</option> video filter at the end of the filter chain
4946 to avoid this kind of problem.
4947 You can find more technical information about <option>harddup</option>
4948 in the section
4949 <link linkend="menc-feat-dvd-mpeg4-muxing-filter-issues">Improving muxing and A/V sync reliability</link>
4950 or in the manual page.
4951 </para>
4952 </sect3>
4953
4954
4955 <sect3 id="menc-feat-vcd-dvd-output-srate">
4956 <title>Sample Rate Conversion</title>
4957
4958 <para>
4959 If the audio sample rate in the original file is not the same as
4960 required by the target format, sample rate conversion is required.
4961 This is achieved using the <option>-srate</option> option and
4962 the <option>-af lavcresample</option> audio filter together.
4963 </para>
4964
4965 <para>
4966 DVD:
4967 <screen>-srate 48000 -af lavcresample=48000</screen>
4968 </para>
4969
4970 <para>
4971 VCD and SVCD:
4972 <screen>-srate 44100 -af lavcresample=44100</screen>
4973 </para>
4974 </sect3>
4975 </sect2>
4976
4977 <!-- ********** -->
4978
4979 <sect2 id="menc-feat-vcd-dvd-lavc">
4980 <title>Using libavcodec for VCD/SVCD/DVD Encoding</title>
4981
4982 <sect3 id="menc-feat-vcd-dvd-lavc-intro">
4983 <title>Introduction</title>
4984
4985 <para>
4986 <systemitem class="library">libavcodec</systemitem> can be used to
4987 create VCD/SVCD/DVD compliant video by using the appropriate options.
4988 </para>
4989 </sect3>
4990
4991
4992 <sect3 id="menc-feat-vcd-dvd-lavc-options">
4993 <title>lavcopts</title>
4994
4995 <para>
4996 This is a list of fields in <option>-lavcopts</option> that you may
4997 be required to change in order to make a complaint movie for VCD, SVCD,
4998 or DVD:
4999 </para>
5000
5001 <itemizedlist>
5002 <listitem><para>
5003 <emphasis role="bold">acodec</emphasis>:
5004 <option>mp2</option> for VCD, SVCD, or PAL DVD;
5005 <option>ac3</option> is most commonly used for DVD.
5006 PCM audio may also be used for DVD, but this is mostly a big waste of
5007 space.
5008 Note that MP3 audio is not compliant for any of these formats, but
5009 players often have no problem playing it anyway.
5010 </para></listitem>
5011 <listitem><para>
5012 <emphasis role="bold">abitrate</emphasis>:
5013 224 for VCD; up to 384 for SVCD; up to 1536 for DVD, but commonly
5014 used values range from 192 kbps for stereo to 384 kbps for 5.1 channel
5015 sound.
5016 </para></listitem>
5017 <listitem><para>
5018 <emphasis role="bold">vcodec</emphasis>:
5019 <option>mpeg1video</option> for VCD;
5020 <option>mpeg2video</option> for SVCD;
5021 <option>mpeg2video</option> is usually used for DVD but you may also use
5022 <option>mpeg1video</option> for CIF resolutions.
5023 </para></listitem>
5024 <listitem><para>
5025 <emphasis role="bold">keyint</emphasis>:
5026 Used to set the GOP size.
5027 18 for 30fps material, or 15 for 25/24 fps material.
5028 Commercial producers seem to prefer keyframe intervals of 12.
5029 It is possible to make this much larger and still retain compatibility
5030 with most players.
5031 A <option>keyint</option> of 25 should never cause any problems.
5032 </para></listitem>
5033 <listitem><para>
5034 <emphasis role="bold">vrc_buf_size</emphasis>:
5035 327 for VCD, 917 for SVCD, and 1835 for DVD.
5036 </para></listitem>
5037 <listitem><para>
5038 <emphasis role="bold">vrc_minrate</emphasis>:
5039 1152, for VCD. May be left alone for SVCD and DVD.
5040 </para></listitem>
5041 <listitem><para>
5042 <emphasis role="bold">vrc_maxrate</emphasis>:
5043 1152 for VCD; 2500 for SVCD; 9800 for DVD.
5044 For SVCD and DVD, you might wish to use lower values depending on your
5045 own personal preferences and requirements.
5046 </para></listitem>
5047 <listitem><para>
5048 <emphasis role="bold">vbitrate</emphasis>:
5049 1152 for VCD;
5050 up to 2500 for SVCD;
5051 up to 9800 for DVD.
5052 For the latter two formats, vbitrate should be set based on personal
5053 preference.
5054 For instance, if you insist on fitting 20 or so hours on a DVD, you
5055 could use vbitrate=400.
5056 The resulting video quality would probably be quite bad.
5057 If you are trying to squeeze out the maximum possible quality on a DVD,
5058 use vbitrate=9800, but be warned that this could constrain you to less
5059 than an hour of video on a single-layer DVD.
5060 </para></listitem>
5061 <listitem><para>
5062 <emphasis role="bold">vstrict</emphasis>:
5063 <option>vstrict</option>=0 should be used to create DVDs.
5064 Without this option, <application>MEncoder</application> creates a
5065 stream that cannot be correctly decoded by some standalone DVD
5066 players.
5067 </para></listitem>
5068 </itemizedlist>
5069 </sect3>
5070
5071
5072 <sect3 id="menc-feat-vcd-dvd-lavc-examples">
5073 <title>Examples</title>
5074
5075 <para>
5076 This is a typical minimum set of <option>-lavcopts</option> for
5077 encoding video:
5078 </para>
5079 <para>
5080 VCD:
5081 <screen>
5082 -lavcopts vcodec=mpeg1video:vrc_buf_size=327:vrc_minrate=1152:\
5083 vrc_maxrate=1152:vbitrate=1152:keyint=15:acodec=mp2
5084 </screen>
5085 </para>
5086
5087 <para>
5088 SVCD:
5089 <screen>
5090 -lavcopts vcodec=mpeg2video:vrc_buf_size=917:vrc_maxrate=2500:vbitrate=1800:\
5091 keyint=15:acodec=mp2
5092 </screen>
5093 </para>
5094
5095 <para>
5096 DVD:
5097 <screen>
5098 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5099 keyint=15:vstrict=0:acodec=ac3
5100 </screen>
5101 </para>
5102 </sect3>
5103
5104
5105 <sect3 id="menc-feat-vcd-dvd-lavc-advanced">
5106 <title>Advanced Options</title>
5107
5108 <para>
5109 For higher quality encoding, you may also wish to add quality-enhancing
5110 options to lavcopts, such as <option>trell</option>,
5111 <option>mbd=2</option>, and others.
5112 Note that <option>qpel</option> and <option>v4mv</option>, while often
5113 useful with MPEG-4, are not usable with MPEG-1 or MPEG-2.
5114 Also, if you are trying to make a very high quality DVD encode, it may
5115 be useful to add <option>dc=10</option> to lavcopts.
5116 Doing so may help reduce the appearance of blocks in flat-colored areas.
5117 Putting it all together, this is an example of a set of lavcopts for a
5118 higher quality DVD:
5119 </para>
5120
5121 <para>
5122 <screen>
5123 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=8000:\
5124 keyint=15:trell:mbd=2:precmp=2:subcmp=2:cmp=2:dia=-10:predia=-10:cbp:mv0:\
5125 vqmin=1:lmin=1:dc=10:vstrict=0
5126 </screen>
5127 </para>
5128 </sect3>
5129 </sect2>
5130
5131 <!-- ********** -->
5132
5133 <sect2 id="menc-feat-vcd-dvd-audio">
5134 <title>Encoding Audio</title>
5135
5136 <para>
5137 VCD and SVCD support MPEG-1 layer II audio, using one of
5138 <systemitem class="library">toolame</systemitem>,
5139 <systemitem class="library">twolame</systemitem>,
5140 or <systemitem class="library">libavcodec</systemitem>'s MP2 encoder.
5141 The libavcodec MP2 is far from being as good as the other two libraries,
5142 however it should always be available to use.
5143 VCD only supports constant bitrate audio (CBR) whereas SVCD supports
5144 variable bitrate (VBR), too.
5145 Be careful when using VBR because some bad standalone players might not
5146 support it too well.
5147 </para>
5148
5149 <para>
5150 For DVD audio, <systemitem class="library">libavcodec</systemitem>'s
5151 AC-3 codec is used.
5152 </para>
5153
5154
5155 <sect3 id="menc-feat-vcd-dvd-audio-toolame">
5156 <title>toolame</title>
5157
5158 <para>
5159 For VCD and SVCD:
5160 <screen>-oac toolame -toolameopts br=224</screen>
5161 </para>
5162 </sect3>
5163
5164
5165 <sect3 id="menc-feat-vcd-dvd-audio-twolame">
5166 <title>twolame</title>
5167
5168 <para>
5169 For VCD and SVCD:
5170 <screen>-oac twolame -twolameopts br=224</screen>
5171 </para>
5172 </sect3>
5173
5174
5175 <sect3 id="menc-feat-vcd-dvd-audio-lavc">
5176 <title>libavcodec</title>
5177
5178 <para>
5179 For DVD with 2 channel sound:
5180 <screen>-oac lavc -lavcopts acodec=ac3:abitrate=192</screen>
5181 </para>
5182
5183 <para>
5184 For DVD with 5.1 channel sound:
5185 <screen>-channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=384</screen>
5186 </para>
5187
5188 <para>
5189 For VCD and SVCD:
5190 <screen>-oac lavc -lavcopts acodec=mp2:abitrate=224</screen>
5191 </para>
5192 </sect3>
5193 </sect2>
5194
5195 <!-- ********** -->
5196
5197 <sect2 id="menc-feat-vcd-dvd-all">
5198 <title>Putting it all Together</title>
5199
5200 <para>
5201 This section shows some complete commands for creating VCD/SVCD/DVD
5202 compliant videos.
5203 </para>
5204
5205
5206 <sect3 id="menc-feat-vcd-dvd-all-pal-dvd">
5207 <title>PAL DVD</title>
5208
5209 <para>
5210 <screen>
5211 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5212 -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
5213 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5214 keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 \
5215 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5216 </screen>
5217 </para>
5218 </sect3>
5219
5220
5221 <sect3 id="menc-feat-vcd-dvd-all-ntsc-dvd">
5222 <title>NTSC DVD</title>
5223
5224 <para>
5225 <screen>
5226 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5227 -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 \
5228 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5229 keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 \
5230 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5231 </screen>
5232 </para>
5233 </sect3>
5234
5235
5236 <sect3 id="menc-feat-vcd-dvd-all-pal-ac3-copy">
5237 <title>PAL AVI Containing AC-3 Audio to DVD</title>
5238
5239 <para>
5240 If the source already has AC-3 audio, use -oac copy instead of re-encoding it.
5241 <screen>
5242 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5243 -vf scale=720:576,harddup -ofps 25 \
5244 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5245 keyint=15:vstrict=0:aspect=16/9 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5246 </screen>
5247 </para>
5248 </sect3>
5249
5250
5251 <sect3 id="menc-feat-vcd-dvd-all-ntsc-ac3-copy">
5252 <title>NTSC AVI Containing AC-3 Audio to DVD</title>
5253
5254 <para>
5255 If the source already has AC-3 audio, and is NTSC @ 24000/1001 fps:
5256 <screen>
5257 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd:tsaf:telecine \
5258 -vf scale=720:480,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:\
5259 vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:aspect=16/9 -ofps 24000/1001 \
5260 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5261 </screen>
5262 </para>
5263 </sect3>
5264
5265
5266 <sect3 id="menc-feat-vcd-dvd-all-pal-svcd">
5267 <title>PAL SVCD</title>
5268
5269 <para>
5270 <screen>
5271 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
5272 scale=480:576,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5273 vcodec=mpeg2video:mbd=2:keyint=15:vrc_buf_size=917:vrc_minrate=600:\
5274 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 25 \
5275 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5276 </screen>
5277 </para>
5278 </sect3>
5279
5280
5281 <sect3 id="menc-feat-vcd-dvd-all-ntsc-svcd">
5282 <title>NTSC SVCD</title>
5283
5284 <para>
5285 <screen>
5286 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
5287 scale=480:480,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5288 vcodec=mpeg2video:mbd=2:keyint=18:vrc_buf_size=917:vrc_minrate=600:\
5289 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 30000/1001 \
5290 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5291 </screen>
5292 </para>
5293 </sect3>
5294
5295
5296 <sect3 id="menc-feat-vcd-dvd-all-pal-vcd">
5297 <title>PAL VCD</title>
5298
5299 <para>
5300 <screen>
5301 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
5302 scale=352:288,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5303 vcodec=mpeg1video:keyint=15:vrc_buf_size=327:vrc_minrate=1152:\
5304 vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 25 \
5305 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5306 </screen>
5307 </para>
5308 </sect3>
5309
5310
5311 <sect3 id="menc-feat-vcd-dvd-all-ntsc-vcd">
5312 <title>NTSC VCD</title>
5313
5314 <para>
5315 <screen>
5316 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
5317 scale=352:240,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5318 vcodec=mpeg1video:keyint=18:vrc_buf_size=327:vrc_minrate=1152:\
5319 vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 30000/1001 \
5320 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5321 </screen>
5322 </para>
5323 </sect3>
5324 </sect2>
5325 </sect1>
5326 </chapter>