1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- synced with 27843 -->
3 <!-- Opiekun: Torinthiel -->
4 <!-- INCOMPLETE!!!! -->
5 <chapter id="encoding-guide">
6 <title>Kodowanie przy użyciu <application>MEncodera</application></title>
8 <sect1 id="menc-feat-dvd-mpeg4">
9 <title>Rippowanie DVD do wysokiej jakości pliku MPEG-4 ("DivX")</title>
12 Jednym z często zadawanych pytań jest "Jak zrobić rip najlepszej jakości
13 przy danej objętości?". Innym pytaniem jest "Jak zrobić najlepszy możliwy
14 rip? Nie ważne jaka będzie objętość, chcę najlepszej jakości."
18 To drugie pytanie jest przynajmniej źle postawione. W końcu, jeśli nie
19 przejmujesz się wielkością pliku, mógłbyć po prostu skopiować strumień
20 MPEG-2 z DVD. Pewnie, dostaniesz AVI wielkości około 5GB, ale jeśli chcesz
21 najlepszej jakości i nie przejmujesz się wielkością to jest to najlepsze
26 Tak na prawdę, powodem dla którego chcesz przekodować DVD na MPEG-4 jest to,
27 że <emphasis role="bold">przejmujesz</emphasis> się wielkością pliku.
31 Ciężko jest pokazać książkowy przepis na tworzenie ripu DVD bardzo wysokiej
32 jakości. Trzeba wziąć pod uwagę kilka czynników, i powinieneś rozumieć
33 szczegóły procesu, albo jest duża szansa że nie będziesz zadowolony z wyników.
34 Poniżej zbadamy niektóre problemy i pokażemy przykład. Zakładamy że używasz
35 <systemitem class="library">libavcodec</systemitem> do kodowania obrazu,
36 chociaż ta sama teoria działą też przy innych kodekach.
40 Jeśli to wydaje Ci się za dużo, to pewnie powinieneś użyć jednej z wielu
42 <ulink url="http://mplayerhq.hu/homepage/design7/projects.html#mencoder_frontends">sekcji MEncodera</ulink>
43 naszej strony z powiązanymi projektami.
44 W ten sposób, powinno się udać otrzymać ripy wysokiej jakości bez zbyt
45 myślenia za dużo, ponieważ te narzędzia są projektowane by podejmować za
51 <sect2 id="menc-feat-dvd-mpeg4-preparing-encode">
52 <title>Przygotowanie do kodowania: Identyfikowanie materiału źródłowego
56 Zanim w ogóle zaczniesz myśleć o kodowaniu filmu, musisz przejść kilka
61 Pierwszym i najważniejszym krokiem przed kodowaniem powinno być
62 ustalenie jakim typem filmu się zajmujesz.
63 Jeśli Twój film jest z DVD albo telewizji (zwykłej, kablowej czy
64 satelitarnej), będzie w jednym z dwóch formatów: NTSC w Ameryce Północnej
65 i Japonii, PAL w Europie itp.
66 Trzeba sobie jednak zdawać sprawę z tego, że jest to tylko format do
67 prezentacji w telewizji, i często <emphasis role="bold">nie</emphasis> jest
68 oryginalnym formatem filmu.
69 Doświadczenie pokazuje że filmy NTSC są trudniejsze do kodowania, ponieważ
70 jest więcej elementów do zidentyfikowania w źródle.
71 Żeby zrobić odpowienie kodowanie musisz znać oryginalny format filmu.
72 Nieuwzględnienie tego skutkuje wieloma wadami wynikowego pliku, na przykład
73 brzydkie artefakty przeplotu i powtórzone albo zagubione klatki.
74 Poza tym że są brzydkie, artefakty są też szkodliwe dla kodowania:
75 Dostaniesz gorszą jakość na jednostkę bitrate.
78 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-fps">
79 <title>Ustalanie źródłowego framerate</title>
81 Poniżej jest lista popularnych typów materiału źródłowego, gdzie można je
82 najczęściej znaleźć i ich własności:
86 <emphasis role="bold">Typowy film</emphasis>: Tworzony do wyświetlania przy
90 <emphasis role="bold">Film PAL</emphasis>: Nagrywany kamerą video PAL
91 z prędkością 50 pól na sekundę.
92 Pole składa się tylko z parzystych albo nieparzystych linii klatki.
93 Telewizja była projektowana by odświerzać je naprzemiennie, w charakterze
94 taniej formy analogowej kompresji.
95 Ludzkie oko podobno kompensuje ten efekt, ale jeśli zrozumiesz przeplot
96 nauczysz się go widzieć też w telewizji i nigdy już nie będziesz z niej
98 Dwa pola <emphasis role="bold">nie</emphasis> dają pełnej klatki, ponieważ
99 są uchwycone co 1/50 sekundy, więc nie pasują do siebie, chyba że nie ma
103 <emphasis role="bold">Film NTSC</emphasis>: Nagrany kamerą NTSC z prędkością
104 60000/1001 pól na sekundę, albo 60 pól na sekundę w erze przedkolorowej.
105 Poza tym podobny do PAL.
108 <emphasis role="bold">Animacja</emphasis>: Zazwyczaj rysowana przy 24fps,
109 ale zdarzają się też z mieszanym framerate.
112 <emphasis role="bold">Grafika komputerowa (CG)</emphasis>: Może być dowolny
113 framerate, ale niektóre są częstsze niż inne; wartości 24 i 30 klatek na
114 sekundę są typowe dla NTSC, a 25fps jest typowe dla PAL.
117 <emphasis role="bold">Stary film</emphasis>: Rozmaite niższe framerate.
123 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-material">
124 <title>Identyfikowanie materiału źródłowego</title>
126 Filmy składające się z klatek nazywa się progresywnymi,
127 podczas gdy te składające się z niezależnych pól nazywa się
128 z przeplotem, albo filmem - chociaż ten drugi termin jest niejasny.
131 Żeby nie było za łatwo, niektóre filmy są kombinacją kilku powyższych typów.
134 Najważniejszą różnicą między tymi formatami, jest to że niektóre są oparte
135 na klatkach a inne na polach.
136 <emphasis role="bold">Zawsze</emphasis> gdy film jest przygotowywany do
137 wyświetlania w telewizji jest przekształcany na format oparty na polach.
138 Rozliczne metody którymi się tego dokonuje są wspólnie nazywane "telecine",
139 a niesławne "3:2 pulldown" z NTSC jest jednym z jego rodzajów.
140 Jeżeli oryginał nie był też oparty na polach (z tą samą prędkością),
141 dostajesz film w innym formacie niż oryginał.
145 <title>Jest kilka popularnych typów pulldown:</title>
147 <emphasis role="bold">pulldown PAL 2:2</emphasis>: Najprzyjemniejszy z nich
149 Każda klatka jest pokazywana przez czas dwóch pól, poprzez wydobycie
150 parzystych i nieparzystych linii i pokazywanie ich na przemian.
151 Jeśli oryginalny materiał miał 24fps, ten proces przyspiesza film o 4%.
154 <emphasis role="bold">pulldown PAL 2:2:2:2:2:2:2:2:2:2:2:3</emphasis>:
155 Każda 12ta klatka jest pokazywana przez czas trzech pól zamiast tylko dwóch.
156 Dzięki temu nie ma przyspieszenia o 4%, ale proces jest o wiele trudniejszy
158 Zazwyczaj występuje w produkcjach muzycznych, gdzie zmiana prędkości o 4%
159 poważnie by uszkodziła muzykę.
162 <emphasis role="bold">NTSC 3:2 telecine</emphasis>: Klatki są pokazywane na
163 przemian przez czas 3ch albo 2ch pól.
164 To daje częstotliwość pól 2.5 raza większą niż oryginalna częstotliwość
165 klatek. Rezultat jest też lekko zwolniony z 60 pól na sekundę do 60000/1001
166 pól na sekundę by utrzymać częstotliwość pól w NTSC.
169 <emphasis role="bold">NTSC 2:2 pulldown</emphasis>: Używane do pokazywania
170 materiałów 30fps na NTSC.
171 Przyjemne, tak jak pulldown 2:2 PAL.
176 Są też metody konwersji między filmami PAL i NTSC, ale ten temat
177 wykracza poza zakres tego podręcznika.
178 Jeśli natkniesz się na taki film i chcesz go zakodować, to największe
179 szanse masz robiąc kopię w oryginalnym formacie.
180 Konwersja między tymi dwoma formatami jest wysoce destrukcyjna i nie może
181 zostać ładnie odwrócona, więc kodowanie będzie o wiele gorszej jakości jeśli
182 jest robione z przekonwertowanego źródła.
186 Gdy film jest zapisywany na DVD, kolejne pary pól są zapisywane jako klatka,
187 pomimo tego że nie są przezaczone do wyświetlania razem.
188 Standard MPEG-2 używany na DVD i w cyfrowej TV pozwala na zakodowanie
189 oryginalnej progresywnej klatki i na przechowanie w nagłówku klatki ilości
190 pól przez które ta klatka powinna być pokazana.
191 Filmy zrobione przy użyciu tej metody są często określane mianem "miękkiego
192 telecine" (soft-telecine), ponieważ proces ten tylko informuje odtwarzacz że
193 ma on zastosować pulldown, a nie stosuje go samemu.
194 Tak jest o wiele lepiej, ponieważ może to zostać łatwo odwrócone (a tak na
195 prawdę zignorowane) przez koder i ponieważ zachowuje możliwie najwyższą
197 Niestety, wielu producentów DVD i stacji nadawczych nie stosuje prawidłowych
198 technik kodowania ale w zamian produkuje filmy przy użyciu "twardego
199 telecine" (hard-telecine), gdzie pola są faktycznie powtórzone
200 w zakodowanym MPEG-2.
204 Procedury radzenia sobie z takimi przypadkami będą omówione
205 <link linkend="menc-feat-telecine">w dalszej części przewodnika</link>.
206 Teraz podamy tylko kilka wskazówek jak identyfikować z jakim typem materiału
211 <title>Regiony NTSC:</title>
213 Jeśli <application>MPlayer</application> wyświetla w trakcie oglądania filmu
214 że framerate zostało zmienione na 24000/1001 i nigdy nie powraca, to jest
215 to prawie na pewno progresywny materiał na którym zastosowano "miękkie
219 Jeśli <application>MPlayer</application> pokazuje że framerate zmienia się
220 między 24000/1001 i 30000/1001 i czasami widzisz "grzebienie" to jest kilka
222 <!-- Torinthiel: grzebienie mi najlepiej pasują, ale może jest oficjalne tłumaczenie -->
223 Kawałki 24000/1001fps są prawie na pewno progresywne, poddane "miękkiemu
224 telecine", ale fragmenty 30000/1001 fps mogą albo być 24000/1001 poddanym
225 "twardemu telecine" albo filmem NTCS o 60000/1001 polach na sekundę.
226 Używaj tych samych metod co w następnych dwóch przypadkach żeby je odróżnić.
229 Jeśli <application>MPlayer</application> nigdy nie pokazuje informacji
230 o zmianie framerate i każda klatka z ruchem wygląda jak grzebień, to masz
231 film NTSC z 60000/1001 polami na sekundę.
234 Jeśli <application>MPlayer</application> nigdy nie pokazuje informacji
235 o zmianie framerate i dwie klatki z każdych pięciu mają grzebienie, to film
236 jest 24000/1001 fps poddanym "twardemu telecine".
241 <title>Regiony PAL:</title>
243 Jeśli nie widzisz grzebieni, to jest to 2:2 pulldown.
246 Jeśli na przemian przez pół sekundy widzisz grzebienie a potem nie, to masz
247 2:2:2:2:2:2:2:2:2:2:2:3 pulldown.
250 Jeśli zawsze widzisz grzebienie w trakcie ruchu, to film jest filmem PAL
251 wyświetlanym z 50 polami na sekundę.
252 <!-- Torinthiel: wyświetlanym czy nagranym? -->
256 <note><title>Podpowiedź:</title>
258 <application>MPlayer</application> może zwolnić odtwarzanie filmu opcją
259 -speed albo odtwarzać klatka po klatce.
260 Spróbuj użyć opcji <option>-speed</option> 0.2 żeby oglądać film bardzo
261 wolno, albo naciskaj wielokrotnie klawisz "<keycap>.</keycap>" żeby
262 wyświetlać klatka po klatce.
263 Może to pomóc zidentyfikować wzorzec jeśli
264 nie możesz go dostrzec przy pełnej prędkości.
272 <sect2 id="menc-feat-dvd-mpeg4-2pass">
273 <title>Stały kwantyzator a tryb wieloprzebiegowy</title>
276 Jest możliwe zakodowanie filmu z szeroką gamą jakości.
277 Z nowoczesnymi koderami i odrobiną kompresji przed kodekiem (zmniejszenie
278 rozdzielczości i usuwanie szumu), możliwe jest osiągnięcie bardzo dobrej
279 jakości przy 700 MB, dla 90-110 minutowego filmu kinowego.
280 Dodatkowo tylko najdłuższe filmy nie dają się zakodować na 1400 MB z prawie
285 Są trzy podejścia do kodowania video: stały bitrate (CBR),
286 stały kwantyzator i tryb wieloprzebiegowy (ABR, uśrednione bitrate).
290 Złożoność klatek filmu, a zatem i ilość bitów potrzebna na ich zakodowanie,
291 może się bardzo mocno zmieniać w zależności od sceny.
292 Nowoczesne kodery potrafią się dostosowywać do tych zmian i zmieniać
294 Jednak w prostych trybach, takich jak CBR, kodery nie znają zapotrzebowania
295 na bitrate w przyszłych scenach, więc nie mogą na długo przekraczać
297 Bardziej zaawansowane tryby, takie jak kodowanie wieloprzebiegowe, potrafią
298 wziąć pod uwagę statystyki z poprzednich przebiegów, co naprawia ten problem.
301 <note><title>Uwaga:</title>
303 Większość kodeków obsługujących kodowanie ABR obsługuje tylko kodowanie
304 dwuprzebiegowe, podczas gdy niektóre inne, na przykład
305 <systemitem class="library">x264</systemitem> albo
306 <systemitem class="library">Xvid</systemitem> potrafią wykonywać wiele
307 przebiegów, z lekką poprawą jakości po każdym przebiegu. Jednak ta poprawa
308 nie jest zauważalna ani mierzalna po około 4tym przebiegu.
309 Dlatego też, w tej części, tryb dwuprzebiegowy i wieloprzebiegowy będą
315 W każdym z tych trybów, kodek video (na przykład
316 <systemitem class="library">libavcodec</systemitem>)
317 dzieli klatkę obrazu na makrobloki 16x16 pikseli i stosuje do każdego z nich
318 kwantyzator. Im niższy kwantyzator, tym lepsza jakość i tym wyższe bitrate.
319 Metody jakiej koder używa do ustalenia kwantyzatora są różne i można nimi
320 sterować. (Jest to straszliwe uproszczenie, ale wystarcza do zrozumienia
325 Kiedy podajesz stałe bitrate, kodek koduje usuwając tyle szczegółów ile musi
326 i tak mało jak to tylko możliwe żeby pozostać poniżej podanego bitrate.
327 Jeśli na prawdę nie obchodzi cię wielkość pliku, możesz użyć CBR i podać
328 nieskończone bitrate (W praktyce oznacza to bitrate na tyle wysokie że nie
329 stanowi bariery, na przykład 10000Kbit.) Bez żadnego ograniczenia na bitrate
330 kodek użyje najniższego możliwego kwantyzatora do każdej klatki (ustalonego
331 dla <systemitem class="library">libavcodec</systemitem> opcją
332 <option>vqmin</option>, domyślnie 2).
333 Gdy tylko podasz bitrate na tyle niskie że kodek musi używać wyższego
334 kwantyzatora, to prawie na pewno niszczysz film.
335 Żeby tego uniknąć, powinieneś pewnie zmniejszyć rozdzielczość filmu, metodą
337 Ogólnie, jeśli zależy Ci na jakości, powinieneś unikać CBR.
341 Przy stałym kwantyzatorze, kodek używa na każdym makrobloku tego samego
342 kwantyzatora, podanego opcją <option>vqscale</option>
343 (w przypadku <systemitem class="library">libavcodec</systemitem>).
344 Jeśli chcesz możliwie najlepszy efekt, znów ignorując bitrate, możesz użyć
345 <option>vqscale=2</option>. Da to ten sam bitrate i PSNR (peak
346 signal-to-noise ratio, szczytowa proporcja sygnału do szumu) co CBR
347 z <option>vbitrate</option>=nieskończoność i domyślnym
348 <option>vqmin</option>.
352 Problemem przy stałym kwantyzatorze jest to, że używa podanego kwantyzatora
353 niezależnie od tego czy makroblok tego wymaga czy nie. To znaczy że można by
354 było zastosować do makrobloku wyższy kwantyzator bez utraty postrzegalnej
355 jakości. Dlaczego marnować bity na niepotrzebnie niski kwantyzator?
356 Mikroprocesor ma tyle cykli ile jest czasu, ale jest tylko ograniczona ilość
357 bitów na twardym dysku.
361 Przy kodowaniu dwuprzebiegowym, pierwszy przebieg potraktuje film jak przu
362 ustawieniu CBR, ale zachowa informacje o własnościach każdej klatki. Te dane
363 są później używane przy drugim przebiegu do podejmowania słusznych decyzji
364 o używanym kwantyzatorze. Przy szybkich scenach albo niewielu szczegółach
365 pewnie użyje większego kwantyzatora, podczas gdy dla powolnych,
366 szczegółowych scen będzie niższy kwantyzator.
370 Jeśli używasz <option>vqscale=2</option> to marnujesz bity. Jeśli używasz
371 <option>vqscale=3</option> to nie dostajesz najlepszej możliwej jakości.
372 Załóżmy że zakodowałeś swoje DVD przy <option>vqscale=3</option>
373 i dostałeś bitrate 1800Kbit. Jeśli zrobisz dwa przebiegi
374 z <option>vbitrate=1800</option> ostateczny wynik będzie miał
375 <emphasis role="bold">wyższą jakość</emphasis> przy
376 <emphasis role="bold">tym samym bitrate</emphasis>.
380 Ponieważ jesteś już przekonany że prawidłowym wyborem są dwa przebiegi,
381 prawdziwym pytaniem jest jakiego bitrate użyć. Nie ma jednej odpowiedzi.
382 Idealnie chcesz wybrać bitrate będący najlepszym kompromisem między jakością
383 a wielkością pliku. To się zmienia w zależności od filmu.
387 Jeśli wielkość nie ma znaczenia, dobrym punktem wyjściowym do bardzo
388 wysokiej jakości jest około 2000Kbit plus minus 200Kbit.
389 Jeśli jest dużo akcji albo szczegółów, albo po prostu masz bardzo wrażliwe
390 oko, możesz się zdecydować na 2400 albo 2600.
391 Przy niektórych DVD możesz nie zauważyć różnicy przy 1400Kbit. Dobrym
392 pomysłem jest poeksperymentowanie z kilkoma scenami i różnymi wartościami
393 bitrate żeby nabrać wyczucia.
397 Jeśli chcesz konkretnej wielkości, musisz jakoś obliczyć bitrare.
398 Ale zanim to zrobisz, musisz wiedzieć ile miejsca potrzebujesz na dźwięk,
399 więc powinieneś <link linkend="menc-feat-dvd-mpeg4-audio">ściągnąć go</link>
401 Możesz wyliczyć bitrate z następującego równania:
402 <systemitem>bitrate = (wielkość_docelowa_w_MBajtach - wielkość_dźwięku_w_MBajtach)
403 * 1024 * 1024 / długość_w_sekundach * 8 / 1000</systemitem>
404 Na przykład by wcisnąć dwugodzinny film na płytkę 702MB, z 60MB ścieżki
405 dźwiękowej, bitrate video musi być:
406 <systemitem>(702 - 60) * 1024 * 1024 / (120*60) * 8 / 1000
407 = 740kbps</systemitem>
413 <sect2 id="menc-feat-dvd-mpeg4-constraints">
414 <title>Ograniczenia efektywnego kodowania</title>
417 Ze względu na naturę kodowania typu MPEG istnieją różne ograniczenia których
418 warto się trzymać żeby osiągnąć najlepszą jakość.
419 MPEG dzieli obraz na kwadraty 16x16 pikseli nazywane makroblokami,
420 każdy z nich składa się z 4 bloków 8x8 informacji o jasności (luminancja, luma)
421 i dwóch 8x8 z połową rozdzielczości (jeden na składową czerwono-morską, drugi
423 Nawet jeśli wysokość i szerokość filmu nie są wielokrotnościami 16,
424 koder użyje tyle makrobloków żeby przykryć cały obszar obrazu,
425 dodatkowa przestrzeń zostanie zmarnowana.
426 Zatem w interesie zwiększenai jakości przy utrzymaniu wielkości pliku kiepskim
427 pomysłem jest używanie wymiarów które nie są wielokrotnością 16.
431 Większość DVD ma też jakieś czarne ramki na brzegach.
432 Zostawienie ich tam <emphasis role="bold">mocno</emphasis> zaszkodzi jakości
439 Kompresje typu MPEG są zależne od transformat przestrzeni częstotliwości,
440 a dokładniej Dyskretnej Transformaty Cosinusowej (DCT), która jest podobna do
441 transformaty Fouriera.
442 Ten sposób kodowania jest efektywny przy wzorach i gładkich przejściach, ale
443 kiepsko sobie radzi z ostrymi krawędziami.
444 Żeby je zakoować, musi używać o wiele większej liczby bitów, albo wystąpią
445 artefakty znane jako pierścienie.
449 Transformacja częstotliwości (DCT) jest stosowana osobno do każdego
450 makrobloku (tak na prawdę do każdego bloku), więc ten problem istnieje tylko
451 gdy ostra krawędź jest wewnątrz bloku.
452 Jeśli czarna ramka zaczyna się dokładnie na krawędzi 16-pikselowego bloku,
453 nie stwarza problemów.
454 Jednakże, rzadko kiedy takie ramki są ładnie wyrównane, więc zazwyczaj będzie
455 trzeba przyciąć obraz żeby tego uniknąć.
461 Poza transformatami przestrzeni częstotliwości, kompresje typu MPEG używają
462 wektorów ruchu, by reprezentować zmiany między sąsiednimi klatkami.
463 Oczywiście wektory ruchu są mniej efektywne w stosunku do nowej treści
464 przychodzącej z brzegów obrazka, ponieważ nie było jej na poprzedniej klatce.
465 Jeśli obraz rozciąga się do krawędzi zakodowanego regionu,
466 wektory ruchu radzą sobie z treścią wychodzącą poza krawędzie.
467 Jednak jeśli są ramki, mogą być kłopoty:
470 <orderedlist continuation="continues">
473 Dla każdego makrobloku, kompresja typu MPEG przechowuje wektor opisujący
474 która część poprzedniej klatki powinna być skopiowana do tego makrobloku jako
475 podstawa do przewidzenia następnej klatki.
476 Zakodowane wtedy muszą być tylko różnice.
477 Jeśli makroblok zawiera fragment ramki, to wektory ruchu z pozostałych cześci
478 obrazu zamażą obramowanie.
479 Oznacza to że dużo bitów będzie zużytych albo na jej powtórne zaczernienie
480 albo (co bardziej prawdopodobne), wektor ruchu w ogóle nie będzie użyty
481 i wszystkie zmiany w tym makrobloku będzie trzeba zakodować bezpośrednio.
482 W obu przypadkach, bardzo cierpi na tym efektywność kodowania.
486 Powtórnie, ten problem występuje tylko jeśli ramki nie są na krawędziach
487 16-pikselowych bloków.
493 W końcu, przypuśćmy że mamy makroblok wewnątrz obrazu i obiekt dostaje się do
494 niego z okolic krawędzi.
495 Kodowanie typu MPEG nie potrafi powiedzieć "skopiuj część która jeest
496 wewnątrz obraka, ale nie czarne obramowanie." Dlatego obramowanie też
497 zostanie skopiowane i trzeba będzie zużyć sporo bitów żeby zakodować fragment
498 obrazu który powinien tam być.
502 Jeśli obraz sięga do krawędzi zakodowanego obszaru, MPEG ma specjalne
503 optymalizacje do wielokrotnego kopiowania ostatniego rzędu pikseli jeśli
504 wektor ruchu przychodzi z poza zakodoanego obszaru.
505 Staje się to bezużyteczne gry obraz ma czarne obramowanie.
506 W odróżnieniu od problemów 1 i 2 tutaj nic nie pomoże ustawienie obramowania
507 w odpowiednim miejscu.
512 Mimo tego, że obramowanie jest całkowicie czarne i nigdy się nie zmienia,
513 zawsze jest pewien narzut związany z większą ilością makrobloków.
518 Ze wszystkich tych powodów zalecane jest całkowite wycięcie czarnych obramowań.
519 Dodatkowo, jeśli przy krawędziach jest obszar zakłóceń/zniekształceń, obcięcie
520 go również poprawi efektywność kodowania.
521 Puryści, którzy chcą możliwie dokładnie zachować oryginał mogą się sprzeciwiać,
522 ale jeśli nie planujesz używać stałego kwantyzatora to jakość uzyskana dzięki
523 skadrowaniu znacząco przewyższy utratę informacji przy brzegach.
529 <sect2 id="menc-feat-dvd-mpeg4-crop">
530 <title>Kadrowanie i skalowanie</title>
533 Przypomnijmy z poprzedniej części że ostateczna wielkość (wysokość i szerokość)
534 obrazu do kodowania powinna być wielokrotnością 16.
535 Można to osiągnąć kadrowaniem, skalowaniem albo kombinacją obydwu.
539 Przy kadrowaniu, jest kilka reguł których musimy przestrzegać by uniknąć
541 Zwykły format YUV, 4:2:0, przechowuje wartości koloru podpróbkowane, czyli
542 kolor jest próbkowany o połowę rzadziej w każdym kierunku niż jasność.
543 Spójrzmy na diagram, na którym L oznacza punkty próbkowania jasności (luma)
548 <?dbhtml table-width="40%" ?>
549 <?dbfo table-width="40%" ?>
550 <tgroup cols="8" align="center">
551 <colspec colnum="1" colname="col1"/>
552 <colspec colnum="2" colname="col2"/>
553 <colspec colnum="3" colname="col3"/>
554 <colspec colnum="4" colname="col4"/>
555 <colspec colnum="5" colname="col5"/>
556 <colspec colnum="6" colname="col6"/>
557 <colspec colnum="7" colname="col7"/>
558 <colspec colnum="8" colname="col8"/>
559 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
560 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
561 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
562 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
575 <entry spanname="spa1-2">C</entry>
576 <entry spanname="spa3-4">C</entry>
577 <entry spanname="spa5-6">C</entry>
578 <entry spanname="spa7-8">C</entry>
601 <entry spanname="spa1-2">C</entry>
602 <entry spanname="spa3-4">C</entry>
603 <entry spanname="spa5-6">C</entry>
604 <entry spanname="spa7-8">C</entry>
621 Jak widać, wiersze i kolumny obrazu w sposób naturalny łączą się w pary.
622 Dlatego przesunięcia i wymiary kadrowania <emphasis>muszą</emphasis> być
624 Jeśli nie są, barwa nie będzie już dobrze dopasowana do jasności.
625 Teoretycznie możliwe jest kadrowanie z nieparzystym przesunięciem, ale wymaga
626 to przepróbkowania kolorów, co jest potencjalnie stratną operacją nie
627 obsługiwaną przez filtr kadrowania.
631 Dalej, film z przeplotem jest kodowany jak poniżej:
635 <?dbhtml table-width="80%" ?>
636 <?dbfo table-width="80%" ?>
637 <tgroup cols="16" align="center">
638 <colspec colnum="1" colname="col1"/>
639 <colspec colnum="2" colname="col2"/>
640 <colspec colnum="3" colname="col3"/>
641 <colspec colnum="4" colname="col4"/>
642 <colspec colnum="5" colname="col5"/>
643 <colspec colnum="6" colname="col6"/>
644 <colspec colnum="7" colname="col7"/>
645 <colspec colnum="8" colname="col8"/>
646 <colspec colnum="9" colname="col9"/>
647 <colspec colnum="10" colname="col10"/>
648 <colspec colnum="11" colname="col11"/>
649 <colspec colnum="12" colname="col12"/>
650 <colspec colnum="13" colname="col13"/>
651 <colspec colnum="14" colname="col14"/>
652 <colspec colnum="15" colname="col15"/>
653 <colspec colnum="16" colname="col16"/>
654 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
655 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
656 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
657 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
658 <spanspec spanname="spa9-10" namest="col9" nameend="col10"/>
659 <spanspec spanname="spa11-12" namest="col11" nameend="col12"/>
660 <spanspec spanname="spa13-14" namest="col13" nameend="col14"/>
661 <spanspec spanname="spa15-16" namest="col15" nameend="col16"/>
664 <entry namest="col1" nameend="col8">Górne pole</entry>
665 <entry namest="col9" nameend="col16">Dolne pole</entry>
686 <entry spanname="spa1-2">C</entry>
687 <entry spanname="spa3-4">C</entry>
688 <entry spanname="spa5-6">C</entry>
689 <entry spanname="spa7-8">C</entry>
744 <entry spanname="spa9-10">C</entry>
745 <entry spanname="spa11-12">C</entry>
746 <entry spanname="spa13-14">C</entry>
747 <entry spanname="spa15-16">C</entry>
786 <entry spanname="spa1-2">C</entry>
787 <entry spanname="spa3-4">C</entry>
788 <entry spanname="spa5-6">C</entry>
789 <entry spanname="spa7-8">C</entry>
844 <entry spanname="spa9-10">C</entry>
845 <entry spanname="spa11-12">C</entry>
846 <entry spanname="spa13-14">C</entry>
847 <entry spanname="spa15-16">C</entry>
872 Jak widać, wzór powtarza się dopiero po 4 liniach.
873 Dlatego przy filmie z przeplotem, pionowa współrzędna i wysokość kadrowania
874 muszą być wielokrotnościami 4.
878 Podstawową rozdzielczością DVD jest 720x480 dla NTSC i 720x576 dla PAL, ale
879 jest też flaga proporcji, która określa czy obraz jest ekranowy (4:3) czy
881 Wiele (jeśli nie większość) panoramicznych DVD nie jest dokładnie 16:9 tylko
882 raczej 1,85:1 lub 2,35:1 (cinescope).
883 Oznacza to że będzie czarne obramowanie na filmie, które trzeba usunąć.
887 <application>MPlayer</application> dostarcza filtr wykrywania kadrowania
888 (<option>-vf cropdetect</option>), który określi prostokąt kadrowania.
889 Uruchom <application>MPlayera</application> z opcją <option>-vf
890 cropdetect</option> a wydrukuje on ustawienia kadrowania potrzebne do usunięcia
892 Powinieneś puścić film wystarczająco długo żeby został użyty cały obszar
893 obrazu, inaczej wartości będą niedokładne.
897 Potem przetestuj otrzymane wartości z użyciem
898 <application>MPlayera</application>, przekazując opcje podane przez
899 <option>cropdetect</option> i dostosowując prostokąt według potrzeb.
900 Filtr <option>rectangle</option> może w tym pomóc, pozwalając na interaktywne
901 ustawienie prostokąta kadrowania na filmie.
902 Pamiętaj, by trzymać się powyższych reguł podzielności, żeby nie przestawić
907 W pewnych przypadkach skalowanie może być niepożądane.
908 Skalowanie w kierunku pionowym jest trudne przy filmie z przeplotem, a jeśli
909 chcesz zachować przeplot, zazwyczaj powinieneś się wstrzymać od skalowania.
910 Jeśl nie chcesz skalować, ale nadal chcesz używać wymiarów będących wielokrotnościami 16 to musisz przekadrować.
911 NIe należy niedokadrowywać, bo obramowania są bardzo szkodliwe przy kodowaniu!
915 Ponieważ MPEG-4 używa makrobloków 16x16, powinieneś się upewnić,
916 że każdy wymiar kodowanego filmu jest wielokrotnością 16, inaczej
917 degradujemy jakość, zwłaszcza przy niższych bitrate.
918 Można tego dokonać zaokrąglając wysokość i szerokość prostokąta kadrowania do
919 najbliższej wielokrotności 16.
920 Jak powiedziano wcześniej, trzeba zwiększyć przesunięcie
921 pionowe o połowę różnicy między starą a nową wysokością,
922 żeby wynikowy film był brany ze środka klatki.
923 A ze względu na sposób w jaki próbkowane jest DVD, upewnij się że przesunięcie
924 jest parzyste (w zasadzie, stosuj się do reguły, żeby nigdy nie używać
925 nieparzystych wartości przy przycinaniu i skalowaniu obrazu).
926 Jeśli nie czujesz się dobrze odrzucając dodatkowe piksele,
927 może wolisz przeskalować video.
928 Przyjżymy się temu w przykładzie poniżej.
929 Możesz też pozwolić filtrowi <option>cropdetect</option> zrobić to wszystko za
930 Ciebie, jako że ma on opcjonalny parametr <option>round</option>
931 (zaokrąglenie), domyślnie równy 16.
935 Uważaj też na "poł-czarne" piksele na przegach. Też je wykadruj, albo będziesz
936 na nie marnował bity któ?e przydadzą się gdzie indziej.
940 Po tym wszystkim prawdopodobnie dostaniesz film który nie ma dokładnie
941 proporcji 1,85:1 ani 2,35:1 tylko coś podobnego.
942 Mógłbyś samemu policzyć nowe proporcje, ale <application>MEncoder</application>
943 ma pocję do <systemitem class="library">libavcodec</systemitem> nazywaną
944 <option>autoaspect</option> która zrobi to za Ciebie.
945 Nie powinieneś przeskalowywać video żeby wyrównać piksele, chyba że chcesz
946 marnować miejsce na dysku.
947 Skalowanie powinno być robione przy odtwarzaniu, a odtwarzacz używa informacji
948 o proporcjach zapisanych w AVI żeby określić prawidłową rozdzielczość.
949 Niestety, nie wszystkie odtwarzacze uznają te informacje,
950 dlatego mimo wszystko możesz chcieć przeskalować.
956 <sect2 id="menc-feat-dvd-mpeg4-resolution-bitrate">
957 <title>Dobieranie rozdzielczości i bitrate</title>
960 Jeśli nie kodujesz w trybie stałego kwantyzatora, musisz wybrać bitrate.
961 Jest to dość prosta rzecz – to (średnia) ilość bitów jaka będzie
962 używana do zakodowania jednej sekundy filmu.
963 Zazwyczaj bitrate mierzy się w kilobitach (1000 bitów) na sekundę.
964 Wielkość filmu na dysku to bitrate razy długość filmu,
965 plus drobne "dodatki" (patrz na przykład sekcja o
966 <link linkend="menc-feat-dvd-mpeg4-muxing-avi-limitations">kontenerze AVI</link>
968 Pozostałe parametry, takie jak skalowanie, kadrowanie itp.
969 <emphasis role="bold">nie</emphasis> zmienią wielkości pliku jeśli nie
970 zmienisz też bitrate!
974 Bitrate <emphasis role="bold">nie</emphasis> skaluje się proporcjonalnie do
976 To znaczy, film 320x240 w 200 kbit/s nie będzie tej samej jakości co ten sam
977 film w 640x480 i 800 kbit/s!
978 Są ku temu dwie przyczyny:
981 <emphasis role="bold">Wizualna</emphasis>: Łatwiej zauważyć artefakty MPEG
982 jeśli są bardziej powiększone!
983 Artefakty powstają na poziomie bloków (8x8).
984 Ludzkie oko trudniej dostrzega błędy w 4800 małych blokach niż w 1200 dużych
985 (zakładając że skalujesz na pełny ekran).
988 <emphasis role="bold">Teoretyczna</emphasis>: Kiedy zmniejszasz obraz ale
989 nadal używasz tych samych bloków 8x8 do transformacji przestrzeni
990 częstotliwości. masz więcej danych w pasmach wyższych częstotliwości.
991 W pewien sposób każdy piksel ma więcej szczegółów niż poprzednio.
992 Dlatego, mimo że przeskalowany obraz zawiera 1/4 informacji jeśli chodzi
993 o wielkość, to nadal może zawierać większość informacji w przestrzeni
994 częstotliwości (zakładając że wysokie częstotliwości były mało używane
995 w oryginalnym filmie 640x480).
1001 Poprzednie podręczniki zalecały dobranie bitrate i rozdzielczości w sposób
1002 bazujący na podejściu "bity na piksel", ale z powyższych powodów zazwyczaj nie
1004 Lepszym przybliżeniem zdaje się skalowanie bitrate proporcjonalnie do
1005 pierwiastka kwadratowego z rozdzielczości, czyli film 320x240 i 400 kbit/s
1006 powinien być podobny do 640x480 i 800 kbit/s.
1007 Nie zostało to jednak zweryfikowane ani teoretycznie ani empirycznie.
1008 Dodatkowo, ponieważ filmy są bardzo zróżnicowane jeśli chodzi o szum,
1009 szczegóły, ilość ruchu itp. bezsensowne jest podawanie ogólnych zaleceń na bity
1010 na przekątą (analogia bitów na piksel używająca pierwiastka).
1013 Omówiliśmy więc problemy z wyborem bitrate i rozdzielczości.
1017 <sect3 id="menc-feat-dvd-mpeg4-resolution-bitrate-compute">
1018 <title>Obliczanie rozdzielczości</title>
1021 Następne kroki przeprowadzą Cię przez obliczenie rozdzielczości dla Twojego
1022 filmu bez zniekształcania go za bardzo, biorąc pod uwagę kilka typów informacji
1024 Najpierw powinieneś policzyć zakodowane proporcje:
1025 <systemitem>ARc = (Wc x (ARa / PRdvd )) / Hc</systemitem>
1028 <title>gdzie:</title>
1030 Hc i Wc to wysokość i szerokość skadrowanego filmu.
1033 ARa do wyświetlane proporcje, zazwyczaj 4/3 lub 16/9.
1036 PRdvd to proporcje na DVD równe 1,25=(720*576) dla DVD PAL i 1,5=(720/480) dla
1043 Potem możesz policzyć rozdzielczość X i Y, zgodnie z dobranym wskażnikiem
1044 Jakości Kompresji (Compression Quality, CQ):
1045 <systemitem>RozY = INT(Pierw( 1000*Bitrate/25/ARc/CQ )/16) * 16</systemitem>
1047 <systemitem>RozX = INT( ResY * ARc / 16) * 16</systemitem>,
1048 gdzie INT oznacza zaokrąglenie do liczby całkowitej.
1052 Dobrze, ale co to jest CQ?
1053 CQ reprezentuje ilość bitów na piksel i klatkę kodowania.
1054 Z grubsza biorąc, im większe CQ tym mniejsza szansa na zobaczenie artefaktów
1056 Jednakże, jeśli masz docelową wielkość filmu (na przykład 1 lub 2 płyty CD),
1057 masz ograniczoną ilość bitów do zużycia; dlatego musisz znaleźć równowagę
1058 między poziomem kompresji i jakością.
1062 CQ zależy od bitrate, efektywności kodeka video i rozdzielczości filmu.
1063 Żeby podnieść CQ zazwyczej zmniejszysz film, ponieważ bitrate jest funkcją docelowej wielkości i długości filmu, które są stałe.
1064 Przy użyciu kodeków MPEG-4 ASP, takich jak
1065 <systemitem class="library">Xvid</systemitem> i
1066 <systemitem class="library">libavcodec</systemitem>, CQ niższe niż 0,18
1067 zazwyczaj daje kiepski obraz, ponieważ nie ma dość bitów by zakodować
1068 informacje z każdego makrobloku.
1069 (MPEG4, jak wiele innych kodeków, grupuje piksele w bloki żeby
1070 skompresować obraz. Jeśli nie ma dość bitów widać krawędzie tych bloków.)
1071 Dlatego też mądrze jest wybrać CQ w zakresie 0,20 do 0,22 na film jednopłytkowy
1072 i 0,26-0,28 na dwupłytkowy przy standardowych opcjach kodowania.
1073 Bardziej zaawansowane opcje kodowania, takie jak te podane tutaj dla
1074 <link linkend="menc-feat-mpeg4-lavc-example-settings"><systemitem class="library">libavcodec</systemitem></link>
1076 <link linkend="menc-feat-xvid-example-settings"><systemitem class="library">Xvid</systemitem></link>
1077 powinny umożliwić otrzymanie takiej samej jakości z CQ w zakresie 0,18 do 0,20
1078 na 1 CD i 0,24 do 0,26 na 2 CD.
1079 Z kodekami MPEG-4 AVC, takimi jak
1080 <systemitem class="library">x264</systemitem>, możesz używać CQ w zakresie
1081 0,14 do 0,16 przy standardowych opcjach
1082 a powinno się też udać zejść do 0,10 do 0,12 z
1083 <link linkend="menc-feat-x264-example-settings">zaawansowanymi opcjami kodowania <systemitem class="library">x264</systemitem></link>.
1087 Pamiętajmy, że CQ jest tylko przydatnym odnośnikiem, zależnym od kodowanego
1088 filmu. CQ równe ,018 może wyglądać dobrze przy Bergmanie, w przeciwieństwie do
1089 filmu takiego jak Martix, który zaawiera wiele bardzo ruchliwych scen.
1090 Z drugiej strony, bezsensowne jest podnoszenie CQ powyżej 0,30 jako że marnuje się bity bez zauważalnej poprawy jakości.
1091 Pamiętajmy też że, jak było wspomniane wcześniej, filmy w niższej
1092 rozdzielczości potrzebują większego CQ (w porównaniu do na przykład
1093 rozdzielczości DVD) żeby dobrze wyglądać.
1100 <sect2 id="menc-feat-dvd-mpeg4-filtering">
1101 <title>Filtrowanie</title>
1104 Bardzo ważne do robienia dobrych kodowań jest nauczenie się posługiwania
1105 systemem filtrów <application>MEncodera</application>.
1106 Całe przetwarzanie video jest wykonywane przez filtry – kadrowanie, skalowanie,
1107 dopasowywanie kolorów, usuwanie szumu, telecine, odwrócone telecine, usuwanie
1108 bloków żeby wymienić choć część.
1109 Poza dużą ilością obsługiwanych formatów wejściowych to właśnie zakres
1110 dostępnych filtrów jest jedną z głównych przewag
1111 <application>MEncodera</application> nad podobnymi programami.
1115 Filtry są ładowane do łańcucha przy pomocy opcji -vf:
1117 <screen>-vf filtr1=opcje,filtr2=opcje,...</screen>
1119 Większość filtrów przyjmuje kilka parametrów numerycznych oddzielanych
1120 dwukropkami, ale dokładna składnia zależy od filtru więc szczegóły odnośnie
1121 filtrów, które chcesz zastosować, znajdziesz na stronie man.
1125 Filtry działają na filmie w kolejnoścy w jakiej zostały załadowane.
1126 Na przykład następujący łańcuch:
1128 <screen>-vf crop=688:464:12:4,scale=640:464</screen>
1130 najpierw skadruje fragment 688x464 filmu z lewym górnym rogiem na pozycji
1131 (12,4) a potem zmniejszy rozdzielczość wyniku do 640x464.
1135 Niektóre filtry trzeba ładować na początku lub blisko początku łańcucha,
1136 ponieważ korzystają one z informacji którą następne filtry mogą zgubić lub
1138 Sztandarowym przykłądem jest <option>pp</option> (postprocessing, tylko gdy
1139 wykonuje operacje usuwania bloków lub pierścieni),
1140 <option>spp</option> (inny postprocessor do usuwania artefaktów MPEG),
1141 <option>pullup</option> (odwrócone telecine) i
1142 <option>softpulldown</option> (konwertuje miękkie telecine na twarde).
1146 W ogólności chcesz przeprowadzać jak najmniej filtrowania żeby film pozostał
1147 możliwie bliski oryginałowi.
1148 Kadrowanie często jest niezbęne (jak opisano powyżej) ale staraj się uniknąć
1150 Chociaż czasami zmniejszenie rozdzielczości jest lepszym wyjściem niż użycie
1151 wyższego kwantyzatora, chcemy uniknąć obu: pamiętajmy, że od początku
1152 zdecydowaliśmy się wybrać jakość kosztem wielkości.
1156 Nie należy też dostosowywać gammy, kontrastu, jasności itp.
1157 Co wygląda dobrze na Twoim ekranie może nie być tak dobre na innych.
1158 Takie dostrojenia powinny być wykonywane tylko przy odtwarzaniu.
1162 Jedną rzeczą którą możesz chcieć zrobić, jest przepuszczenie filmu przez bardzo
1163 lekkie usuwanie szumów, takie jak <option>-vf hqdn3d=2:1:2</option>.
1164 Znów, to kwestia lepszego zastosowania bitów: po co marnować je na zakodowanie
1165 szumu skoro można dodać ten szum przy odtwarzaniu?
1166 Zwiększenie parametrów dla <option>hqdn3d</option> jeszcze bardziej poprawi
1167 kompresowalność, ale jeśli przesadzisz to zauważalnie zniekształcisz obraz.
1168 Wartości sugerowane powyżej (<option>2:1:2</option>) są dość konserwatywne; nie
1169 bój się eksperymentować z wyższymi wartościami i samemu oceniać wyniki.
1175 <sect2 id="menc-feat-dvd-mpeg4-interlacing">
1176 <title>Przeplot i telecine</title>
1179 Prawie wszystkie filmy są kręcone przy 24 fps.
1180 Ponieważ NTSC ma 30000/1001 fps potrzebna jest pewna przeróbka żeby film 24 fps
1181 mógł być wyświetlany z prawidłową szybkością NTSC.
1182 Ten proces nazywa się 3:2 pulldown, często zwany też telecine (ponieważ jest
1183 używany przy konwersji z kina do telewizji) i, w uproszczeniu, jest to
1184 spowolnienie filmu do 24000/1001 fps i powtórzenie co czwartej klatki.
1188 Filmy DVD PAL, odtwarzanie przy 25 fps, nie wymagają żadnego specjalnego
1190 (Technicznie rzecz ujmując, PAL może być poddany telecine, nazywanemu 2:2
1191 pulldown, ale w praktyce nie jest to problemem.)
1192 Po prostu film 24 fps jest odtwarzany przy 25 fps.
1193 W wyniku tego film jest odtwarzany odrobinkę szybciej, ale jeśli nie masz
1194 nieziemskich zmysłów to tego nie zauważysz.
1195 Większość DVD PAL ma skorygowaną wysokość dźwięku, więc kiedy są odtwarzane
1196 przy 25 fps dźwięk będzie brzmiał poprawnie, mimo tego że ścieżka dźwiekowa
1197 (jak i cały film) jest o 4% krótsza niż DVD NTSC.
1201 Ponieważ film na DVD PAL nie został zmieniony, nie ma powodu za bardzo
1202 przejmować się framerate.
1203 Oryginał ma 25 fps i Twój rip też będzie miał 25 fps.
1204 Jednak jeśli ripujesz film z DVD NTSC możesz być zmuszony do zastosowania
1205 odwrotnego telecine.
1209 Dla filmów nagrywanych przy 24 fps obraz na DVD NTSC jest albo poddany telecine
1210 na 30000/1001 albo jest progresywny przy 24000/1001 i przeznaczony do poddania
1211 telecine w locie przez odtwarzacz DVD.
1212 Z drugiej strony seriale telewizyjne zazwyczaj mają tylko przeplot, nie są poddane telecine.
1213 Nie jest to reguła: Niektóre seriale (na przykład Buffy Łowca Wampirów) mają
1214 przeplot, a inne są mieszanką progresywnego i przeplotu (Angel, 24).
1218 Jest wysoce zalecane żebyś przeczytał sekcję
1219 <!-- TODO przetłumaczyć tytuł -->
1220 <link linkend="menc-feat-telecine">How to deal with telecine and interlacing in NTSC DVDs</link>
1221 żeby dowiedzieć się jak sobie radzić z różnymi możliwościami.
1225 Jednak jeśli zazwyczaj tylko ripujesz filmy, prawdopodobnie masz doczynienia
1226 z filmem 24 fps progresywnym lub poddanym telecine, a w takim przypadku możesz
1227 użyć filtra <option>pullup</option> podając parametr
1228 <option>-vf pullup,softskip</option>.
1233 <!-- synced 'till here -->
1235 <sect2 id="menc-feat-dvd-mpeg4-encoding-interlaced">
1236 <title>Encoding interlaced video</title>
1239 If the movie you want to encode is interlaced (NTSC video or
1240 PAL video), you will need to choose whether you want to
1242 While deinterlacing will make your movie usable on progressive
1243 scan displays such a computer monitors and projectors, it comes
1244 at a cost: The fieldrate of 50 or 60000/1001 fields per second
1245 is halved to 25 or 30000/1001 frames per second, and roughly half of
1246 the information in your movie will be lost during scenes with
1251 Therefore, if you are encoding for high quality archival purposes,
1252 it is recommended not to deinterlace.
1253 You can always deinterlace the movie at playback time when
1254 displaying it on progressive scan devices.
1255 The power of currently available computers forces players to use a
1256 deinterlacing filter, which results in a slight degradation in
1258 But future players will be able to mimic the interlaced display of
1259 a TV, deinterlacing to full fieldrate and interpolating 50 or
1260 60000/1001 entire frames per second from the interlaced video.
1264 Special care must be taken when working with interlaced video:
1269 Crop height and y-offset must be multiples of 4.
1272 Any vertical scaling must be performed in interlaced mode.
1275 Postprocessing and denoising filters may not work as expected
1276 unless you take special care to operate them a field at a time,
1277 and they may damage the video if used incorrectly.
1282 With these things in mind, here is our first example:
1284 mencoder <replaceable>capture.avi</replaceable> -mc 0 -oac lavc -ovc lavc -lavcopts \
1285 vcodec=mpeg2video:vbitrate=6000:ilme:ildct:acodec=mp2:abitrate=224
1287 Note the <option>ilme</option> and <option>ildct</option> options.
1293 <sect2 id="menc-feat-dvd-mpeg4-av-sync">
1294 <title>Notes on Audio/Video synchronization</title>
1297 <application>MEncoder</application>'s audio/video synchronization
1298 algorithms were designed with the intention of recovering files with
1300 However, in some cases they can cause unnecessary skipping and duplication of
1301 frames, and possibly slight A/V desync, when used with proper input
1302 (of course, A/V sync issues apply only if you process or copy the
1303 audio track while transcoding the video, which is strongly encouraged).
1304 Therefore, you may have to switch to basic A/V sync with
1305 the <option>-mc 0</option> option, or put this in your
1306 <systemitem>~/.mplayer/mencoder</systemitem> config file, as long as
1307 you are only working with good sources (DVD, TV capture, high quality
1308 MPEG-4 rips, etc) and not broken ASF/RM/MOV files.
1312 If you want to further guard against strange frame skips and
1313 duplication, you can use both <option>-mc 0</option> and
1314 <option>-noskip</option>.
1315 This will prevent <emphasis>all</emphasis> A/V sync, and copy frames
1316 one-to-one, so you cannot use it if you will be using any filters that
1317 unpredictably add or drop frames, or if your input file has variable
1319 Therefore, using <option>-noskip</option> is not in general recommended.
1323 The so-called "three-pass" audio encoding which
1324 <application>MEncoder</application> supports has been reported to cause A/V
1326 This will definitely happen if it is used in conjunction with certain
1327 filters, therefore, it is now recommended <emphasis>not</emphasis> to
1328 use three-pass audio mode.
1329 This feature is only left for compatibility purposes and for expert
1330 users who understand when it is safe to use and when it is not.
1331 If you have never heard of three-pass mode before, forget that we
1336 There have also been reports of A/V desync when encoding from stdin
1337 with <application>MEncoder</application>.
1338 Do not do this! Always use a file or CD/DVD/etc device as input.
1344 <sect2 id="menc-feat-dvd-mpeg4-codec">
1345 <title>Choosing the video codec</title>
1348 Which video codec is best to choose depends on several factors,
1349 like size, quality, streamability, usability and popularity, some of
1350 which widely depend on personal taste and technical constraints.
1355 <emphasis role="bold">Compression efficiency</emphasis>:
1356 It is quite easy to understand that most newer-generation codecs are
1357 made to increase quality and compression.
1358 Therefore, the authors of this guide and many other people suggest that
1360 <footnote id='fn-menc-feat-dvd-mpeg4-codec-cpu'><para>
1361 Be careful, however: Decoding DVD-resolution MPEG-4 AVC videos
1362 requires a fast machine (i.e. a Pentium 4 over 1.5GHz or a Pentium M
1365 when choosing MPEG-4 AVC codecs like
1366 <systemitem class="library">x264</systemitem> instead of MPEG-4 ASP codecs
1367 such as <systemitem class="library">libavcodec</systemitem> MPEG-4 or
1368 <systemitem class="library">Xvid</systemitem>.
1369 (Advanced codec developers may be interested in reading Michael
1370 Niedermayer's opinion on
1371 "<ulink url="http://guru.multimedia.cx/?p=10">why MPEG4-ASP sucks</ulink>".)
1372 Likewise, you should get better quality using MPEG-4 ASP than you
1373 would with MPEG-2 codecs.
1377 However, newer codecs which are in heavy development can suffer from
1378 bugs which have not yet been noticed and which can ruin an encode.
1379 This is simply the tradeoff for using bleeding-edge technology.
1383 What is more, beginning to use a new codec requires that you spend some
1384 time becoming familiar with its options, so that you know what
1385 to adjust to achieve a desired picture quality.
1390 <emphasis role="bold">Hardware compatibility</emphasis>:
1391 It usually takes a long time for standalone video players to begin to
1392 include support for the latest video codecs.
1393 As a result, most only support MPEG-1 (like VCD, XVCD and KVCD), MPEG-2
1394 (like DVD, SVCD and KVCD) and MPEG-4 ASP (like DivX,
1395 <systemitem class="library">libavcodec</systemitem>'s LMP4 and
1396 <systemitem class="library">Xvid</systemitem>)
1397 (Beware: Usually, not all MPEG-4 ASP features are supported).
1398 Please refer to the technical specs of your player (if they are available),
1399 or google around for more information.
1404 <emphasis role="bold">Best quality per encoding time</emphasis>:
1405 Codecs that have been around for some time (such as
1406 <systemitem class="library">libavcodec</systemitem> MPEG-4 and
1407 <systemitem class="library">Xvid</systemitem>) are usually heavily
1408 optimized with all kinds of smart algorithms and SIMD assembly code.
1409 That is why they tend to yield the best quality per encoding time ratio.
1410 However, they may have some very advanced options that, if enabled,
1411 will make the encode really slow for marginal gains.
1415 If you are after blazing speed you should stick around the default
1416 settings of the video codec (although you should still try the other
1417 options which are mentioned in other sections of this guide).
1421 You may also consider choosing a codec which can do multi-threaded
1422 processing, though this is only useful for users of machines with
1424 <systemitem class="library">libavcodec</systemitem> MPEG-4 does
1425 allow that, but speed gains are limited, and there is a slight
1426 negative effect on picture quality.
1427 <systemitem class="library">Xvid</systemitem>'s multi-threaded encoding,
1428 activated by the <option>threads</option> option, can be used to
1429 boost encoding speed — by about 40-60% in typical cases —
1430 with little if any picture degradation.
1431 <systemitem class="library">x264</systemitem> also allows multi-threaded
1432 encoding, which currently speeds up encoding by 94% per CPU core while
1433 lowering PSNR between 0.005dB and 0.01dB on a typical setup.
1439 <emphasis role="bold">Personal taste</emphasis>:
1440 This is where it gets almost irrational: For the same reason that some
1441 hung on to DivX 3 for years when newer codecs were already doing wonders,
1442 some folks will prefer <systemitem class="library">Xvid</systemitem>
1443 or <systemitem class="library">libavcodec</systemitem> MPEG-4 over
1444 <systemitem class="library">x264</systemitem>.
1447 You should make your own judgement; do not take advice from people who
1449 Take a few sample clips from raw sources and compare different
1450 encoding options and codecs to find one that suits you best.
1451 The best codec is the one you master, and the one that looks
1452 best to your eyes on your display
1453 <footnote id='fn-menc-feat-dvd-mpeg4-codec-playback'><para>
1454 The same encode may not look the same on someone else's monitor or
1455 when played back by a different decoder, so future-proof your encodes by
1456 playing them back on different setups.
1463 Please refer to the section
1464 <link linkend="menc-feat-selecting-codec">selecting codecs and container formats</link>
1465 to get a list of supported codecs.
1471 <sect2 id="menc-feat-dvd-mpeg4-audio">
1472 <title>Audio</title>
1475 Audio is a much simpler problem to solve: if you care about quality, just
1477 Even AC-3 5.1 streams are at most 448Kbit/s, and they are worth every bit.
1478 You might be tempted to transcode the audio to high quality Vorbis, but
1479 just because you do not have an A/V receiver for AC-3 pass-through today
1480 does not mean you will not have one tomorrow. Future-proof your DVD rips by
1481 preserving the AC-3 stream.
1482 You can keep the AC-3 stream either by copying it directly into the video
1483 stream <link linkend="menc-feat-mpeg4">during the encoding</link>.
1484 You can also extract the AC-3 stream in order to mux it into containers such
1487 mplayer <replaceable>source_file.vob</replaceable> -aid 129 -dumpaudio -dumpfile <replaceable>sound.ac3</replaceable>
1489 will dump into the file <replaceable>sound.ac3</replaceable> the
1490 audio track number 129 from the file
1491 <replaceable>source_file.vob</replaceable> (NB: DVD VOB files
1492 usually use a different audio numbering,
1493 which means that the VOB audio track 129 is the 2nd audio track of the file).
1497 But sometimes you truly have no choice but to further compress the
1498 sound so that more bits can be spent on the video.
1499 Most people choose to compress audio with either MP3 or Vorbis audio codecs.
1500 While the latter is a very space-efficient codec, MP3 is better supported
1501 by hardware players, although this trend is changing.
1505 Do <emphasis>not</emphasis> use <option>-nosound</option> when encoding
1506 a file with audio, even if you will be encoding and muxing audio
1508 Though it may work in ideal cases, using <option>-nosound</option> is
1509 likely to hide some problems in your encoding command line setting.
1510 In other words, having a soundtrack during your encode assures you that,
1511 provided you do not see messages such as
1512 <quote>Too many audio packets in the buffer</quote>, you will be able
1517 You need to have <application>MEncoder</application> process the sound.
1518 You can for example copy the original soundtrack during the encode with
1519 <option>-oac copy</option> or convert it to a "light" 4 kHz mono WAV
1520 PCM with <option>-oac pcm -channels 1 -srate 4000</option>.
1521 Otherwise, in some cases, it will generate a video file that will not sync
1523 Such cases are when the number of video frames in the source file does
1524 not match up to the total length of audio frames or whenever there
1525 are discontinuities/splices where there are missing or extra audio frames.
1526 The correct way to handle this kind of problem is to insert silence or
1527 cut audio at these points.
1528 However <application>MPlayer</application> cannot do that, so if you
1529 demux the AC-3 audio and encode it with a separate app (or dump it to PCM with
1530 <application>MPlayer</application>), the splices will be left incorrect
1531 and the only way to correct them is to drop/duplicate video frames at the
1533 As long as <application>MEncoder</application> sees the audio when it is
1534 encoding the video, it can do this dropping/duping (which is usually OK
1535 since it takes place at full black/scene change), but if
1536 <application>MEncoder</application> cannot see the audio, it will just
1537 process all frames as-is and they will not fit the final audio stream when
1538 you for example merge your audio and video track into a Matroska file.
1542 First of all, you will have to convert the DVD sound into a WAV file that the
1543 audio codec can use as input.
1546 mplayer <replaceable>source_file.vob</replaceable> -ao pcm:file=<replaceable>destination_sound.wav</replaceable> \
1547 -vc dummy -aid 1 -vo null
1549 will dump the second audio track from the file
1550 <replaceable>source_file.vob</replaceable> into the file
1551 <replaceable>destination_sound.wav</replaceable>.
1552 You may want to normalize the sound before encoding, as DVD audio tracks
1553 are commonly recorded at low volumes.
1554 You can use the tool <application>normalize</application> for instance,
1555 which is available in most distributions.
1556 If you are using Windows, a tool such as <application>BeSweet</application>
1557 can do the same job.
1558 You will compress in either Vorbis or MP3.
1560 <screen>oggenc -q1 <replaceable>destination_sound.wav</replaceable></screen>
1561 will encode <replaceable>destination_sound.wav</replaceable> with
1562 the encoding quality 1, which is roughly equivalent to 80Kb/s, and
1563 is the minimum quality at which you should encode if you care about
1565 Please note that <application>MEncoder</application> currently cannot
1566 mux Vorbis audio tracks
1567 into the output file because it only supports AVI and MPEG
1568 containers as an output, each of which may lead to audio/video
1569 playback synchronization problems with some players when the AVI file
1570 contain VBR audio streams such as Vorbis.
1571 Do not worry, this document will show you how you can do that with third
1578 <sect2 id="menc-feat-dvd-mpeg4-muxing">
1579 <title>Muxing</title>
1582 Now that you have encoded your video, you will most likely want
1583 to mux it with one or more audio tracks into a movie container, such
1584 as AVI, MPEG, Matroska or NUT.
1585 <application>MEncoder</application> is currently only able to natively output
1586 audio and video into MPEG and AVI container formats.
1589 mencoder -oac copy -ovc copy -o <replaceable>output_movie.avi</replaceable> \
1590 -audiofile <replaceable>input_audio.mp2</replaceable> <replaceable>input_video.avi</replaceable>
1592 This would merge the video file <replaceable>input_video.avi</replaceable>
1593 and the audio file <replaceable>input_audio.mp2</replaceable>
1594 into the AVI file <replaceable>output_movie.avi</replaceable>.
1595 This command works with MPEG-1 layer I, II and III (more commonly known
1596 as MP3) audio, WAV and a few other audio formats too.
1600 <application>MEncoder</application> features experimental support for
1601 <systemitem class="library">libavformat</systemitem>, which is a
1602 library from the FFmpeg project that supports muxing and demuxing
1603 a variety of containers.
1606 mencoder -oac copy -ovc copy -o <replaceable>output_movie.asf</replaceable> -audiofile <replaceable>input_audio.mp2</replaceable> \
1607 <replaceable>input_video.avi</replaceable> -of lavf -lavfopts format=asf
1609 This will do the same thing as the previous example, except that
1610 the output container will be ASF.
1611 Please note that this support is highly experimental (but getting
1612 better every day), and will only work if you compiled
1613 <application>MPlayer</application> with the support for
1614 <systemitem class="library">libavformat</systemitem> enabled (which
1615 means that a pre-packaged binary version will not work in most cases).
1619 <sect3 id="menc-feat-dvd-mpeg4-muxing-filter-issues">
1620 <title>Improving muxing and A/V sync reliability</title>
1623 You may experience some serious A/V sync problems while trying to mux
1624 your video and some audio tracks, where no matter how you adjust the
1625 audio delay, you will never get proper sync.
1626 That may happen when you use some video filters that will drop or
1627 duplicate some frames, like the inverse telecine filters.
1628 It is strongly encouraged to append the <option>harddup</option> video
1629 filter at the end of the filter chain to avoid this kind of problem.
1633 Without <option>harddup</option>, if <application>MEncoder</application>
1634 wants to duplicate a frame, it relies on the muxer to put a mark on the
1635 container so that the last frame will be displayed again to maintain
1636 sync while writing no actual frame.
1637 With <option>harddup</option>, <application>MEncoder</application>
1638 will instead just push the last frame displayed again into the filter
1640 This means that the encoder receives the <emphasis>exact</emphasis>
1641 same frame twice, and compresses it.
1642 This will result in a slightly bigger file, but will not cause problems
1643 when demuxing or remuxing into other container formats.
1647 You may also have no choice but to use <option>harddup</option> with
1648 container formats that are not too tightly linked with
1649 <application>MEncoder</application> such as the ones supported through
1650 <systemitem class="library">libavformat</systemitem>, which may not
1651 support frame duplication at the container level.
1656 <sect3 id="menc-feat-dvd-mpeg4-muxing-avi-limitations">
1657 <title>Limitations of the AVI container</title>
1660 Although it is the most widely-supported container format after MPEG-1,
1661 AVI also has some major drawbacks.
1662 Perhaps the most obvious is the overhead.
1663 For each chunk of the AVI file, 24 bytes are wasted on headers and index.
1664 This translates into a little over 5 MB per hour, or 1-2.5%
1665 overhead for a 700 MB movie. This may not seem like much, but it could
1666 mean the difference between being able to use 700 kbit/sec video or
1667 714 kbit/sec, and every bit of quality counts.
1671 In addition this gross inefficiency, AVI also has the following major
1677 Only fixed-fps content can be stored. This is particularly limiting
1678 if the original material you want to encode is mixed content, for
1679 example a mix of NTSC video and film material.
1680 Actually there are hacks that can be used to store mixed-framerate
1681 content in AVI, but they increase the (already huge) overhead
1682 fivefold or more and so are not practical.
1685 Audio in AVI files must be either constant-bitrate (CBR) or
1686 constant-framesize (i.e. all frames decode to the same number of
1688 Unfortunately, the most efficient codec, Vorbis, does not meet
1689 either of these requirements.
1690 Therefore, if you plan to store your movie in AVI, you will have to
1691 use a less efficient codec such as MP3 or AC-3.
1696 Having said all that, <application>MEncoder</application> does not
1697 currently support variable-fps output or Vorbis encoding.
1698 Therefore, you may not see these as limitations if
1699 <application>MEncoder</application> is the
1700 only tool you will be using to produce your encodes.
1701 However, it is possible to use <application>MEncoder</application>
1702 only for video encoding, and then use external tools to encode
1703 audio and mux it into another container format.
1708 <sect3 id="menc-feat-dvd-mpeg4-muxing-matroska">
1709 <title>Muxing into the Matroska container</title>
1712 Matroska is a free, open standard container format, aiming
1713 to offer a lot of advanced features, which older containers
1714 like AVI cannot handle.
1715 For example, Matroska supports variable bitrate audio content
1716 (VBR), variable framerates (VFR), chapters, file attachments,
1717 error detection code (EDC) and modern A/V Codecs like "Advanced Audio
1718 Coding" (AAC), "Vorbis" or "MPEG-4 AVC" (H.264), next to nothing
1723 The tools required to create Matroska files are collectively called
1724 <application>mkvtoolnix</application>, and are available for most
1725 Unix platforms as well as <application>Windows</application>.
1726 Because Matroska is an open standard you may find other
1727 tools that suit you better, but since mkvtoolnix is the most
1728 common, and is supported by the Matroska team itself, we will
1729 only cover its usage.
1733 Probably the easiest way to get started with Matroska is to use
1734 <application>MMG</application>, the graphical frontend shipped with
1735 <application>mkvtoolnix</application>, and follow the
1736 <ulink url="http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html">guide to mkvmerge GUI (mmg)</ulink>
1740 You may also mux audio and video files using the command line:
1742 mkvmerge -o <replaceable>output.mkv</replaceable> <replaceable>input_video.avi</replaceable> <replaceable>input_audio1.mp3</replaceable> <replaceable>input_audio2.ac3</replaceable>
1744 This would merge the video file <replaceable>input_video.avi</replaceable>
1745 and the two audio files <replaceable>input_audio1.mp3</replaceable>
1746 and <replaceable>input_audio2.ac3</replaceable> into the Matroska
1747 file <replaceable>output.mkv</replaceable>.
1748 Matroska, as mentioned earlier, is able to do much more than that, like
1749 multiple audio tracks (including fine-tuning of audio/video
1750 synchronization), chapters, subtitles, splitting, etc...
1751 Please refer to the documentation of those applications for
1759 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
1762 <sect1 id="menc-feat-telecine">
1763 <title>How to deal with telecine and interlacing within NTSC DVDs</title>
1765 <sect2 id="menc-feat-telecine-intro">
1766 <title>Introduction</title>
1769 <title>What is telecine?</title>
1771 If you do not understand much of what is written in this document, read the
1772 <ulink url="http://en.wikipedia.org/wiki/Telecine">Wikipedia entry on telecine</ulink>.
1773 It is an understandable and reasonably comprehensive
1774 description of what telecine is.
1775 </para></formalpara>
1778 <title>A note about the numbers.</title>
1780 Many documents, including the article linked above, refer to the fields
1781 per second value of NTSC video as 59.94 and the corresponding frames
1782 per second values as 29.97 (for telecined and interlaced) and 23.976
1783 (for progressive). For simplicity, some documents even round these
1784 numbers to 60, 30, and 24.
1785 </para></formalpara>
1788 Strictly speaking, all those numbers are approximations. Black and
1789 white NTSC video was exactly 60 fields per second, but 60000/1001
1790 was later chosen to accommodate color data while remaining compatible
1791 with contemporary black and white televisions. Digital NTSC video
1792 (such as on a DVD) is also 60000/1001 fields per second. From this,
1793 interlaced and telecined video are derived to be 30000/1001 frames
1794 per second; progressive video is 24000/1001 frames per second.
1798 Older versions of the <application>MEncoder</application> documentation
1799 and many archived mailing list posts refer to 59.94, 29.97, and 23.976.
1800 All <application>MEncoder</application> documentation has been updated
1801 to use the fractional values, and you should use them too.
1805 <option>-ofps 23.976</option> is incorrect.
1806 <option>-ofps 24000/1001</option> should be used instead.
1810 <title>How telecine is used.</title>
1812 All video intended to be displayed on an NTSC
1813 television set must be 60000/1001 fields per second. Made-for-TV movies
1814 and shows are often filmed directly at 60000/1001 fields per second, but
1815 the majority of cinema is filmed at 24 or 24000/1001 frames per
1816 second. When cinematic movie DVDs are mastered, the video is then
1817 converted for television using a process called telecine.
1818 </para></formalpara>
1821 On a DVD, the video is never actually stored as 60000/1001 fields per
1822 second. For video that was originally 60000/1001, each pair of fields is
1823 combined to form a frame, resulting in 30000/1001 frames per
1824 second. Hardware DVD players then read a flag embedded in the video
1825 stream to determine whether the odd- or even-numbered lines should
1826 form the first field.
1830 Usually, 24000/1001 frames per second content stays as it is when
1831 encoded for a DVD, and the DVD player must perform telecining
1832 on-the-fly. Sometimes, however, the video is telecined
1833 <emphasis>before</emphasis> being stored on the DVD; even though it
1834 was originally 24000/1001 frames per second, it becomes 60000/1001 fields per
1835 second. When it is stored on the DVD, pairs of fields are combined to form
1836 30000/1001 frames per second.
1840 When looking at individual frames formed from 60000/1001 fields per
1841 second video, telecined or otherwise, interlacing is clearly visible
1842 wherever there is any motion, because one field (say, the
1843 even-numbered lines) represents a moment in time 1/(60000/1001)
1844 seconds later than the other. Playing interlaced video on a computer
1845 looks ugly both because the monitor is higher resolution and because
1846 the video is shown frame-after-frame instead of field-after-field.
1850 <title>Notes:</title>
1852 This section only applies to NTSC DVDs, and not PAL.
1855 The example <application>MEncoder</application> lines throughout the
1856 document are <emphasis role="bold">not</emphasis> intended for
1857 actual use. They are simply the bare minimum required to encode the
1858 pertaining video category. How to make good DVD rips or fine-tune
1859 <systemitem class="library">libavcodec</systemitem> for maximal
1860 quality is not within the scope of this section; refer to other
1861 sections within the <link linkend="encoding-guide">MEncoder encoding
1865 There are a couple footnotes specific to this guide, linked like this:
1866 <link linkend="menc-feat-telecine-footnotes">[1]</link>
1873 <sect2 id="menc-feat-telecine-ident">
1874 <title>How to tell what type of video you have</title>
1876 <sect3 id="menc-feat-telecine-ident-progressive">
1877 <title>Progressive</title>
1880 Progressive video was originally filmed at 24000/1001 fps, and stored
1881 on the DVD without alteration.
1885 When you play a progressive DVD in <application>MPlayer</application>,
1886 <application>MPlayer</application> will print the following line as
1887 soon as the movie begins to play:
1889 demux_mpg: 24000/1001 fps progressive NTSC content detected, switching framerate.
1891 From this point forward, demux_mpg should never say it finds
1892 "30000/1001 fps NTSC content."
1896 When you watch progressive video, you should never see any
1897 interlacing. Beware, however, because sometimes there is a tiny bit
1898 of telecine mixed in where you would not expect. I have encountered TV
1899 show DVDs that have one second of telecine at every scene change, or
1900 at seemingly random places. I once watched a DVD that had a
1901 progressive first half, and the second half was telecined. If you
1902 want to be <emphasis>really</emphasis> thorough, you can scan the
1904 <screen>mplayer dvd://1 -nosound -vo null -benchmark</screen>
1905 Using <option>-benchmark</option> makes
1906 <application>MPlayer</application> play the movie as quickly as it
1907 possibly can; still, depending on your hardware, it can take a
1908 while. Every time demux_mpg reports a framerate change, the line
1909 immediately above will show you the time at which the change
1914 Sometimes progressive video on DVDs is referred to as
1915 "soft-telecine" because it is intended to
1916 be telecined by the DVD player.
1921 <sect3 id="menc-feat-telecine-ident-telecined">
1922 <title>Telecined</title>
1925 Telecined video was originally filmed at 24000/1001, but was telecined
1926 <emphasis>before</emphasis> it was written to the DVD.
1930 <application>MPlayer</application> does not (ever) report any
1931 framerate changes when it plays telecined video.
1935 Watching a telecined video, you will see interlacing artifacts that
1936 seem to "blink": they repeatedly appear and disappear.
1937 You can look closely at this by
1939 <listitem><screen>mplayer dvd://1</screen></listitem>
1941 Seek to a part with motion.
1944 Use the <keycap>.</keycap> key to step forward one frame at a time.
1947 Look at the pattern of interlaced-looking and progressive-looking
1948 frames. If the pattern you see is PPPII,PPPII,PPPII,... then the
1949 video is telecined. If you see some other pattern, then the video
1950 may have been telecined using some non-standard method;
1951 <application>MEncoder</application> cannot losslessly convert
1952 non-standard telecine to progressive. If you do not see any
1953 pattern at all, then it is most likely interlaced.
1959 Sometimes telecined video on DVDs is referred to as
1960 "hard-telecine". Since hard-telecine is already 60000/1001 fields
1961 per second, the DVD player plays the video without any manipulation.
1965 Another way to tell if your source is telecined or not is to play
1966 the source with the <option>-vf pullup</option> and <option>-v</option>
1967 command line options to see how <option>pullup</option> matches frames.
1968 If the source is telecined, you should see on the console a 3:2 pattern
1969 with <systemitem>0+.1.+2</systemitem> and <systemitem>0++1</systemitem>
1971 This technique has the advantage that you do not need to watch the
1972 source to identify it, which could be useful if you wish to automate
1973 the encoding procedure, or to carry out said procedure remotely via
1979 <sect3 id="menc-feat-telecine-ident-interlaced">
1980 <title>Interlaced</title>
1983 Interlaced video was originally filmed at 60000/1001 fields per second,
1984 and stored on the DVD as 30000/1001 frames per second. The interlacing effect
1985 (often called "combing") is a result of combining pairs of
1986 fields into frames. Each field is supposed to be 1/(60000/1001) seconds apart,
1987 and when they are displayed simultaneously the difference is apparent.
1991 As with telecined video, <application>MPlayer</application> should
1992 not ever report any framerate changes when playing interlaced content.
1996 When you view an interlaced video closely by frame-stepping with the
1997 <keycap>.</keycap> key, you will see that every single frame is interlaced.
2002 <sect3 id="menc-feat-telecine-ident-mixedpt">
2003 <title>Mixed progressive and telecine</title>
2006 All of a "mixed progressive and telecine" video was originally
2007 24000/1001 frames per second, but some parts of it ended up being telecined.
2011 When <application>MPlayer</application> plays this category, it will
2012 (often repeatedly) switch back and forth between "30000/1001 fps NTSC"
2013 and "24000/1001 fps progressive NTSC". Watch the bottom of
2014 <application>MPlayer</application>'s output to see these messages.
2018 You should check the "30000/1001 fps NTSC" sections to make sure
2019 they are actually telecine, and not just interlaced.
2024 <sect3 id="menc-feat-telecine-ident-mixedpi">
2025 <title>Mixed progressive and interlaced</title>
2028 In "mixed progressive and interlaced" content, progressive
2029 and interlaced video have been spliced together.
2033 This category looks just like "mixed progressive and telecine",
2034 until you examine the 30000/1001 fps sections and see that they do not have the
2042 <sect2 id="menc-feat-telecine-encode">
2043 <title>How to encode each category</title>
2045 As I mentioned in the beginning, example <application>MEncoder</application>
2046 lines below are <emphasis role="bold">not</emphasis> meant to actually be used;
2047 they only demonstrate the minimum parameters to properly encode each category.
2051 <sect3 id="menc-feat-telecine-encode-progressive">
2052 <title>Progressive</title>
2054 Progressive video requires no special filtering to encode. The only
2055 parameter you need to be sure to use is <option>-ofps 24000/1001</option>.
2056 Otherwise, <application>MEncoder</application>
2057 will try to encode at 30000/1001 fps and will duplicate frames.
2061 <screen>mencoder dvd://1 -oac copy -ovc lavc -ofps 24000/1001</screen>
2065 It is often the case, however, that a video that looks progressive
2066 actually has very short parts of telecine mixed in. Unless you are
2067 sure, it is safest to treat the video as
2068 <link linkend="menc-feat-telecine-encode-mixedpt">mixed progressive and telecine</link>.
2069 The performance loss is small
2070 <link linkend="menc-feat-telecine-footnotes">[3]</link>.
2075 <sect3 id="menc-feat-telecine-encode-telecined">
2076 <title>Telecined</title>
2079 Telecine can be reversed to retrieve the original 24000/1001 content,
2080 using a process called inverse-telecine.
2081 <application>MPlayer</application> contains several filters to
2082 accomplish this; the best filter, <option>pullup</option>, is described
2083 in the <link linkend="menc-feat-telecine-encode-mixedpt">mixed
2084 progressive and telecine</link> section.
2089 <sect3 id="menc-feat-telecine-encode-interlaced">
2090 <title>Interlaced</title>
2093 For most practical cases it is not possible to retrieve a complete
2094 progressive video from interlaced content. The only way to do so
2095 without losing half of the vertical resolution is to double the
2096 framerate and try to "guess" what ought to make up the
2097 corresponding lines for each field (this has drawbacks - see method 3).
2102 Encode the video in interlaced form. Normally, interlacing wreaks
2103 havoc with the encoder's ability to compress well, but
2104 <systemitem class="library">libavcodec</systemitem> has two
2105 parameters specifically for dealing with storing interlaced video a
2106 bit better: <option>ildct</option> and <option>ilme</option>. Also,
2107 using <option>mbd=2</option> is strongly recommended
2108 <link linkend="menc-feat-telecine-footnotes">[2] </link> because it
2109 will encode macroblocks as non-interlaced in places where there is
2110 no motion. Note that <option>-ofps</option> is NOT needed here.
2111 <screen>mencoder dvd://1 -oac copy -ovc lavc -lavcopts ildct:ilme:mbd=2</screen>
2114 Use a deinterlacing filter before encoding. There are several of
2115 these filters available to choose from, each with its own advantages
2116 and disadvantages. Consult <option>mplayer -pphelp</option> and
2117 <option>mplayer -vf help</option> to see what is available
2118 (grep for "deint"), read Michael Niedermayer's
2119 <ulink url="http://guru.multimedia.cx/deinterlacing-filters/">Deinterlacing filters comparison</ulink>,
2121 <ulink url="http://www.mplayerhq.hu/design7/mailing_lists.html">
2122 MPlayer mailing lists</ulink> to find many discussions about the
2124 Again, the framerate is not changing, so no
2125 <option>-ofps</option>. Also, deinterlacing should be done after
2126 cropping <link linkend="menc-feat-telecine-footnotes">[1]</link> and
2128 <screen>mencoder dvd://1 -oac copy -vf yadif -ovc lavc</screen>
2131 Unfortunately, this option is buggy with
2132 <application>MEncoder</application>; it ought to work well with
2133 <application>MEncoder G2</application>, but that is not here yet. You
2134 might experience crashes. Anyway, the purpose of <option> -vf
2135 tfields</option> is to create a full frame out of each field, which
2136 makes the framerate 60000/1001. The advantage of this approach is that no
2137 data is ever lost; however, since each frame comes from only one
2138 field, the missing lines have to be interpolated somehow. There are
2139 no very good methods of generating the missing data, and so the
2140 result will look a bit similar to when using some deinterlacing
2141 filters. Generating the missing lines creates other issues, as well,
2142 simply because the amount of data doubles. So, higher encoding
2143 bitrates are required to maintain quality, and more CPU power is
2144 used for both encoding and decoding. tfields has several different
2145 options for how to create the missing lines of each frame. If you
2146 use this method, then Reference the manual, and chose whichever
2147 option looks best for your material. Note that when using
2148 <option>tfields</option> you
2149 <emphasis role="bold">have to</emphasis> specify both
2150 <option>-fps</option> and <option>-ofps</option> to be twice the
2151 framerate of your original source.
2153 mencoder dvd://1 -oac copy -vf tfields=2 -ovc lavc \
2154 -fps 60000/1001 -ofps 60000/1001<!--
2158 If you plan on downscaling dramatically, you can extract and encode
2159 only one of the two fields. Of course, you will lose half the vertical
2160 resolution, but if you plan on downscaling to at most 1/2 of the
2161 original, the loss will not matter much. The result will be a
2162 progressive 30000/1001 frames per second file. The procedure is to use
2163 <option>-vf field</option>, then crop
2164 <link linkend="menc-feat-telecine-footnotes">[1]</link> and scale
2165 appropriately. Remember that you will have to adjust the scale to
2166 compensate for the vertical resolution being halved.
2167 <screen>mencoder dvd://1 -oac copy -vf field=0 -ovc lavc</screen>
2173 <sect3 id="menc-feat-telecine-encode-mixedpt">
2174 <title>Mixed progressive and telecine</title>
2177 In order to turn mixed progressive and telecine video into entirely
2178 progressive video, the telecined parts have to be
2179 inverse-telecined. There are three ways to accomplish this,
2180 described below. Note that you should
2181 <emphasis role="bold">always</emphasis> inverse-telecine before any
2182 rescaling; unless you really know what you are doing,
2183 inverse-telecine before cropping, too
2184 <link linkend="menc-feat-telecine-footnotes">[1]</link>.
2185 <option>-ofps 24000/1001</option> is needed here because the output video
2186 will be 24000/1001 frames per second.
2191 <option>-vf pullup</option> is designed to inverse-telecine
2192 telecined material while leaving progressive data alone. In order to
2193 work properly, <option>pullup</option> <emphasis role="bold">must</emphasis>
2194 be followed by the <option>softskip</option> filter or
2195 else <application>MEncoder</application> will crash.
2196 <option>pullup</option> is, however, the cleanest and most
2197 accurate method available for encoding both telecine and
2198 "mixed progressive and telecine".
2200 mencoder dvd://1 -oac copy -vf pullup,softskip
2201 -ovc lavc -ofps 24000/1001<!--
2205 <option>-vf filmdint</option> is similar to
2206 <option>-vf pullup</option>: both filters attempt to match a pair of
2207 fields to form a complete frame. <option>filmdint</option> will
2208 deinterlace individual fields that it cannot match, however, whereas
2209 <option>pullup</option> will simply drop them. Also, the two filters
2210 have separate detection code, and <option>filmdint</option> may tend to match fields a
2211 bit less often. Which filter works better may depend on the input
2212 video and personal taste; feel free to experiment with fine-tuning
2213 the filters' options if you encounter problems with either one (see
2214 the man page for details). For most well-mastered input video,
2215 however, both filters work quite well, so either one is a safe choice
2218 mencoder dvd://1 -oac copy -vf filmdint -ovc lavc -ofps 24000/1001<!--
2223 is to, rather than inverse-telecine the telecined parts, telecine
2224 the non-telecined parts and then inverse-telecine the whole
2225 video. Sound confusing? softpulldown is a filter that goes through
2226 a video and makes the entire file telecined. If we follow
2227 softpulldown with either <option>detc</option> or
2228 <option>ivtc</option>, the final result will be entirely
2229 progressive. <option>-ofps 24000/1001</option> is needed.
2231 mencoder dvd://1 -oac copy -vf softpulldown,ivtc=1 -ovc lavc -ofps 24000/1001
2239 <sect3 id="menc-feat-telecine-encode-mixedpi">
2240 <title>Mixed progressive and interlaced</title>
2243 There are two options for dealing with this category, each of
2244 which is a compromise. You should decide based on the
2245 duration/location of each type.
2251 Treat it as progressive. The interlaced parts will look interlaced,
2252 and some of the interlaced fields will have to be dropped, resulting
2253 in a bit of uneven jumpiness. You can use a postprocessing filter if
2254 you want to, but it may slightly degrade the progressive parts.
2258 This option should definitely not be used if you want to eventually
2259 display the video on an interlaced device (with a TV card, for
2260 example). If you have interlaced frames in a 24000/1001 frames per
2261 second video, they will be telecined along with the progressive
2262 frames. Half of the interlaced "frames" will be displayed for three
2263 fields' duration (3/(60000/1001) seconds), resulting in a flicking
2264 "jump back in time" effect that looks quite bad. If you
2265 even attempt this, you <emphasis role="bold">must</emphasis> use a
2266 deinterlacing filter like <option>lb</option> or
2267 <option>l5</option>.
2271 It may also be a bad idea for progressive display, too. It will drop
2272 pairs of consecutive interlaced fields, resulting in a discontinuity
2273 that can be more visible than with the second method, which shows
2274 some progressive frames twice. 30000/1001 frames per second interlaced
2275 video is already a bit choppy because it really should be shown at
2276 60000/1001 fields per second, so the duplicate frames do not stand out as
2281 Either way, it is best to consider your content and how you intend to
2282 display it. If your video is 90% progressive and you never intend to
2283 show it on a TV, you should favor a progressive approach. If it is
2284 only half progressive, you probably want to encode it as if it is all
2290 Treat it as interlaced. Some frames of the progressive parts will
2291 need to be duplicated, resulting in uneven jumpiness. Again,
2292 deinterlacing filters may slightly degrade the progressive parts.
2300 <sect2 id="menc-feat-telecine-footnotes">
2301 <title>Footnotes</title>
2306 <title>About cropping:</title>
2308 Video data on DVDs are stored in a format called YUV 4:2:0. In YUV
2309 video, luma ("brightness") and chroma ("color")
2310 are stored separately. Because the human eye is somewhat less
2311 sensitive to color than it is to brightness, in a YUV 4:2:0 picture
2312 there is only one chroma pixel for every four luma pixels. In a
2313 progressive picture, each square of four luma pixels (two on each
2314 side) has one common chroma pixel. You must crop progressive YUV
2315 4:2:0 to even resolutions, and use even offsets. For example,
2316 <option>crop=716:380:2:26</option> is OK but
2317 <option>crop=716:380:3:26 </option> is not.
2322 When you are dealing with interlaced YUV 4:2:0, the situation is a
2323 bit more complicated. Instead of every four luma pixels in the
2324 <emphasis>frame</emphasis> sharing a chroma pixel, every four luma
2325 pixels in each <emphasis> field</emphasis> share a chroma
2326 pixel. When fields are interlaced to form a frame, each scanline is
2327 one pixel high. Now, instead of all four luma pixels being in a
2328 square, there are two pixels side-by-side, and the other two pixels
2329 are side-by-side two scanlines down. The two luma pixels in the
2330 intermediate scanline are from the other field, and so share a
2331 different chroma pixel with two luma pixels two scanlines away. All
2332 this confusion makes it necessary to have vertical crop dimensions
2333 and offsets be multiples of four. Horizontal can stay even.
2337 For telecined video, I recommend that cropping take place after
2338 inverse telecining. Once the video is progressive you only need to
2339 crop by even numbers. If you really want to gain the slight speedup
2340 that cropping first may offer, you must crop vertically by multiples
2341 of four or else the inverse-telecine filter will not have proper data.
2345 For interlaced (not telecined) video, you must always crop
2346 vertically by multiples of four unless you use <option>-vf
2347 field</option> before cropping.
2351 <listitem><formalpara>
2352 <title>About encoding parameters and quality:</title>
2354 Just because I recommend <option>mbd=2</option> here does not mean it
2355 should not be used elsewhere. Along with <option>trell</option>,
2356 <option>mbd=2</option> is one of the two
2357 <systemitem class="library">libavcodec</systemitem> options that
2358 increases quality the most, and you should always use at least those
2359 two unless the drop in encoding speed is prohibitive (e.g. realtime
2360 encoding). There are many other options to
2361 <systemitem class="library">libavcodec</systemitem> that increase
2362 encoding quality (and decrease encoding speed) but that is beyond
2363 the scope of this document.
2365 </formalpara></listitem>
2367 <listitem><formalpara>
2368 <title>About the performance of pullup:</title>
2370 It is safe to use <option>pullup</option> (along with <option>softskip
2371 </option>) on progressive video, and is usually a good idea unless
2372 the source has been definitively verified to be entirely progressive.
2373 The performance loss is small for most cases. On a bare-minimum encode,
2374 <option>pullup</option> causes <application>MEncoder</application> to
2375 be 50% slower. Adding sound processing and advanced <option>lavcopts
2376 </option> overshadows that difference, bringing the performance
2377 decrease of using <option>pullup</option> down to 2%.
2379 </formalpara></listitem>
2385 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
2388 <sect1 id="menc-feat-enc-libavcodec">
2389 <title>Encoding with the <systemitem class="library">libavcodec</systemitem>
2390 codec family</title>
2393 <systemitem class="library">libavcodec</systemitem>
2394 provides simple encoding to a lot of interesting video and audio formats.
2395 You can encode to the following codecs (more or less up to date):
2400 <sect2 id="menc-feat-enc-libavcodec-video-codecs">
2401 <title><systemitem class="library">libavcodec</systemitem>'s
2402 video codecs</title>
2405 <informaltable frame="all">
2408 <row><entry>Video codec name</entry><entry>Description</entry></row>
2412 <entry>mjpeg</entry>
2413 <entry>Motion JPEG</entry>
2416 <entry>ljpeg</entry>
2417 <entry>lossless JPEG</entry>
2420 <entry>jpegls</entry>
2421 <entry>JPEG LS</entry>
2424 <entry>targa</entry>
2425 <entry>Targa image</entry>
2429 <entry>GIF image</entry>
2433 <entry>BMP image</entry>
2437 <entry>PNG image</entry>
2441 <entry>H.261</entry>
2445 <entry>H.263 </entry>
2448 <entry>h263p</entry>
2449 <entry>H.263+</entry>
2452 <entry>mpeg4</entry>
2453 <entry>ISO standard MPEG-4 (DivX, Xvid compatible)</entry>
2456 <entry>msmpeg4</entry>
2457 <entry>pre-standard MPEG-4 variant by MS, v3 (AKA DivX3)</entry>
2460 <entry>msmpeg4v2</entry>
2461 <entry>pre-standard MPEG-4 by MS, v2 (used in old ASF files)</entry>
2465 <entry>Windows Media Video, version 1 (AKA WMV7)</entry>
2469 <entry>Windows Media Video, version 2 (AKA WMV8)</entry>
2473 <entry>RealVideo 1.0</entry>
2477 <entry>RealVideo 2.0</entry>
2480 <entry>mpeg1video</entry>
2481 <entry>MPEG-1 video</entry>
2484 <entry>mpeg2video</entry>
2485 <entry>MPEG-2 video</entry>
2488 <entry>huffyuv</entry>
2489 <entry>lossless compression</entry>
2492 <entry>ffvhuff</entry>
2493 <entry>FFmpeg modified huffyuv lossless</entry>
2497 <entry>ASUS Video v1</entry>
2501 <entry>ASUS Video v2</entry>
2505 <entry>FFmpeg's lossless video codec</entry>
2509 <entry>Sorenson video 1</entry>
2513 <entry>Sorenson H.263 used in Flash Video</entry>
2516 <entry>flashsv</entry>
2517 <entry>Flash Screen Video</entry>
2520 <entry>dvvideo</entry>
2521 <entry>Sony Digital Video</entry>
2525 <entry>FFmpeg's experimental wavelet-based codec</entry>
2529 <entry>Zip Motion Blocks Video</entry>
2532 <entry>dnxhd</entry>
2533 <entry>AVID DNxHD</entry>
2539 The first column contains the codec names that should be passed after the
2540 <literal>vcodec</literal> config,
2541 like: <option>-lavcopts vcodec=msmpeg4</option>
2544 <informalexample><para>
2545 An example with MJPEG compression:
2547 mencoder dvd://2 -o <replaceable>title2.avi</replaceable> -ovc lavc -lavcopts vcodec=mjpeg -oac copy
2549 </para></informalexample>
2554 <sect2 id="menc-feat-enc-libavcodec-audio-codecs">
2555 <title><systemitem class="library">libavcodec</systemitem>'s
2556 audio codecs</title>
2559 <informaltable frame="all">
2562 <row><entry>Audio codec name</entry><entry>Description</entry></row>
2567 <entry>Dolby Digital (AC-3)</entry>
2570 <entry>adpcm_*</entry>
2571 <entry>Adaptive PCM formats - see supplementary table</entry>
2575 <entry>Free Lossless Audio Codec (FLAC)</entry>
2579 <entry>G.726 ADPCM</entry>
2582 <entry>libamr_nb</entry>
2583 <entry>3GPP Adaptive Multi-Rate (AMR) narrow-band</entry>
2586 <entry>libamr_wb</entry>
2587 <entry>3GPP Adaptive Multi-Rate (AMR) wide-band</entry>
2590 <entry>libfaac</entry>
2591 <entry>Advanced Audio Coding (AAC) - using FAAC</entry>
2594 <entry>libgsm</entry>
2595 <entry>ETSI GSM 06.10 full rate</entry>
2598 <entry>libgsm_ms</entry>
2599 <entry>Microsoft GSM</entry>
2602 <entry>libmp3lame</entry>
2603 <entry>MPEG-1 audio layer 3 (MP3) - using LAME</entry>
2607 <entry>MPEG-1 audio layer 2 (MP2)</entry>
2610 <entry>pcm_*</entry>
2611 <entry>PCM formats - see supplementary table</entry>
2614 <entry>roq_dpcm</entry>
2615 <entry>Id Software RoQ DPCM</entry>
2618 <entry>sonic</entry>
2619 <entry>experimental FFmpeg lossy codec</entry>
2622 <entry>sonicls</entry>
2623 <entry>experimental FFmpeg lossless codec</entry>
2626 <entry>vorbis</entry>
2627 <entry>Vorbis</entry>
2630 <entry>wmav1</entry>
2631 <entry>Windows Media Audio v1</entry>
2634 <entry>wmav2</entry>
2635 <entry>Windows Media Audio v2</entry>
2641 The first column contains the codec names that should be passed after the
2642 <literal>acodec</literal> option, like: <option>-lavcopts acodec=ac3</option>
2645 <informalexample><para>
2646 An example with AC-3 compression:
2648 mencoder dvd://2 -o <replaceable>title2.avi</replaceable> -oac lavc -lavcopts acodec=ac3 -ovc copy
2650 </para></informalexample>
2653 Contrary to <systemitem class="library">libavcodec</systemitem>'s video
2654 codecs, its audio codecs do not make a wise usage of the bits they are
2655 given as they lack some minimal psychoacoustic model (if at all)
2656 which most other codec implementations feature.
2657 However, note that all these audio codecs are very fast and work
2658 out-of-the-box everywhere <application>MEncoder</application> has been
2659 compiled with <systemitem class="library">libavcodec</systemitem> (which
2660 is the case most of time), and do not depend on external libraries.
2663 <sect3 id="menc-feat-enc-libavcodec-audio-codecs-pcmadpcm">
2664 <title>PCM/ADPCM format supplementary table</title>
2667 <informaltable frame="all">
2670 <row><entry>PCM/ADPCM codec name</entry><entry>Description</entry></row>
2674 <entry>pcm_s32le</entry>
2675 <entry>signed 32-bit little-endian</entry>
2678 <entry>pcm_s32be</entry>
2679 <entry>signed 32-bit big-endian</entry>
2682 <entry>pcm_u32le</entry>
2683 <entry>unsigned 32-bit little-endian</entry>
2686 <entry>pcm_u32be</entry>
2687 <entry>unsigned 32-bit big-endian</entry>
2690 <entry>pcm_s24le</entry>
2691 <entry>signed 24-bit little-endian</entry>
2694 <entry>pcm_s24be</entry>
2695 <entry>signed 24-bit big-endian</entry>
2698 <entry>pcm_u24le</entry>
2699 <entry>unsigned 24-bit little-endian</entry>
2702 <entry>pcm_u24be</entry>
2703 <entry>unsigned 24-bit big-endian</entry>
2706 <entry>pcm_s16le</entry>
2707 <entry>signed 16-bit little-endian</entry>
2710 <entry>pcm_s16be</entry>
2711 <entry>signed 16-bit big-endian</entry>
2714 <entry>pcm_u16le</entry>
2715 <entry>unsigned 16-bit little-endian</entry>
2718 <entry>pcm_u16be</entry>
2719 <entry>unsigned 16-bit big-endian</entry>
2722 <entry>pcm_s8</entry>
2723 <entry>signed 8-bit</entry>
2726 <entry>pcm_u8</entry>
2727 <entry>unsigned 8-bit</entry>
2730 <entry>pcm_alaw</entry>
2731 <entry>G.711 A-LAW </entry>
2734 <entry>pcm_mulaw</entry>
2735 <entry>G.711 μ-LAW</entry>
2738 <entry>pcm_s24daud</entry>
2739 <entry>signed 24-bit D-Cinema Audio format</entry>
2742 <entry>pcm_zork</entry>
2743 <entry>Activision Zork Nemesis</entry>
2746 <entry>adpcm_ima_qt</entry>
2747 <entry>Apple QuickTime</entry>
2750 <entry>adpcm_ima_wav</entry>
2751 <entry>Microsoft/IBM WAVE</entry>
2754 <entry>adpcm_ima_dk3</entry>
2755 <entry>Duck DK3</entry>
2758 <entry>adpcm_ima_dk4</entry>
2759 <entry>Duck DK4</entry>
2762 <entry>adpcm_ima_ws</entry>
2763 <entry>Westwood Studios</entry>
2766 <entry>adpcm_ima_smjpeg</entry>
2767 <entry>SDL Motion JPEG</entry>
2770 <entry>adpcm_ms</entry>
2771 <entry>Microsoft</entry>
2774 <entry>adpcm_4xm</entry>
2775 <entry>4X Technologies</entry>
2778 <entry>adpcm_xa</entry>
2779 <entry>Phillips Yellow Book CD-ROM eXtended Architecture</entry>
2782 <entry>adpcm_ea</entry>
2783 <entry>Electronic Arts</entry>
2786 <entry>adpcm_ct</entry>
2787 <entry>Creative 16->4-bit</entry>
2790 <entry>adpcm_swf</entry>
2791 <entry>Adobe Shockwave Flash</entry>
2794 <entry>adpcm_yamaha</entry>
2795 <entry>Yamaha</entry>
2798 <entry>adpcm_sbpro_4</entry>
2799 <entry>Creative VOC SoundBlaster Pro 8->4-bit</entry>
2802 <entry>adpcm_sbpro_3</entry>
2803 <entry>Creative VOC SoundBlaster Pro 8->2.6-bit</entry>
2806 <entry>adpcm_sbpro_2</entry>
2807 <entry>Creative VOC SoundBlaster Pro 8->2-bit</entry>
2810 <entry>adpcm_thp</entry>
2811 <entry>Nintendo GameCube FMV THP</entry>
2814 <entry>adpcm_adx</entry>
2815 <entry>Sega/CRI ADX</entry>
2827 <sect2 id="menc-feat-dvd-mpeg4-lavc-encoding-options">
2828 <title>Encoding options of libavcodec</title>
2831 Ideally, you would probably want to be able to just tell the encoder to switch
2832 into "high quality" mode and move on.
2833 That would probably be nice, but unfortunately hard to implement as different
2834 encoding options yield different quality results depending on the source
2835 material. That is because compression depends on the visual properties of the
2837 For example, Anime and live action have very different properties and
2838 thus require different options to obtain optimum encoding.
2839 The good news is that some options should never be left out, like
2840 <option>mbd=2</option>, <option>trell</option>, and <option>v4mv</option>.
2841 See below for a detailed description of common encoding options.
2845 <title>Options to adjust:</title>
2847 <emphasis role="bold">vmax_b_frames</emphasis>: 1 or 2 is good, depending on
2849 Note that if you need to have your encode be decodable by DivX5, you
2850 need to activate closed GOP support, using
2851 <systemitem class="library">libavcodec</systemitem>'s <option>cgop</option>
2852 option, but you need to deactivate scene detection, which
2853 is not a good idea as it will hurt encode efficiency a bit.
2856 <emphasis role="bold">vb_strategy=1</emphasis>: helps in high-motion scenes.
2857 On some videos, vmax_b_frames may hurt quality, but vmax_b_frames=2 along
2858 with vb_strategy=1 helps.
2861 <emphasis role="bold">dia</emphasis>: motion search range. Bigger is better
2863 Negative values are a completely different scale.
2864 Good values are -1 for a fast encode, or 2-4 for slower.
2867 <emphasis role="bold">predia</emphasis>: motion search pre-pass.
2868 Not as important as dia. Good values are 1 (default) to 4. Requires preme=2
2869 to really be useful.
2872 <emphasis role="bold">cmp, subcmp, precmp</emphasis>: Comparison function for
2874 Experiment with values of 0 (default), 2 (hadamard), 3 (dct), and 6 (rate
2876 0 is fastest, and sufficient for precmp.
2877 For cmp and subcmp, 2 is good for Anime, and 3 is good for live action.
2878 6 may or may not be slightly better, but is slow.
2881 <emphasis role="bold">last_pred</emphasis>: Number of motion predictors to
2882 take from the previous frame.
2883 1-3 or so help at little speed cost.
2884 Higher values are slow for no extra gain.
2887 <emphasis role="bold">cbp, mv0</emphasis>: Controls the selection of
2888 macroblocks. Small speed cost for small quality gain.
2891 <emphasis role="bold">qprd</emphasis>: adaptive quantization based on the
2892 macroblock's complexity.
2893 May help or hurt depending on the video and other options.
2894 This can cause artifacts unless you set vqmax to some reasonably small value
2895 (6 is good, maybe as low as 4); vqmin=1 should also help.
2898 <emphasis role="bold">qns</emphasis>: very slow, especially when combined
2900 This option will make the encoder minimize noise due to compression
2901 artifacts instead of making the encoded video strictly match the source.
2902 Do not use this unless you have already tweaked everything else as far as it
2903 will go and the results still are not good enough.
2906 <emphasis role="bold">vqcomp</emphasis>: Tweak ratecontrol.
2907 What values are good depends on the movie.
2908 You can safely leave this alone if you want.
2909 Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts
2910 them on high-complexity scenes (default: 0.5, range: 0-1. recommended range:
2914 <emphasis role="bold">vlelim, vcelim</emphasis>: Sets the single coefficient
2915 elimination threshold for luminance and chroma planes.
2916 These are encoded separately in all MPEG-like algorithms.
2917 The idea behind these options is to use some good heuristics to determine
2918 when the change in a block is less than the threshold you specify, and in
2919 such a case, to just encode the block as "no change".
2920 This saves bits and perhaps speeds up encoding. vlelim=-4 and vcelim=9
2921 seem to be good for live movies, but seem not to help with Anime;
2922 when encoding animation, you should probably leave them unchanged.
2925 <emphasis role="bold">qpel</emphasis>: Quarter pixel motion estimation.
2926 MPEG-4 uses half pixel precision for its motion search by default,
2927 therefore this option comes with an overhead as more information will be
2928 stored in the encoded file.
2929 The compression gain/loss depends on the movie, but it is usually not very
2931 qpel always incurs a significant cost in CPU decode time (+25% in
2935 <emphasis role="bold">psnr</emphasis>: does not affect the actual encoding,
2936 but writes a log file giving the type/size/quality of each frame, and
2937 prints a summary of PSNR (Peak Signal to Noise Ratio) at the end.
2942 <title>Options not recommended to play with:</title>
2944 <emphasis role="bold">vme</emphasis>: The default is best.
2947 <emphasis role="bold">lumi_mask, dark_mask</emphasis>: Psychovisual adaptive
2949 You do not want to play with those options if you care about quality.
2950 Reasonable values may be effective in your case, but be warned this is very
2954 <emphasis role="bold">scplx_mask</emphasis>: Tries to prevent blocky
2955 artifacts, but postprocessing is better.
2962 <sect2 id="menc-feat-mpeg4-lavc-example-settings">
2963 <title>Encoding setting examples</title>
2966 The following settings are examples of different encoding
2967 option combinations that affect the speed vs quality tradeoff
2968 at the same target bitrate.
2972 All the encoding settings were tested on a 720x448 @30000/1001 fps
2973 video sample, the target bitrate was 900kbps, and the machine was an
2974 AMD-64 3400+ at 2400 MHz in 64 bits mode.
2975 Each encoding setting features the measured encoding speed (in
2976 frames per second) and the PSNR loss (in dB) compared to the "very
2977 high quality" setting.
2978 Please understand that depending on your source, your machine type
2979 and development advancements, you may get very different results.
2983 <informaltable frame="all">
2987 <entry>Description</entry>
2988 <entry>Encoding options</entry>
2989 <entry>speed (in fps)</entry>
2990 <entry>Relative PSNR loss (in dB)</entry>
2995 <entry>Very high quality</entry>
2996 <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>
3001 <entry>High quality</entry>
3002 <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>
3003 <entry>15fps</entry>
3004 <entry>-0.5dB</entry>
3008 <entry><option>vcodec=mpeg4:mbd=2:trell:v4mv:turbo</option></entry>
3009 <entry>42fps</entry>
3010 <entry>-0.74dB</entry>
3013 <entry>Realtime</entry>
3014 <entry><option>vcodec=mpeg4:mbd=2:turbo</option></entry>
3015 <entry>54fps</entry>
3016 <entry>-1.21dB</entry>
3026 <sect2 id="custommatrices">
3027 <title>Custom inter/intra matrices</title>
3030 With this feature of
3031 <systemitem class="library">libavcodec</systemitem>
3032 you are able to set custom inter (I-frames/keyframes) and intra
3033 (P-frames/predicted frames) matrices. It is supported by many of the codecs:
3034 <systemitem>mpeg1video</systemitem> and <systemitem>mpeg2video</systemitem>
3035 are reported as working.
3039 A typical usage of this feature is to set the matrices preferred by the
3040 <ulink url="http://www.kvcd.net/">KVCD</ulink> specifications.
3044 The <emphasis role="bold">KVCD "Notch" Quantization Matrix:</emphasis>
3050 8 9 12 22 26 27 29 34
3051 9 10 14 26 27 29 34 37
3052 12 14 18 27 29 34 37 38
3053 22 26 27 31 36 37 38 40
3054 26 27 29 36 39 38 40 48
3055 27 29 34 37 38 40 48 58
3056 29 34 37 38 40 48 58 69
3057 34 37 38 40 48 58 69 79
3062 16 18 20 22 24 26 28 30
3063 18 20 22 24 26 28 30 32
3064 20 22 24 26 28 30 32 34
3065 22 24 26 30 32 32 34 36
3066 24 26 28 32 34 34 36 38
3067 26 28 30 32 34 36 38 40
3068 28 30 32 34 36 38 42 42
3069 30 32 34 36 38 40 42 44
3076 mencoder <replaceable>input.avi</replaceable> -o <replaceable>output.avi</replaceable> -oac copy -ovc lavc \
3077 -lavcopts inter_matrix=...:intra_matrix=...
3083 mencoder <replaceable>input.avi</replaceable> -ovc lavc -lavcopts \
3084 vcodec=mpeg2video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,\
3085 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,\
3086 29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79\
3087 :inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,\
3088 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,\
3089 36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -oac copy -o svcd.mpg
3096 <sect2 id="menc-feat-dvd-mpeg4-example">
3097 <title>Example</title>
3100 So, you have just bought your shiny new copy of Harry Potter and the Chamber
3101 of Secrets (widescreen edition, of course), and you want to rip this DVD
3102 so that you can add it to your Home Theatre PC. This is a region 1 DVD,
3103 so it is NTSC. The example below will still apply to PAL, except you will
3104 omit <option>-ofps 24000/1001</option> (because the output framerate is the
3105 same as the input framerate), and of course the crop dimensions will be
3110 After running <option>mplayer dvd://1</option>, we follow the process
3111 detailed in the section <link linkend="menc-feat-telecine">How to deal
3112 with telecine and interlacing in NTSC DVDs</link> and discover that it is
3113 24000/1001 fps progressive video, which means that we need not use an inverse
3114 telecine filter, such as <option>pullup</option> or
3115 <option>filmdint</option>.
3118 <para id="menc-feat-dvd-mpeg4-example-crop">
3119 Next, we want to determine the appropriate crop rectangle, so we use the
3121 <screen>mplayer dvd://1 -vf cropdetect</screen>
3122 Make sure you seek to a fully filled frame (such as a bright scene,
3123 past the opening credits and logos), and
3124 you will see in <application>MPlayer</application>'s console output:
3125 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen>
3126 We then play the movie back with this filter to test its correctness:
3127 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen>
3128 And we see that it looks perfectly fine. Next, we ensure the width and
3129 height are a multiple of 16. The width is fine, however the height is
3130 not. Since we did not fail 7th grade math, we know that the nearest
3131 multiple of 16 lower than 362 is 352.
3135 We could just use <option>crop=720:352:0:58</option>, but it would be nice
3136 to take a little off the top and a little off the bottom so that we
3137 retain the center. We have shrunk the height by 10 pixels, but we do not
3138 want to increase the y-offset by 5-pixels since that is an odd number and
3139 will adversely affect quality. Instead, we will increase the y-offset by
3141 <screen>mplayer dvd://1 -vf crop=720:352:0:62</screen>
3142 Another reason to shave pixels from both the top and the bottom is that we
3143 ensure we have eliminated any half-black pixels if they exist. Note that if
3144 your video is telecined, make sure the <option>pullup</option> filter (or
3145 whichever inverse telecine filter you decide to use) appears in the filter
3146 chain before you crop. If it is interlaced, deinterlace before cropping.
3147 (If you choose to preserve the interlaced video, then make sure your
3148 vertical crop offset is a multiple of 4.)
3152 If you are really concerned about losing those 10 pixels, you might
3153 prefer instead to scale the dimensions down to the nearest multiple of 16.
3154 The filter chain would look like:
3155 <screen>-vf crop=720:362:0:58,scale=720:352</screen>
3156 Scaling the video down like this will mean that some small amount of
3157 detail is lost, though it probably will not be perceptible. Scaling up will
3158 result in lower quality (unless you increase the bitrate). Cropping
3159 discards those pixels altogether. It is a tradeoff that you will want to
3160 consider for each circumstance. For example, if the DVD video was made
3161 for television, you might want to avoid vertical scaling, since the line
3162 sampling corresponds to the way the content was originally recorded.
3166 On inspection, we see that our movie has a fair bit of action and high
3167 amounts of detail, so we pick 2400Kbit for our bitrate.
3171 We are now ready to do the two pass encode. Pass one:
3173 mencoder dvd://1 -ofps 24000/1001 -oac copy -o <replaceable>Harry_Potter_2.avi</replaceable> -ovc lavc \
3174 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:autoaspect:vpass=1 \
3175 -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2
3177 And pass two is the same, except that we specify <option>vpass=2</option>:
3179 mencoder dvd://1 -ofps 24000/1001 -oac copy -o <replaceable>Harry_Potter_2.avi</replaceable> -ovc lavc \
3180 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:autoaspect:vpass=2 \
3181 -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2
3186 The options <option>v4mv:mbd=2:trell</option> will greatly increase the
3187 quality at the expense of encoding time. There is little reason to leave
3188 these options out when the primary goal is quality. The options
3189 <option>cmp=3:subcmp=3</option> select a comparison function that
3190 yields higher quality than the defaults. You might try experimenting with
3191 this parameter (refer to the man page for the possible values) as
3192 different functions can have a large impact on quality depending on the
3193 source material. For example, if you find
3194 <systemitem class="library">libavcodec</systemitem> produces too much
3195 blocky artifacts, you could try selecting the experimental NSSE as
3196 comparison function via <option>*cmp=10</option>.
3200 For this movie, the resulting AVI will be 138 minutes long and nearly
3201 3GB. And because you said that file size does not matter, this is a
3202 perfectly acceptable size. However, if you had wanted it smaller, you
3203 could try a lower bitrate. Increasing bitrates have diminishing
3204 returns, so while we might clearly see an improvement from 1800Kbit to
3205 2000Kbit, it might not be so noticeable above 2000Kbit. Feel
3206 free to experiment until you are happy.
3210 Because we passed the source video through a denoise filter, you may want
3211 to add some of it back during playback. This, along with the
3212 <option>spp</option> post-processing filter, drastically improves the
3213 perception of quality and helps eliminate blocky artifacts in the video.
3214 With <application>MPlayer</application>'s <option>autoq</option> option,
3215 you can vary the amount of post-processing done by the spp filter
3216 depending on available CPU. Also, at this point, you may want to apply
3217 gamma and/or color correction to best suit your display. For example:
3219 mplayer <replaceable>Harry_Potter_2.avi</replaceable> -vf spp,noise=9ah:5ah,eq2=1.2 -autoq 3
3226 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
3229 <sect1 id="menc-feat-xvid">
3230 <title>Encoding with the <systemitem class="library">Xvid</systemitem>
3234 <systemitem class="library">Xvid</systemitem> is a free library for
3235 encoding MPEG-4 ASP video streams.
3236 Before starting to encode, you need to <link linkend="xvid">
3237 set up <application>MEncoder</application> to support it</link>.
3241 This guide mainly aims at featuring the same kind of information
3242 as x264's encoding guide.
3243 Therefore, please begin by reading
3244 <link linkend="menc-feat-x264-encoding-options-intro">the first part</link>
3250 <sect2 id="menc-feat-xvid-intro">
3251 <title>What options should I use to get the best results?</title>
3254 Please begin by reviewing the
3255 <systemitem class="library">Xvid</systemitem> section of
3256 <application>MPlayer</application>'s man page.
3257 This section is intended to be a supplement to the man page.
3261 The Xvid default settings are already a good tradeoff between
3262 speed and quality, therefore you can safely stick to them if
3263 the following section puzzles you.
3269 <sect2 id="menc-feat-xvid-encoding-options">
3270 <title>Encoding options of <systemitem class="library">Xvid</systemitem></title>
3274 <emphasis role="bold">vhq</emphasis>
3275 This setting affects the macroblock decision algorithm, where the
3276 higher the setting, the wiser the decision.
3277 The default setting may be safely used for every encode, while
3278 higher settings always help PSNR but are significantly slower.
3279 Please note that a better PSNR does not necessarily mean
3280 that the picture will look better, but tells you that it is
3281 closer to the original.
3282 Turning it off will noticeably speed up encoding; if speed is
3283 critical for you, the tradeoff may be worth it.
3286 <emphasis role="bold">bvhq</emphasis>
3287 This does the same job as vhq, but does it on B-frames.
3288 It has a negligible impact on speed, and slightly improves quality
3289 (around +0.1dB PSNR).
3292 <emphasis role="bold">max_bframes</emphasis>
3293 A higher number of consecutive allowed B-frames usually improves
3294 compressibility, although it may also lead to more blocking artifacts.
3295 The default setting is a good tradeoff between compressibility and
3296 quality, but you may increase it up to 3 if you are bitrate-starved.
3297 You may also decrease it to 1 or 0 if you are aiming at perfect
3298 quality, though in that case you should make sure your
3299 target bitrate is high enough to ensure that the encoder does not
3300 have to increase quantizers to reach it.
3303 <emphasis role="bold">bf_threshold</emphasis>
3304 This controls the B-frame sensitivity of the encoder, where a higher
3305 value leads to more B-frames being used (and vice versa).
3306 This setting is to be used together with <option>max_bframes</option>;
3307 if you are bitrate-starved, you should increase both
3308 <option>max_bframes</option> and <option>bf_threshold</option>,
3309 while you may increase <option>max_bframes</option> and reduce
3310 <option>bf_threshold</option> so that the encoder may use more
3311 B-frames in places that only <emphasis role="bold">really</emphasis>
3313 A low number of <option>max_bframes</option> and a high value of
3314 <option>bf_threshold</option> is probably not a wise choice as it
3315 will force the encoder to put B-frames in places that would not
3316 benefit from them, therefore reducing visual quality.
3317 However, if you need to be compatible with standalone players that
3318 only support old DivX profiles (which only supports up to 1
3319 consecutive B-frame), this would be your only way to
3320 increase compressibility through using B-frames.
3323 <emphasis role="bold">trellis</emphasis>
3324 Optimizes the quantization process to get an optimal tradeoff
3325 between PSNR and bitrate, which allows significant bit saving.
3326 These bits will in return be spent elsewhere on the video,
3327 raising overall visual quality.
3328 You should always leave it on as its impact on quality is huge.
3329 Even if you are looking for speed, do not disable it until you
3330 have turned down <option>vhq</option> and all other more
3331 CPU-hungry options to the minimum.
3334 <emphasis role="bold">hq_ac</emphasis>
3335 Activates a better coefficient cost estimation method, which slightly
3336 reduces file size by around 0.15 to 0.19% (which corresponds to less
3337 than 0.01dB PSNR increase), while having a negligible impact on speed.
3338 It is therefore recommended to always leave it on.
3341 <emphasis role="bold">cartoon</emphasis>
3342 Designed to better encode cartoon content, and has no impact on
3343 speed as it just tunes the mode decision heuristics for this type
3348 <emphasis role="bold">me_quality</emphasis>
3349 This setting is to control the precision of the motion estimation.
3350 The higher <option>me_quality</option>, the more
3351 precise the estimation of the original motion will be, and the
3352 better the resulting clip will capture the original motion.
3355 The default setting is best in all cases;
3356 thus it is not recommended to turn it down unless you are
3357 really looking for speed, as all the bits saved by a good motion
3358 estimation would be spent elsewhere, raising overall quality.
3359 Therefore, do not go any lower than 5, and even that only as a last
3364 <emphasis role="bold">chroma_me</emphasis>
3365 Improves motion estimation by also taking the chroma (color)
3366 information into account, whereas <option>me_quality</option>
3367 alone only uses luma (grayscale).
3368 This slows down encoding by 5-10% but improves visual quality
3369 quite a bit by reducing blocking effects and reduces file size by
3371 If you are looking for speed, you should disable this option before
3372 starting to consider reducing <option>me_quality</option>.
3375 <emphasis role="bold">chroma_opt</emphasis>
3376 Is intended to increase chroma image quality around pure
3377 white/black edges, rather than improving compression.
3378 This can help to reduce the "red stairs" effect.
3381 <emphasis role="bold">lumi_mask</emphasis>
3382 Tries to give less bitrate to part of the picture that the
3383 human eye cannot see very well, which should allow the encoder
3384 to spend the saved bits on more important parts of the picture.
3385 The quality of the encode yielded by this option highly depends
3386 on personal preferences and on the type and monitor settings
3387 used to watch it (typically, it will not look as good if it is
3388 bright or if it is a TFT monitor).
3392 <emphasis role="bold">qpel</emphasis>
3393 Raise the number of candidate motion vectors by increasing
3394 the precision of the motion estimation from halfpel to
3396 The idea is to find better motion vectors which will in return
3397 reduce bitrate (hence increasing quality).
3398 However, motion vectors with quarterpel precision require a
3399 few extra bits to code, but the candidate vectors do not always
3400 give (much) better results.
3401 Quite often, the codec still spends bits on the extra precision,
3402 but little or no extra quality is gained in return.
3403 Unfortunately, there is no way to foresee the possible gains of
3404 <option>qpel</option>, so you need to actually encode with and
3405 without it to know for sure.
3408 <option>qpel</option> can be almost double encoding time, and
3409 requires as much as 25% more processing power to decode.
3410 It is not supported by all standalone players.
3414 <emphasis role="bold">gmc</emphasis>
3415 Tries to save bits on panning scenes by using a single motion
3416 vector for the whole frame.
3417 This almost always raises PSNR, but significantly slows down
3418 encoding (as well as decoding).
3419 Therefore, you should only use it when you have turned
3420 <option>vhq</option> to the maximum.
3421 <systemitem class="library">Xvid</systemitem>'s GMC is more
3422 sophisticated than DivX's, but is only supported by few
3430 <sect2 id="menc-feat-xvid-encoding-profiles">
3431 <title>Encoding profiles</title>
3434 Xvid supports encoding profiles through the <option>profile</option> option,
3435 which are used to impose restrictions on the properties of the Xvid video
3436 stream such that it will be playable on anything which supports the
3438 The restrictions relate to resolutions, bitrates and certain MPEG-4
3440 The following table shows what each profile supports.
3444 <tgroup cols="16" align="center">
3445 <colspec colnum="1" colname="col1"/>
3446 <colspec colnum="2" colname="col2"/>
3447 <colspec colnum="3" colname="col3"/>
3448 <colspec colnum="4" colname="col4"/>
3449 <colspec colnum="5" colname="col5"/>
3450 <colspec colnum="6" colname="col6"/>
3451 <colspec colnum="7" colname="col7"/>
3452 <colspec colnum="8" colname="col8"/>
3453 <colspec colnum="9" colname="col9"/>
3454 <colspec colnum="10" colname="col10"/>
3455 <colspec colnum="11" colname="col11"/>
3456 <colspec colnum="12" colname="col12"/>
3457 <colspec colnum="13" colname="col13"/>
3458 <colspec colnum="14" colname="col14"/>
3459 <colspec colnum="15" colname="col15"/>
3460 <colspec colnum="16" colname="col16"/>
3461 <colspec colnum="17" colname="col17"/>
3462 <spanspec spanname="spa2-5" namest="col2" nameend="col5"/>
3463 <spanspec spanname="spa6-11" namest="col6" nameend="col11"/>
3464 <spanspec spanname="spa12-17" namest="col12" nameend="col17"/>
3468 <entry spanname="spa2-5">Simple</entry>
3469 <entry spanname="spa6-11">Advanced Simple</entry>
3470 <entry spanname="spa12-17">DivX</entry>
3473 <entry>Profile name</entry>
3484 <entry>Handheld</entry>
3485 <entry>Portable NTSC</entry>
3486 <entry>Portable PAL</entry>
3487 <entry>Home Theater NTSC</entry>
3488 <entry>Home Theater PAL</entry>
3492 <entry>Width [pixels]</entry>
3511 <entry>Height [pixels]</entry>
3530 <entry>Frame rate [fps]</entry>
3549 <entry>Max average bitrate [kbps]</entry>
3560 <entry>537.6</entry>
3565 <entry>9708.4</entry>
3568 <entry>Peak average bitrate over 3 secs [kbps]</entry>
3584 <entry>16000</entry>
3587 <entry>Max. B-frames</entry>
3606 <entry>MPEG quantization</entry>
3625 <entry>Adaptive quantization</entry>
3644 <entry>Interlaced encoding</entry>
3663 <entry>Quarterpixel</entry>
3682 <entry>Global motion compensation</entry>
3707 <sect2 id="menc-feat-xvid-example-settings">
3708 <title>Encoding setting examples</title>
3711 The following settings are examples of different encoding
3712 option combinations that affect the speed vs quality tradeoff
3713 at the same target bitrate.
3717 All the encoding settings were tested on a 720x448 @30000/1001 fps
3718 video sample, the target bitrate was 900kbps, and the machine was an
3719 AMD-64 3400+ at 2400 MHz in 64 bits mode.
3720 Each encoding setting features the measured encoding speed (in
3721 frames per second) and the PSNR loss (in dB) compared to the "very
3722 high quality" setting.
3723 Please understand that depending on your source, your machine type
3724 and development advancements, you may get very different results.
3727 <informaltable frame="all">
3730 <row><entry>Description</entry><entry>Encoding options</entry><entry>speed (in fps)</entry><entry>Relative PSNR loss (in dB)</entry></row>
3734 <entry>Very high quality</entry>
3735 <entry><option>chroma_opt:vhq=4:bvhq=1:quant_type=mpeg</option></entry>
3736 <entry>16fps</entry>
3740 <entry>High quality</entry>
3741 <entry><option>vhq=2:bvhq=1:chroma_opt:quant_type=mpeg</option></entry>
3742 <entry>18fps</entry>
3743 <entry>-0.1dB</entry>
3747 <entry><option>turbo:vhq=0</option></entry>
3748 <entry>28fps</entry>
3749 <entry>-0.69dB</entry>
3752 <entry>Realtime</entry>
3753 <entry><option>turbo:nochroma_me:notrellis:max_bframes=0:vhq=0</option></entry>
3754 <entry>38fps</entry>
3755 <entry>-1.48dB</entry>
3764 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
3767 <sect1 id="menc-feat-x264">
3768 <title>Encoding with the
3769 <systemitem class="library">x264</systemitem> codec</title>
3772 <systemitem class="library">x264</systemitem> is a free library for
3773 encoding H.264/AVC video streams.
3774 Before starting to encode, you need to
3775 <link linkend="x264">set up <application>MEncoder</application> to support it</link>.
3780 <sect2 id="menc-feat-x264-encoding-options">
3781 <title>Encoding options of x264</title>
3784 Please begin by reviewing the
3785 <systemitem class="library">x264</systemitem> section of
3786 <application>MPlayer</application>'s man page.
3787 This section is intended to be a supplement to the man page.
3788 Here you will find quick hints about which options are most
3789 likely to interest most people. The man page is more terse,
3790 but also more exhaustive, and it sometimes offers much better
3795 <sect3 id="menc-feat-x264-encoding-options-intro">
3796 <title>Introduction</title>
3799 This guide considers two major categories of encoding options:
3804 Options which mainly trade off encoding time vs. quality
3807 Options which may be useful for fulfilling various personal
3808 preferences and special requirements
3813 Ultimately, only you can decide which options are best for your
3814 purposes. The decision for the first class of options is the simplest:
3815 you only have to decide whether you think the quality differences
3816 justify the speed differences. For the second class of options,
3817 preferences may be far more subjective, and more factors may be
3818 involved. Note that some of the "personal preferences and special
3819 requirements" options can still have large impacts on speed or quality,
3820 but that is not what they are primarily useful for. A couple of the
3821 "personal preference" options may even cause changes that look better
3822 to some people, but look worse to others.
3826 Before continuing, you need to understand that this guide uses only one
3827 quality metric: global PSNR.
3828 For a brief explanation of what PSNR is, see
3829 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>.
3830 Global PSNR is the last PSNR number reported when you include
3831 the <option>psnr</option> option in <option>x264encopts</option>.
3832 Any time you read a claim about PSNR, one of the assumptions
3833 behind the claim is that equal bitrates are used.
3837 Nearly all of this guide's comments assume you are using two pass.
3838 When comparing options, there are two major reasons for using
3840 First, using two pass often gains around 1dB PSNR, which is a
3841 very big difference.
3842 Secondly, testing options by doing direct quality comparisons
3843 with one pass encodes introduces a major confounding
3844 factor: bitrate often varies significantly with each encode.
3845 It is not always easy to tell whether quality changes are due
3846 mainly to changed options, or if they mostly reflect essentially
3847 random differences in the achieved bitrate.
3852 <sect3 id="menc-feat-x264-encoding-options-speedvquality">
3853 <title>Options which primarily affect speed and quality</title>
3858 <emphasis role="bold">subq</emphasis>:
3859 Of the options which allow you to trade off speed for quality,
3860 <option>subq</option> and <option>frameref</option> (see below) are usually
3861 by far the most important.
3862 If you are interested in tweaking either speed or quality, these
3863 are the first options you should consider.
3864 On the speed dimension, the <option>frameref</option> and
3865 <option>subq</option> options interact with each other fairly
3867 Experience shows that, with one reference frame,
3868 <option>subq=5</option> (the default setting) takes about 35% more time than
3869 <option>subq=1</option>.
3870 With 6 reference frames, the penalty grows to over 60%.
3871 <option>subq</option>'s effect on PSNR seems fairly constant
3872 regardless of the number of reference frames.
3873 Typically, <option>subq=5</option> achieves 0.2-0.5 dB higher global
3874 PSNR in comparison <option>subq=1</option>.
3875 This is usually enough to be visible.
3878 <option>subq=6</option> is slower and yields better quality at a reasonable
3880 In comparison to <option>subq=5</option>, it usually gains 0.1-0.4 dB
3881 global PSNR with speed costs varying from 25%-100%.
3882 Unlike other levels of <option>subq</option>, the behavior of
3883 <option>subq=6</option> does not depend much on <option>frameref</option>
3884 and <option>me</option>. Instead, the effectiveness of <option>subq=6
3885 </option> depends mostly upon the number of B-frames used. In normal
3886 usage, this means <option>subq=6</option> has a large impact on both speed
3887 and quality in complex, high motion scenes, but it may not have much effect
3888 in low-motion scenes. Note that it is still recommended to always set
3889 <option>bframes</option> to something other than zero (see below).
3892 <option>subq=7</option> is the slowest, highest quality mode.
3893 In comparison to <option>subq=6</option>, it usually gains 0.01-0.05 dB
3894 global PSNR with speed costs varying from 15%-33%.
3895 Since the tradeoff encoding time vs. quality is quite low, you should
3896 only use it if you are after every bit saving and if encoding time is
3902 <emphasis role="bold">frameref</emphasis>:
3903 <option>frameref</option> is set to 1 by default, but this
3904 should not be taken to imply that it is reasonable to set it to 1.
3905 Merely raising <option>frameref</option> to 2 gains around
3906 0.15dB PSNR with a 5-10% speed penalty; this seems like a good tradeoff.
3907 <option>frameref=3</option> gains around 0.25dB PSNR over
3908 <option>frameref=1</option>, which should be a visible difference.
3909 <option>frameref=3</option> is around 15% slower than
3910 <option>frameref=1</option>.
3911 Unfortunately, diminishing returns set in rapidly.
3912 <option>frameref=6</option> can be expected to gain only
3913 0.05-0.1 dB over <option>frameref=3</option> at an additional
3915 Above <option>frameref=6</option>, the quality gains are
3916 usually very small (although you should keep in mind throughout
3917 this whole discussion that it can vary quite a lot depending on your source).
3918 In a fairly typical case, <option>frameref=12</option>
3919 will improve global PSNR by a tiny 0.02dB over
3920 <option>frameref=6</option>, at a speed cost of 15%-20%.
3921 At such high <option>frameref</option> values, the only really
3922 good thing that can be said is that increasing it even further will
3923 almost certainly never <emphasis role="bold">harm</emphasis>
3924 PSNR, but the additional quality benefits are barely even
3925 measurable, let alone perceptible.
3927 <note><title>Note:</title>
3929 Raising <option>frameref</option> to unnecessarily high values
3930 <emphasis role="bold">can</emphasis> and
3931 <emphasis role="bold">usually does</emphasis>
3932 hurt coding efficiency if you turn CABAC off.
3933 With CABAC on (the default behavior), the possibility of setting
3934 <option>frameref</option> "too high" currently seems too remote
3935 to even worry about, and in the future, optimizations may remove
3936 the possibility altogether.
3939 If you care about speed, a reasonable compromise is to use low
3940 <option>subq</option> and <option>frameref</option> values on
3941 the first pass, and then raise them on the second pass.
3942 Typically, this has a negligible negative effect on the final
3943 quality: You will probably lose well under 0.1dB PSNR, which
3944 should be much too small of a difference to see.
3945 However, different values of <option>frameref</option> can
3946 occasionally affect frame type decision.
3947 Most likely, these are rare outlying cases, but if you want to
3948 be pretty sure, consider whether your video has either
3949 fullscreen repetitive flashing patterns or very large temporary
3950 occlusions which might force an I-frame.
3951 Adjust the first-pass <option>frameref</option> so it is large
3952 enough to contain the duration of the flashing cycle (or occlusion).
3953 For example, if the scene flashes back and forth between two images
3954 over a duration of three frames, set the first pass
3955 <option>frameref</option> to 3 or higher.
3956 This issue is probably extremely rare in live action video material,
3957 but it does sometimes come up in video game captures.
3962 <emphasis role="bold">me</emphasis>:
3963 This option is for choosing the motion estimation search method.
3964 Altering this option provides a straightforward quality-vs-speed
3965 tradeoff. <option>me=dia</option> is only a few percent faster than
3966 the default search, at a cost of under 0.1dB global PSNR. The
3967 default setting (<option>me=hex</option>) is a reasonable tradeoff
3968 between speed and quality. <option>me=umh</option> gains a little under
3969 0.1dB global PSNR, with a speed penalty that varies depending on
3970 <option>frameref</option>. At high values of
3971 <option>frameref</option> (e.g. 12 or so), <option>me=umh</option>
3972 is about 40% slower than the default <option> me=hex</option>. With
3973 <option>frameref=3</option>, the speed penalty incurred drops to
3977 <option>me=esa</option> uses an exhaustive search that is too slow for
3982 <emphasis role="bold">partitions=all</emphasis>:
3983 This option enables the use of 8x4, 4x8 and 4x4 subpartitions in
3984 predicted macroblocks (in addition to the default partitions).
3985 Enabling it results in a fairly consistent
3986 10%-15% loss of speed. This option is rather useless in source
3987 containing only low motion, however in some high-motion source,
3988 particularly source with lots of small moving objects, gains of
3989 about 0.1dB can be expected.
3993 <emphasis role="bold">bframes</emphasis>:
3994 If you are used to encoding with other codecs, you may have found
3995 that B-frames are not always useful.
3996 In H.264, this has changed: there are new techniques and block
3997 types that are possible in B-frames.
3998 Usually, even a naive B-frame choice algorithm can have a
3999 significant PSNR benefit.
4000 It is interesting to note that using B-frames usually speeds up
4001 the second pass somewhat, and may also speed up a single
4002 pass encode if adaptive B-frame decision is turned off.
4005 With adaptive B-frame decision turned off
4006 (<option>x264encopts</option>'s <option>nob_adapt</option>),
4007 the optimal value for this setting is usually no more than
4008 <option>bframes=1</option>, or else high-motion scenes can suffer.
4009 With adaptive B-frame decision on (the default behavior), it is
4010 safe to use higher values; the encoder will reduce the use of
4011 B-frames in scenes where they would hurt compression.
4012 The encoder rarely chooses to use more than 3 or 4 B-frames;
4013 setting this option any higher will have little effect.
4018 <emphasis role="bold">b_adapt</emphasis>:
4019 Note: This is on by default.
4022 With this option enabled, the encoder will use a reasonably fast
4023 decision process to reduce the number of B-frames used in scenes that
4024 might not benefit from them as much.
4025 You can use <option>b_bias</option> to tweak how B-frame-happy
4027 The speed penalty of adaptive B-frames is currently rather modest,
4028 but so is the potential quality gain.
4029 It usually does not hurt, however.
4030 Note that this only affects speed and frame type decision on the
4032 <option>b_adapt</option> and <option>b_bias</option> have no
4033 effect on subsequent passes.
4037 <emphasis role="bold">b_pyramid</emphasis>:
4038 You might as well enable this option if you are using >=2 B-frames;
4039 as the man page says, you get a little quality improvement at no
4041 Note that these videos cannot be read by libavcodec-based decoders
4042 older than about March 5, 2005.
4046 <emphasis role="bold">weight_b</emphasis>:
4047 In typical cases, there is not much gain with this option.
4048 However, in crossfades or fade-to-black scenes, weighted
4049 prediction gives rather large bitrate savings.
4050 In MPEG-4 ASP, a fade-to-black is usually best coded as a series
4051 of expensive I-frames; using weighted prediction in B-frames
4052 makes it possible to turn at least some of these into much smaller
4054 Encoding time cost is minimal, as no extra decisions need to be made.
4055 Also, contrary to what some people seem to guess, the decoder
4056 CPU requirements are not much affected by weighted prediction,
4057 all else being equal.
4060 Unfortunately, the current adaptive B-frame decision algorithm
4061 has a strong tendency to avoid B-frames during fades.
4062 Until this changes, it may be a good idea to add
4063 <option>nob_adapt</option> to your x264encopts, if you expect
4064 fades to have a large effect in your particular video
4068 <listitem id="menc-feat-x264-encoding-options-speedvquality-threads">
4070 <emphasis role="bold">threads</emphasis>:
4071 This option allows to spawn threads to encode in parallel on multiple CPUs.
4072 You can manually select the number of threads to be created or, better, set
4073 <option>threads=auto</option> and let
4074 <systemitem class="library">x264</systemitem> detect how many CPUs are
4075 available and pick an appropriate number of threads.
4076 If you have a multi-processor machine, you should really consider using it
4077 as it can to increase encoding speed linearly with the number of CPU cores
4078 (about 94% per CPU core), with very little quality reduction (about 0.005dB
4079 for dual processor, about 0.01dB for a quad processor machine).
4086 <sect3 id="menc-feat-x264-encoding-options-misc-preferences">
4087 <title>Options pertaining to miscellaneous preferences</title>
4092 <emphasis role="bold">Two pass encoding</emphasis>:
4093 Above, it was suggested to always use two pass encoding, but there
4094 are still reasons for not using it. For instance, if you are capturing
4095 live TV and encoding in realtime, you are forced to use single-pass.
4096 Also, one pass is obviously faster than two passes; if you use the
4097 exact same set of options on both passes, two pass encoding is almost
4101 Still, there are very good reasons for using two pass encoding. For
4102 one thing, single pass ratecontrol is not psychic, and it often makes
4103 unreasonable choices because it cannot see the big picture. For example,
4104 suppose you have a two minute long video consisting of two distinct
4105 halves. The first half is a very high-motion scene lasting 60 seconds
4106 which, in isolation, requires about 2500kbps in order to look decent.
4107 Immediately following it is a much less demanding 60-second scene
4108 that looks good at 300kbps. Suppose you ask for 1400kbps on the theory
4109 that this is enough to accommodate both scenes. Single pass ratecontrol
4110 will make a couple of "mistakes" in such a case. First of all, it
4111 will target 1400kbps in both segments. The first segment may end up
4112 heavily overquantized, causing it to look unacceptably and unreasonably
4113 blocky. The second segment will be heavily underquantized; it may look
4114 perfect, but the bitrate cost of that perfection will be completely
4115 unreasonable. What is even harder to avoid is the problem at the
4116 transition between the two scenes. The first seconds of the low motion
4117 half will be hugely over-quantized, because the ratecontrol is still
4118 expecting the kind of bitrate requirements it met in the first half
4119 of the video. This "error period" of heavily over-quantized low motion
4120 will look jarringly bad, and will actually use less than the 300kbps
4121 it would have taken to make it look decent. There are ways to
4122 mitigate the pitfalls of single-pass encoding, but they may tend to
4123 increase bitrate misprediction.
4126 Multipass ratecontrol can offer huge advantages over a single pass.
4127 Using the statistics gathered from the first pass encode, the encoder
4128 can estimate, with reasonable accuracy, the "cost" (in bits) of
4129 encoding any given frame, at any given quantizer. This allows for
4130 a much more rational, better planned allocation of bits between the
4131 expensive (high-motion) and cheap (low-motion) scenes. See
4132 <option>qcomp</option> below for some ideas on how to tweak this
4133 allocation to your liking.
4136 Moreover, two passes need not take twice as long as one pass. You can
4137 tweak the options in the first pass for higher speed and lower quality.
4138 If you choose your options well, you can get a very fast first pass.
4139 The resulting quality in the second pass will be slightly lower because size
4140 prediction is less accurate, but the quality difference is normally much
4141 too small to be visible. Try, for example, adding
4142 <option>subq=1:frameref=1</option> to the first pass
4143 <option>x264encopts</option>. Then, on the second pass, use slower,
4144 higher-quality options:
4145 <option>subq=6:frameref=15:partitions=all:me=umh</option>
4149 <emphasis role="bold">Three pass encoding</emphasis>?
4150 x264 offers the ability to make an arbitrary number of consecutive
4151 passes. If you specify <option>pass=1</option> on the first pass,
4152 then use <option>pass=3</option> on a subsequent pass, the subsequent
4153 pass will both read the statistics from the previous pass, and write
4154 its own statistics. An additional pass following this one will have
4155 a very good base from which to make highly accurate predictions of
4156 frame sizes at a chosen quantizer. In practice, the overall quality
4157 gain from this is usually close to zero, and quite possibly a third
4158 pass will result in slightly worse global PSNR than the pass before
4159 it. In typical usage, three passes help if you get either bad bitrate
4160 prediction or bad looking scene transitions when using only two passes.
4161 This is somewhat likely to happen on extremely short clips. There are
4162 also a few special cases in which three (or more) passes are handy
4163 for advanced users, but for brevity, this guide omits discussing those
4167 <emphasis role="bold">qcomp</emphasis>:
4168 <option>qcomp</option> trades off the number of bits allocated
4169 to "expensive" high-motion versus "cheap" low-motion frames. At
4170 one extreme, <option>qcomp=0</option> aims for true constant
4171 bitrate. Typically this would make high-motion scenes look completely
4172 awful, while low-motion scenes would probably look absolutely
4173 perfect, but would also use many times more bitrate than they
4174 would need in order to look merely excellent. At the other extreme,
4175 <option>qcomp=1</option> achieves nearly constant quantization parameter
4176 (QP). Constant QP does not look bad, but most people think it is more
4177 reasonable to shave some bitrate off of the extremely expensive scenes
4178 (where the loss of quality is not as noticeable) and reallocate it to
4179 the scenes that are easier to encode at excellent quality.
4180 <option>qcomp</option> is set to 0.6 by default, which may be slightly
4181 low for many peoples' taste (0.7-0.8 are also commonly used).
4184 <emphasis role="bold">keyint</emphasis>:
4185 <option>keyint</option> is solely for trading off file seekability against
4186 coding efficiency. By default, <option>keyint</option> is set to 250. In
4187 25fps material, this guarantees the ability to seek to within 10 seconds
4188 precision. If you think it would be important and useful to be able to
4189 seek within 5 seconds of precision, set <option>keyint=125</option>;
4190 this will hurt quality/bitrate slightly. If you care only about quality
4191 and not about seekability, you can set it to much higher values
4192 (understanding that there are diminishing returns which may become
4193 vanishingly low, or even zero). The video stream will still have seekable
4194 points as long as there are some scene changes.
4198 <emphasis role="bold">deblock</emphasis>:
4199 This topic is going to be a bit controversial.
4202 H.264 defines a simple deblocking procedure on I-blocks that uses
4203 pre-set strengths and thresholds depending on the QP of the block
4205 By default, high QP blocks are filtered heavily, and low QP blocks
4206 are not deblocked at all.
4207 The pre-set strengths defined by the standard are well-chosen and
4208 the odds are very good that they are PSNR-optimal for whatever
4209 video you are trying to encode.
4210 The <option>deblock</option> allow you to specify offsets to the preset
4211 deblocking thresholds.
4214 Many people seem to think it is a good idea to lower the deblocking
4215 filter strength by large amounts (say, -3).
4216 This is however almost never a good idea, and in most cases,
4217 people who are doing this do not understand very well how
4218 deblocking works by default.
4221 The first and most important thing to know about the in-loop
4222 deblocking filter is that the default thresholds are almost always
4224 In the rare cases that they are not optimal, the ideal offset is
4226 Adjusting deblocking parameters by a larger amount is almost
4227 guaranteed to hurt PSNR.
4228 Strengthening the filter will smear more details; weakening the
4229 filter will increase the appearance of blockiness.
4232 It is definitely a bad idea to lower the deblocking thresholds if
4233 your source is mainly low in spacial complexity (i.e., not a lot
4234 of detail or noise).
4235 The in-loop filter does a rather excellent job of concealing
4236 the artifacts that occur.
4237 If the source is high in spacial complexity, however, artifacts
4238 are less noticeable.
4239 This is because the ringing tends to look like detail or noise.
4240 Human visual perception easily notices when detail is removed,
4241 but it does not so easily notice when the noise is wrongly
4243 When it comes to subjective quality, noise and detail are somewhat
4245 By lowering the deblocking filter strength, you are most likely
4246 increasing error by adding ringing artifacts, but the eye does
4247 not notice because it confuses the artifacts with detail.
4250 This <emphasis role="bold">still</emphasis> does not justify
4251 lowering the deblocking filter strength, however.
4252 You can generally get better quality noise from postprocessing.
4253 If your H.264 encodes look too blurry or smeared, try playing with
4254 <option>-vf noise</option> when you play your encoded movie.
4255 <option>-vf noise=8a:4a</option> should conceal most mild
4257 It will almost certainly look better than the results you
4258 would have gotten just by fiddling with the deblocking filter.
4267 <sect2 id="menc-feat-x264-example-settings">
4268 <title>Encoding setting examples</title>
4271 The following settings are examples of different encoding
4272 option combinations that affect the speed vs quality tradeoff
4273 at the same target bitrate.
4277 All the encoding settings were tested on a 720x448 @30000/1001 fps
4278 video sample, the target bitrate was 900kbps, and the machine was an
4279 AMD-64 3400+ at 2400 MHz in 64 bits mode.
4280 Each encoding setting features the measured encoding speed (in
4281 frames per second) and the PSNR loss (in dB) compared to the "very
4282 high quality" setting.
4283 Please understand that depending on your source, your machine type
4284 and development advancements, you may get very different results.
4287 <informaltable frame="all">
4291 <entry>Description</entry>
4292 <entry>Encoding options</entry>
4293 <entry>speed (in fps)</entry>
4294 <entry>Relative PSNR loss (in dB)</entry>
4299 <entry>Very high quality</entry>
4300 <entry><option>subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b</option></entry>
4305 <entry>High quality</entry>
4306 <entry><option>subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b</option></entry>
4307 <entry>13fps</entry>
4308 <entry>-0.89dB</entry>
4312 <entry><option>subq=4:bframes=2:b_pyramid:weight_b</option></entry>
4313 <entry>17fps</entry>
4314 <entry>-1.48dB</entry>
4323 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4326 <sect1 id="menc-feat-video-for-windows">
4328 Encoding with the <systemitem class="library">Video For Windows</systemitem>
4333 Video for Windows provides simple encoding by means of binary video codecs.
4334 You can encode with the following codecs (if you have more, please tell us!)
4338 Note that support for this is very experimental and some codecs may not work
4339 correctly. Some codecs will only work in certain colorspaces, try
4340 <option>-vf format=bgr24</option> and <option>-vf format=yuy2</option>
4341 if a codec fails or gives wrong output.
4346 <sect2 id="menc-feat-enc-vfw-video-codecs">
4347 <title>Video for Windows supported codecs</title>
4350 <informaltable frame="all">
4354 <entry>Video codec file name</entry>
4355 <entry>Description (FourCC)</entry>
4356 <entry>md5sum</entry>
4357 <entry>Comment</entry>
4362 <entry>aslcodec_vfw.dll</entry>
4363 <entry>Alparysoft lossless codec vfw (ASLC)</entry>
4364 <entry>608af234a6ea4d90cdc7246af5f3f29a</entry>
4368 <entry>avimszh.dll</entry>
4369 <entry>AVImszh (MSZH)</entry>
4370 <entry>253118fe1eedea04a95ed6e5f4c28878</entry>
4371 <entry>needs <option>-vf format</option></entry>
4374 <entry>avizlib.dll</entry>
4375 <entry>AVIzlib (ZLIB)</entry>
4376 <entry>2f1cc76bbcf6d77d40d0e23392fa8eda</entry>
4380 <entry>divx.dll</entry>
4381 <entry>DivX4Windows-VFW</entry>
4382 <entry>acf35b2fc004a89c829531555d73f1e6</entry>
4386 <entry>huffyuv.dll</entry>
4387 <entry>HuffYUV (lossless) (HFYU)</entry>
4388 <entry>b74695b50230be4a6ef2c4293a58ac3b</entry>
4392 <entry>iccvid.dll</entry>
4393 <entry>Cinepak Video (cvid)</entry>
4394 <entry>cb3b7ee47ba7dbb3d23d34e274895133</entry>
4398 <entry>icmw_32.dll</entry>
4399 <entry>Motion Wavelets (MWV1)</entry>
4400 <entry>c9618a8fc73ce219ba918e3e09e227f2</entry>
4404 <entry>jp2avi.dll</entry>
4405 <entry>ImagePower MJPEG2000 (IPJ2)</entry>
4406 <entry>d860a11766da0d0ea064672c6833768b</entry>
4407 <entry><option>-vf flip</option></entry>
4410 <entry>m3jp2k32.dll</entry>
4411 <entry>Morgan MJPEG2000 (MJ2C)</entry>
4412 <entry>f3c174edcbaef7cb947d6357cdfde7ff</entry>
4416 <entry>m3jpeg32.dll</entry>
4417 <entry>Morgan Motion JPEG Codec (MJPEG)</entry>
4418 <entry>1cd13fff5960aa2aae43790242c323b1</entry>
4422 <entry>mpg4c32.dll</entry>
4423 <entry>Microsoft MPEG-4 v1/v2</entry>
4424 <entry>b5791ea23f33010d37ab8314681f1256</entry>
4428 <entry>tsccvid.dll</entry>
4429 <entry>TechSmith Camtasia Screen Codec (TSCC)</entry>
4430 <entry>8230d8560c41d444f249802a2700d1d5</entry>
4431 <entry>shareware error on windows</entry>
4434 <entry>vp31vfw.dll</entry>
4435 <entry>On2 Open Source VP3 Codec (VP31)</entry>
4436 <entry>845f3590ea489e2e45e876ab107ee7d2</entry>
4440 <entry>vp4vfw.dll</entry>
4441 <entry>On2 VP4 Personal Codec (VP40)</entry>
4442 <entry>fc5480a482ccc594c2898dcc4188b58f</entry>
4446 <entry>vp6vfw.dll</entry>
4447 <entry>On2 VP6 Personal Codec (VP60)</entry>
4448 <entry>04d635a364243013898fd09484f913fb</entry>
4452 <entry>vp7vfw.dll</entry>
4453 <entry>On2 VP7 Personal Codec (VP70)</entry>
4454 <entry>cb4cc3d4ea7c94a35f1d81c3d750bc8d</entry>
4455 <entry><option>-ffourcc VP70</option></entry>
4458 <entry>ViVD2.dll</entry>
4459 <entry>SoftMedia ViVD V2 codec VfW (GXVE)</entry>
4460 <entry>a7b4bf5cac630bb9262c3f80d8a773a1</entry>
4464 <entry>msulvc06.DLL</entry>
4465 <entry>MSU Lossless codec (MSUD)</entry>
4466 <entry>294bf9288f2f127bb86f00bfcc9ccdda</entry>
4468 Decodable by <application>Window Media Player</application>,
4469 not <application>MPlayer</application> (yet).
4473 <entry>camcodec.dll</entry>
4474 <entry>CamStudio lossless video codec (CSCD)</entry>
4475 <entry>0efe97ce08bb0e40162ab15ef3b45615</entry>
4476 <entry>sf.net/projects/camstudio</entry>
4482 The first column contains the codec names that should be passed after the
4483 <literal>codec</literal> parameter,
4484 like: <option>-xvfwopts codec=divx.dll</option>
4485 The FourCC code used by each codec is given in the parentheses.
4490 An example to convert an ISO DVD trailer to a VP6 flash video file
4491 using compdata bitrate settings:
4493 mencoder -dvd-device <replaceable>zeiram.iso</replaceable> dvd://7 -o <replaceable>trailer.flv</replaceable> \
4494 -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=onepass.mcf -oac mp3lame \
4495 -lameopts cbr:br=64 -af lavcresample=22050 -vf yadif,scale=320:240,flip \
4502 <sect2 id="menc-feat-video-for-windows-bitrate-settings">
4503 <title>Using vfw2menc to create a codec settings file.</title>
4506 To encode with the Video for Windows codecs, you will need to set bitrate
4507 and other options. This is known to work on x86 on both *NIX and Windows.
4510 First you must build the <application>vfw2menc</application> program.
4511 It is located in the <filename class="directory">TOOLS</filename> subdirectory
4512 of the MPlayer source tree.
4513 To build on Linux, this can be done using <application>Wine</application>:
4514 <screen>winegcc vfw2menc.c -o vfw2menc -lwinmm -lole32</screen>
4516 To build on Windows in <application>MinGW</application> or
4517 <application>Cygwin</application> use:
4518 <screen>gcc vfw2menc.c -o vfw2menc.exe -lwinmm -lole32</screen>
4520 To build on <application>MSVC</application> you will need getopt.
4521 Getopt can be found in the original <application>vfw2menc</application>
4522 archive available at:
4523 The <ulink url="http://oss.netfarm.it/mplayer-win32.php">MPlayer on win32</ulink> project.
4527 Below is an example with the VP6 codec.
4529 vfw2menc -f VP62 -d vp6vfw.dll -s firstpass.mcf
4531 This will open the VP6 codec dialog window.
4532 Repeat this step for the second pass
4533 and use <option>-s <replaceable>secondpass.mcf</replaceable></option>.
4537 Windows users can use
4538 <option>-xvfwopts codec=vp6vfw.dll:compdata=dialog</option> to have
4539 the codec dialog display before encoding starts.
4545 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4548 <sect1 id="menc-feat-quicktime-7">
4549 <title>Using <application>MEncoder</application> to create
4550 <application>QuickTime</application>-compatible files</title>
4553 <sect2 id="menc-feat-quicktime-7-why-use-it">
4554 <title>Why would one want to produce <application>QuickTime</application>-compatible Files?</title>
4557 There are several reasons why producing
4558 <application>QuickTime</application>-compatible files can be desirable.
4562 You want any computer illiterate to be able to watch your encode on
4563 any major platform (Windows, Mac OS X, Unices …).
4566 <application>QuickTime</application> is able to take advantage of more
4567 hardware and software acceleration features of Mac OS X than
4568 platform-independent players like <application>MPlayer</application>
4569 or <application>VLC</application>.
4570 That means that your encodes have a chance to be played smoothly by older
4571 G4-powered machines.
4574 <application>QuickTime</application> 7 supports the next-generation codec H.264,
4575 which yields significantly better picture quality than previous codec
4576 generations (MPEG-2, MPEG-4 …).
4581 <sect2 id="menc-feat-quicktime-7-constraints">
4582 <title><application>QuickTime</application> 7 limitations</title>
4585 <application>QuickTime</application> 7 supports H.264 video and AAC audio,
4586 but it does not support them muxed in the AVI container format.
4587 However, you can use <application>MEncoder</application> to encode
4588 the video and audio, and then use an external program such as
4589 <application>mp4creator</application> (part of the
4590 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>)
4591 to remux the video and audio tracks into an MP4 container.
4595 <application>QuickTime</application>'s support for H.264 is limited,
4596 so you will need to drop some advanced features.
4597 If you encode your video with features that
4598 <application>QuickTime</application> 7 does not support,
4599 <application>QuickTime</application>-based players will show you a pretty
4600 white screen instead of your expected video.
4605 <emphasis role="bold">B-frames</emphasis>:
4606 <application>QuickTime</application> 7 supports a maximum of 1 B-frame, i.e.
4607 <option>-x264encopts bframes=1</option>. This means that
4608 <option>b_pyramid</option> and <option>weight_b</option> will have no
4609 effect, since they require <option>bframes</option> to be greater than 1.
4612 <emphasis role="bold">Macroblocks</emphasis>:
4613 <application>QuickTime</application> 7 does not support 8x8 DCT macroblocks.
4614 This option (<option>8x8dct</option>) is off by default, so just be sure
4615 not to explicitly enable it. This also means that the <option>i8x8</option>
4616 option will have no effect, since it requires <option>8x8dct</option>.
4619 <emphasis role="bold">Aspect ratio</emphasis>:
4620 <application>QuickTime</application> 7 does not support SAR (sample
4621 aspect ratio) information in MPEG-4 files; it assumes that SAR=1. Read
4622 <link linkend="menc-feat-quicktime-7-scale">the section on scaling</link>
4629 <sect2 id="menc-feat-quicktime-7-crop">
4630 <title>Cropping</title>
4632 Suppose you want to rip your freshly bought copy of "The Chronicles of
4633 Narnia". Your DVD is region 1,
4634 which means it is NTSC. The example below would still apply to PAL,
4635 except you would omit <option>-ofps 24000/1001</option> and use slightly
4636 different <option>crop</option> and <option>scale</option> dimensions.
4640 After running <option>mplayer dvd://1</option>, you follow the process
4641 detailed in the section <link linkend="menc-feat-telecine">How to deal
4642 with telecine and interlacing in NTSC DVDs</link> and discover that it is
4643 24000/1001 fps progressive video. This simplifies the process somewhat,
4644 since you do not need to use an inverse telecine filter such as
4645 <option>pullup</option> or a deinterlacing filter such as
4646 <option>yadif</option>.
4650 Next, you need to crop out the black bars from the top and bottom of the
4651 video, as detailed in <link linkend="menc-feat-dvd-mpeg4-example-crop">this</link>
4657 <sect2 id="menc-feat-quicktime-7-scale">
4658 <title>Scaling</title>
4661 The next step is truly heartbreaking.
4662 <application>QuickTime</application> 7 does not support MPEG-4 videos
4663 with a sample aspect ratio other than 1, so you will need to upscale
4664 (which wastes a lot of disk space) or downscale (which loses some
4665 details of the source) the video to square pixels.
4666 Either way you do it, this is highly inefficient, but simply cannot
4667 be avoided if you want your video to be playable by
4668 <application>QuickTime</application> 7.
4669 <application>MEncoder</application> can apply the appropriate upscaling
4670 or downscaling by specifying respectively <option>-vf scale=-10:-1</option>
4671 or <option>-vf scale=-1:-10</option>.
4672 This will scale your video to the correct width for the cropped height,
4673 rounded to the closest multiple of 16 for optimal compression.
4674 Remember that if you are cropping, you should crop first, then scale:
4676 <screen>-vf crop=720:352:0:62,scale=-10:-1</screen>
4681 <sect2 id="menc-feat-quicktime-7-avsync">
4682 <title>A/V sync</title>
4685 Because you will be remuxing into a different container, you should
4686 always use the <option>harddup</option> option to ensure that duplicated
4687 frames are actually duplicated in the video output. Without this option,
4688 <application>MEncoder</application> will simply put a marker in the video
4689 stream that a frame was duplicated, and rely on the client software to
4690 show the same frame twice. Unfortunately, this "soft duplication" does
4691 not survive remuxing, so the audio would slowly lose sync with the video.
4695 The final filter chain looks like this:
4696 <screen>-vf crop=720:352:0:62,scale=-10:-1,harddup</screen>
4701 <sect2 id="menc-feat-quicktime-7-bitrate">
4702 <title>Bitrate</title>
4705 As always, the selection of bitrate is a matter of the technical properties
4706 of the source, as explained
4707 <link linkend="menc-feat-dvd-mpeg4-resolution-bitrate">here</link>, as
4708 well as a matter of taste.
4709 This movie has a fair bit of action and lots of detail, but H.264 video
4710 looks good at much lower bitrates than XviD or other MPEG-4 codecs.
4711 After much experimentation, the author of this guide chose to encode
4712 this movie at 900kbps, and thought that it looked very good.
4713 You may decrease bitrate if you need to save more space, or increase
4714 it if you need to improve quality.
4719 <sect2 id="menc-feat-quicktime-7-example">
4720 <title>Encoding example</title>
4723 You are now ready to encode the video. Since you care about
4724 quality, of course you will be doing a two-pass encode. To shave off
4725 some encoding time, you can specify the <option>turbo</option> option
4726 on the first pass; this reduces <option>subq</option> and
4727 <option>frameref</option> to 1. To save some disk space, you can
4728 use the <option>ss</option> option to strip off the first few seconds
4729 of the video. (I found that this particular movie has 32 seconds of
4730 credits and logos.) <option>bframes</option> can be 0 or 1.
4731 The other options are documented in <link
4732 linkend="menc-feat-x264-encoding-options-speedvquality">Encoding with
4733 the <systemitem class="library">x264</systemitem> codec</link> and
4736 <screen>mencoder dvd://1 -o /dev/null -ss 32 -ovc x264 \
4737 -x264encopts pass=1:turbo:bitrate=900:bframes=1:\
4738 me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
4739 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4740 -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
4741 -ofps 24000/1001</screen>
4743 If you have a multi-processor machine, don't miss the opportunity to
4744 dramatically speed-up encoding by enabling
4745 <link linkend="menc-feat-x264-encoding-options-speedvquality-threads">
4746 <systemitem class="library">x264</systemitem>'s multi-threading mode</link>
4747 by adding <option>threads=auto</option> to your <option>x264encopts</option>
4752 The second pass is the same, except that you specify the output file
4753 and set <option>pass=2</option>.
4755 <screen>mencoder dvd://1 <emphasis role="bold">-o narnia.avi</emphasis> -ss 32 -ovc x264 \
4756 -x264encopts <emphasis role="bold">pass=2</emphasis>:turbo:bitrate=900:frameref=5:bframes=1:\
4757 me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
4758 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4759 -oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
4760 -ofps 24000/1001</screen>
4764 The resulting AVI should play perfectly in
4765 <application>MPlayer</application>, but of course
4766 <application>QuickTime</application> can not play it because it does
4767 not support H.264 muxed in AVI.
4768 So the next step is to remux the video into an MP4 container.
4772 <sect2 id="menc-feat-quicktime-7-remux">
4773 <title>Remuxing as MP4</title>
4776 There are several ways to remux AVI files to MP4. You can use
4777 <application>mp4creator</application>, which is part of the
4778 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>.
4782 First, demux the AVI into separate audio and video streams using
4783 <application>MPlayer</application>.
4785 <screen>mplayer narnia.avi -dumpaudio -dumpfile narnia.aac
4786 mplayer narnia.avi -dumpvideo -dumpfile narnia.h264</screen>
4788 The file names are important; <application>mp4creator</application>
4789 requires that AAC audio streams be named <systemitem>.aac</systemitem>
4790 and H.264 video streams be named <systemitem>.h264</systemitem>.
4794 Now use <application>mp4creator</application> to create a new
4795 MP4 file out of the audio and video streams.
4797 <screen>mp4creator -create=narnia.aac narnia.mp4
4798 mp4creator -create=narnia.h264 -rate=23.976 narnia.mp4</screen>
4800 Unlike the encoding step, you must specify the framerate as a
4801 decimal (such as 23.976), not a fraction (such as 24000/1001).
4805 This <systemitem>narnia.mp4</systemitem> file should now be playable
4806 with any <application>QuickTime</application> 7 application, such as
4807 <application>QuickTime Player</application> or
4808 <application>iTunes</application>. If you are planning to view the
4809 video in a web browser with the <application>QuickTime</application>
4810 plugin, you should also hint the movie so that the
4811 <application>QuickTime</application> plugin can start playing it
4812 while it is still downloading. <application>mp4creator</application>
4813 can create these hint tracks:
4815 <screen>mp4creator -hint=1 narnia.mp4
4816 mp4creator -hint=2 narnia.mp4
4817 mp4creator -optimize narnia.mp4</screen>
4819 You can check the final result to ensure that the hint tracks were
4820 created successfully:
4822 <screen>mp4creator -list narnia.mp4</screen>
4824 You should see a list of tracks: 1 audio, 1 video, and 2 hint tracks.
4826 <screen>Track Type Info
4827 1 audio MPEG-4 AAC LC, 8548.714 secs, 190 kbps, 48000 Hz
4828 2 video H264 Main@5.1, 8549.132 secs, 899 kbps, 848x352 @ 23.976001 fps
4829 3 hint Payload mpeg4-generic for track 1
4830 4 hint Payload H264 for track 2
4836 <sect2 id="menc-feat-quicktime-7-metadata">
4837 <title>Adding metadata tags</title>
4840 If you want to add tags to your video that show up in iTunes, you can use
4841 <ulink url="http://atomicparsley.sourceforge.net/">AtomicParsley</ulink>.
4843 <screen>AtomicParsley narnia.mp4 --metaEnema --title "The Chronicles of Narnia" --year 2005 --stik Movie --freefree --overWrite</screen>
4845 The <option>--metaEnema</option> option removes any existing metadata
4846 (<application>mp4creator</application> inserts its name in the
4847 "encoding tool" tag), and <option>--freefree</option> reclaims the
4848 space from the deleted metadata.
4849 The <option>--stik</option> option sets the type of video (such as Movie
4850 or TV Show), which iTunes uses to group related video files.
4851 The <option>--overWrite</option> option overwrites the original file;
4852 without it, <application>AtomicParsley</application> creates a new
4853 auto-named file in the same directory and leaves the original file
4862 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4865 <sect1 id="menc-feat-vcd-dvd">
4866 <title>Using <application>MEncoder</application>
4867 to create VCD/SVCD/DVD-compliant files</title>
4869 <sect2 id="menc-feat-vcd-dvd-constraints">
4870 <title>Format Constraints</title>
4873 <application>MEncoder</application> is capable of creating VCD, SCVD
4874 and DVD format MPEG files using the
4875 <systemitem class="library">libavcodec</systemitem> library.
4876 These files can then be used in conjunction with
4877 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>
4879 <ulink url="http://dvdauthor.sourceforge.net/">dvdauthor</ulink>
4880 to create discs that will play on a standard set-top player.
4884 The DVD, SVCD, and VCD formats are subject to heavy constraints.
4885 Only a small selection of encoded picture sizes and aspect ratios are
4887 If your movie does not already meet these requirements, you may have
4888 to scale, crop or add black borders to the picture to make it
4893 <sect3 id="menc-feat-vcd-dvd-constraints-resolution">
4894 <title>Format Constraints</title>
4896 <informaltable frame="all">
4900 <entry>Format</entry>
4901 <entry>Resolution</entry>
4902 <entry>V. Codec</entry>
4903 <entry>V. Bitrate</entry>
4904 <entry>Sample Rate</entry>
4905 <entry>A. Codec</entry>
4906 <entry>A. Bitrate</entry>
4908 <entry>Aspect</entry>
4913 <entry>NTSC DVD</entry>
4914 <entry>720x480, 704x480, 352x480, 352x240</entry>
4915 <entry>MPEG-2</entry>
4916 <entry>9800 kbps</entry>
4917 <entry>48000 Hz</entry>
4918 <entry>AC-3,PCM</entry>
4919 <entry>1536 kbps (max)</entry>
4920 <entry>30000/1001, 24000/1001</entry>
4921 <entry>4:3, 16:9 (only for 720x480)</entry>
4924 <entry>NTSC DVD</entry>
4925 <entry>352x240<footnote id='fn-rare-resolutions'><para>
4926 These resolutions are rarely used for DVDs because
4927 they are fairly low quality.</para></footnote></entry>
4928 <entry>MPEG-1</entry>
4929 <entry>1856 kbps</entry>
4930 <entry>48000 Hz</entry>
4931 <entry>AC-3,PCM</entry>
4932 <entry>1536 kbps (max)</entry>
4933 <entry>30000/1001, 24000/1001</entry>
4934 <entry>4:3, 16:9</entry>
4937 <entry>NTSC SVCD</entry>
4938 <entry>480x480</entry>
4939 <entry>MPEG-2</entry>
4940 <entry>2600 kbps</entry>
4941 <entry>44100 Hz</entry>
4943 <entry>384 kbps (max)</entry>
4944 <entry>30000/1001</entry>
4948 <entry>NTSC VCD</entry>
4949 <entry>352x240</entry>
4950 <entry>MPEG-1</entry>
4951 <entry>1150 kbps</entry>
4952 <entry>44100 Hz</entry>
4954 <entry>224 kbps</entry>
4955 <entry>24000/1001, 30000/1001</entry>
4959 <entry>PAL DVD</entry>
4960 <entry>720x576, 704x576, 352x576, 352x288</entry>
4961 <entry>MPEG-2</entry>
4962 <entry>9800 kbps</entry>
4963 <entry>48000 Hz</entry>
4964 <entry>MP2,AC-3,PCM</entry>
4965 <entry>1536 kbps (max)</entry>
4967 <entry>4:3, 16:9 (only for 720x576)</entry>
4970 <entry>PAL DVD</entry>
4971 <entry>352x288<footnoteref linkend='fn-rare-resolutions'/></entry>
4972 <entry>MPEG-1</entry>
4973 <entry>1856 kbps</entry>
4974 <entry>48000 Hz</entry>
4975 <entry>MP2,AC-3,PCM</entry>
4976 <entry>1536 kbps (max)</entry>
4978 <entry>4:3, 16:9</entry>
4981 <entry>PAL SVCD</entry>
4982 <entry>480x576</entry>
4983 <entry>MPEG-2</entry>
4984 <entry>2600 kbps</entry>
4985 <entry>44100 Hz</entry>
4987 <entry>384 kbps (max)</entry>
4992 <entry>PAL VCD</entry>
4993 <entry>352x288</entry>
4994 <entry>MPEG-1</entry>
4995 <entry>1152 kbps</entry>
4996 <entry>44100 Hz</entry>
4998 <entry>224 kbps</entry>
5007 If your movie has 2.35:1 aspect (most recent action movies), you will
5008 have to add black borders or crop the movie down to 16:9 to make a DVD or VCD.
5009 If you add black borders, try to align them at 16-pixel boundaries in
5010 order to minimize the impact on encoding performance.
5011 Thankfully DVD has sufficiently excessive bitrate that you do not have
5012 to worry too much about encoding efficiency, but SVCD and VCD are
5013 highly bitrate-starved and require effort to obtain acceptable quality.
5018 <sect3 id="menc-feat-vcd-dvd-constraints-gop">
5019 <title>GOP Size Constraints</title>
5022 DVD, VCD, and SVCD also constrain you to relatively low
5023 GOP (Group of Pictures) sizes.
5024 For 30 fps material the largest allowed GOP size is 18.
5025 For 25 or 24 fps, the maximum is 15.
5026 The GOP size is set using the <option>keyint</option> option.
5031 <sect3 id="menc-feat-vcd-dvd-constraints-bitrate">
5032 <title>Bitrate Constraints</title>
5035 VCD video is required to be CBR at 1152 kbps.
5036 This highly limiting constraint also comes along with an extremely low vbv
5037 buffer size of 327 kilobits.
5038 SVCD allows varying video bitrates up to 2500 kbps, and a somewhat less
5039 restrictive vbv buffer size of 917 kilobits is allowed.
5040 DVD video bitrates may range anywhere up to 9800 kbps (though typical
5041 bitrates are about half that), and the vbv buffer size is 1835 kilobits.
5048 <sect2 id="menc-feat-vcd-dvd-output">
5049 <title>Output Options</title>
5052 <application>MEncoder</application> has options to control the output
5054 Using these options we can instruct it to create the correct type of
5059 The options for VCD and SVCD are called xvcd and xsvcd, because they
5060 are extended formats.
5061 They are not strictly compliant, mainly because the output does not
5062 contain scan offsets.
5063 If you need to generate an SVCD image, you should pass the output file to
5064 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>.
5069 <screen>-of mpeg -mpegopts format=xvcd</screen>
5074 <screen>-of mpeg -mpegopts format=xsvcd</screen>
5078 DVD (with timestamps on every frame, if possible):
5079 <screen>-of mpeg -mpegopts format=dvd:tsaf</screen>
5083 DVD with NTSC Pullup:
5084 <screen>-of mpeg -mpegopts format=dvd:tsaf:telecine -ofps 24000/1001</screen>
5085 This allows 24000/1001 fps progressive content to be encoded at 30000/1001
5086 fps whilst maintaining DVD-compliance.
5090 <sect3 id="menc-feat-vcd-dvd-output-aspect">
5091 <title>Aspect Ratio</title>
5094 The aspect argument of <option>-lavcopts</option> is used to encode
5095 the aspect ratio of the file.
5096 During playback the aspect ratio is used to restore the video to the
5101 16:9 or "Widescreen"
5102 <screen>-lavcopts aspect=16/9</screen>
5107 <screen>-lavcopts aspect=4/3</screen>
5111 2.35:1 or "Cinemascope" NTSC
5112 <screen>-vf scale=720:368,expand=720:480 -lavcopts aspect=16/9</screen>
5113 To calculate the correct scaling size, use the expanded NTSC width of
5118 2.35:1 or "Cinemascope" PAL
5119 <screen>-vf scale=720:432,expand=720:576 -lavcopts aspect=16/9</screen>
5120 To calculate the correct scaling size, use the expanded PAL width of
5126 <sect3 id="menc-feat-vcd-dvd-a-v-sync">
5127 <title>Maintaining A/V sync</title>
5130 In order to maintain audio/video synchronization throughout the encode,
5131 <application>MEncoder</application> has to drop or duplicate frames.
5132 This works rather well when muxing into an AVI file, but is almost
5133 guaranteed to fail to maintain A/V sync with other muxers such as MPEG.
5134 This is why it is necessary to append the
5135 <option>harddup</option> video filter at the end of the filter chain
5136 to avoid this kind of problem.
5137 You can find more technical information about <option>harddup</option>
5139 <link linkend="menc-feat-dvd-mpeg4-muxing-filter-issues">Improving muxing and A/V sync reliability</link>
5140 or in the manual page.
5145 <sect3 id="menc-feat-vcd-dvd-output-srate">
5146 <title>Sample Rate Conversion</title>
5149 If the audio sample rate in the original file is not the same as
5150 required by the target format, sample rate conversion is required.
5151 This is achieved using the <option>-srate</option> option and
5152 the <option>-af lavcresample</option> audio filter together.
5157 <screen>-srate 48000 -af lavcresample=48000</screen>
5162 <screen>-srate 44100 -af lavcresample=44100</screen>
5169 <sect2 id="menc-feat-vcd-dvd-lavc">
5170 <title>Using libavcodec for VCD/SVCD/DVD Encoding</title>
5172 <sect3 id="menc-feat-vcd-dvd-lavc-intro">
5173 <title>Introduction</title>
5176 <systemitem class="library">libavcodec</systemitem> can be used to
5177 create VCD/SVCD/DVD compliant video by using the appropriate options.
5182 <sect3 id="menc-feat-vcd-dvd-lavc-options">
5183 <title>lavcopts</title>
5186 This is a list of fields in <option>-lavcopts</option> that you may
5187 be required to change in order to make a complaint movie for VCD, SVCD,
5193 <emphasis role="bold">acodec</emphasis>:
5194 <option>mp2</option> for VCD, SVCD, or PAL DVD;
5195 <option>ac3</option> is most commonly used for DVD.
5196 PCM audio may also be used for DVD, but this is mostly a big waste of
5198 Note that MP3 audio is not compliant for any of these formats, but
5199 players often have no problem playing it anyway.
5202 <emphasis role="bold">abitrate</emphasis>:
5203 224 for VCD; up to 384 for SVCD; up to 1536 for DVD, but commonly
5204 used values range from 192 kbps for stereo to 384 kbps for 5.1 channel
5208 <emphasis role="bold">vcodec</emphasis>:
5209 <option>mpeg1video</option> for VCD;
5210 <option>mpeg2video</option> for SVCD;
5211 <option>mpeg2video</option> is usually used for DVD but you may also use
5212 <option>mpeg1video</option> for CIF resolutions.
5215 <emphasis role="bold">keyint</emphasis>:
5216 Used to set the GOP size.
5217 18 for 30fps material, or 15 for 25/24 fps material.
5218 Commercial producers seem to prefer keyframe intervals of 12.
5219 It is possible to make this much larger and still retain compatibility
5221 A <option>keyint</option> of 25 should never cause any problems.
5224 <emphasis role="bold">vrc_buf_size</emphasis>:
5225 327 for VCD, 917 for SVCD, and 1835 for DVD.
5228 <emphasis role="bold">vrc_minrate</emphasis>:
5229 1152, for VCD. May be left alone for SVCD and DVD.
5232 <emphasis role="bold">vrc_maxrate</emphasis>:
5233 1152 for VCD; 2500 for SVCD; 9800 for DVD.
5234 For SVCD and DVD, you might wish to use lower values depending on your
5235 own personal preferences and requirements.
5238 <emphasis role="bold">vbitrate</emphasis>:
5240 up to 2500 for SVCD;
5242 For the latter two formats, vbitrate should be set based on personal
5244 For instance, if you insist on fitting 20 or so hours on a DVD, you
5245 could use vbitrate=400.
5246 The resulting video quality would probably be quite bad.
5247 If you are trying to squeeze out the maximum possible quality on a DVD,
5248 use vbitrate=9800, but be warned that this could constrain you to less
5249 than an hour of video on a single-layer DVD.
5252 <emphasis role="bold">vstrict</emphasis>:
5253 <option>vstrict</option>=0 should be used to create DVDs.
5254 Without this option, <application>MEncoder</application> creates a
5255 stream that cannot be correctly decoded by some standalone DVD
5262 <sect3 id="menc-feat-vcd-dvd-lavc-examples">
5263 <title>Examples</title>
5266 This is a typical minimum set of <option>-lavcopts</option> for
5272 -lavcopts vcodec=mpeg1video:vrc_buf_size=327:vrc_minrate=1152:\
5273 vrc_maxrate=1152:vbitrate=1152:keyint=15:acodec=mp2
5280 -lavcopts vcodec=mpeg2video:vrc_buf_size=917:vrc_maxrate=2500:vbitrate=1800:\
5281 keyint=15:acodec=mp2
5288 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5289 keyint=15:vstrict=0:acodec=ac3
5295 <sect3 id="menc-feat-vcd-dvd-lavc-advanced">
5296 <title>Advanced Options</title>
5299 For higher quality encoding, you may also wish to add quality-enhancing
5300 options to lavcopts, such as <option>trell</option>,
5301 <option>mbd=2</option>, and others.
5302 Note that <option>qpel</option> and <option>v4mv</option>, while often
5303 useful with MPEG-4, are not usable with MPEG-1 or MPEG-2.
5304 Also, if you are trying to make a very high quality DVD encode, it may
5305 be useful to add <option>dc=10</option> to lavcopts.
5306 Doing so may help reduce the appearance of blocks in flat-colored areas.
5307 Putting it all together, this is an example of a set of lavcopts for a
5313 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=8000:\
5314 keyint=15:trell:mbd=2:precmp=2:subcmp=2:cmp=2:dia=-10:predia=-10:cbp:mv0:\
5315 vqmin=1:lmin=1:dc=10:vstrict=0
5323 <sect2 id="menc-feat-vcd-dvd-audio">
5324 <title>Encoding Audio</title>
5327 VCD and SVCD support MPEG-1 layer II audio, using one of
5328 <systemitem class="library">toolame</systemitem>,
5329 <systemitem class="library">twolame</systemitem>,
5330 or <systemitem class="library">libavcodec</systemitem>'s MP2 encoder.
5331 The libavcodec MP2 is far from being as good as the other two libraries,
5332 however it should always be available to use.
5333 VCD only supports constant bitrate audio (CBR) whereas SVCD supports
5334 variable bitrate (VBR), too.
5335 Be careful when using VBR because some bad standalone players might not
5336 support it too well.
5340 For DVD audio, <systemitem class="library">libavcodec</systemitem>'s
5345 <sect3 id="menc-feat-vcd-dvd-audio-toolame">
5346 <title>toolame</title>
5350 <screen>-oac toolame -toolameopts br=224</screen>
5355 <sect3 id="menc-feat-vcd-dvd-audio-twolame">
5356 <title>twolame</title>
5360 <screen>-oac twolame -twolameopts br=224</screen>
5365 <sect3 id="menc-feat-vcd-dvd-audio-lavc">
5366 <title>libavcodec</title>
5369 For DVD with 2 channel sound:
5370 <screen>-oac lavc -lavcopts acodec=ac3:abitrate=192</screen>
5374 For DVD with 5.1 channel sound:
5375 <screen>-channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=384</screen>
5380 <screen>-oac lavc -lavcopts acodec=mp2:abitrate=224</screen>
5387 <sect2 id="menc-feat-vcd-dvd-all">
5388 <title>Putting it all Together</title>
5391 This section shows some complete commands for creating VCD/SVCD/DVD
5396 <sect3 id="menc-feat-vcd-dvd-all-pal-dvd">
5397 <title>PAL DVD</title>
5401 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5402 -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
5403 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5404 keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 \
5405 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5411 <sect3 id="menc-feat-vcd-dvd-all-ntsc-dvd">
5412 <title>NTSC DVD</title>
5416 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5417 -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 \
5418 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5419 keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 \
5420 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5426 <sect3 id="menc-feat-vcd-dvd-all-pal-ac3-copy">
5427 <title>PAL AVI Containing AC-3 Audio to DVD</title>
5430 If the source already has AC-3 audio, use -oac copy instead of re-encoding it.
5432 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
5433 -vf scale=720:576,harddup -ofps 25 \
5434 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
5435 keyint=15:vstrict=0:aspect=16/9 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5441 <sect3 id="menc-feat-vcd-dvd-all-ntsc-ac3-copy">
5442 <title>NTSC AVI Containing AC-3 Audio to DVD</title>
5445 If the source already has AC-3 audio, and is NTSC @ 24000/1001 fps:
5447 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd:tsaf:telecine \
5448 -vf scale=720:480,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:\
5449 vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:aspect=16/9 -ofps 24000/1001 \
5450 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5456 <sect3 id="menc-feat-vcd-dvd-all-pal-svcd">
5457 <title>PAL SVCD</title>
5461 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
5462 scale=480:576,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5463 vcodec=mpeg2video:mbd=2:keyint=15:vrc_buf_size=917:vrc_minrate=600:\
5464 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224:aspect=16/9 -ofps 25 \
5465 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5471 <sect3 id="menc-feat-vcd-dvd-all-ntsc-svcd">
5472 <title>NTSC SVCD</title>
5476 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
5477 scale=480:480,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5478 vcodec=mpeg2video:mbd=2:keyint=18:vrc_buf_size=917:vrc_minrate=600:\
5479 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224:aspect=16/9 -ofps 30000/1001 \
5480 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5486 <sect3 id="menc-feat-vcd-dvd-all-pal-vcd">
5487 <title>PAL VCD</title>
5491 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
5492 scale=352:288,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5493 vcodec=mpeg1video:keyint=15:vrc_buf_size=327:vrc_minrate=1152:\
5494 vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224:aspect=16/9 -ofps 25 \
5495 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
5501 <sect3 id="menc-feat-vcd-dvd-all-ntsc-vcd">
5502 <title>NTSC VCD</title>
5506 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
5507 scale=352:240,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
5508 vcodec=mpeg1video:keyint=18:vrc_buf_size=327:vrc_minrate=1152:\
5509 vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224:aspect=16/9 -ofps 30000/1001 \
5510 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>