comparison DOCS/xml/en/mencoder.xml @ 9675:62c5a17038ba

XML version of MPlayer's doc
author nicolas
date Sun, 23 Mar 2003 23:35:12 +0000
parents
children 142c42fa0986
comparison
equal deleted inserted replaced
9674:461f71ba8af4 9675:62c5a17038ba
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <chapter id="mencoder">
3 <title>Encoding with MEncoder</title>
4
5 <para>
6 For the complete list of available <application>MEncoder</application> options
7 and examples, please see the man page. For a series of hands-on examples and
8 detailed guides on using several encoding parameters, read the
9 <ulink url="../../tech/encoding-tips.txt">encoding-tips</ulink> that were
10 collected from several mailing list threads on mplayer-users. Search the
11 <ulink url="http://mplayerhq.hu/pipermail/mplayer-users/">archives</ulink>
12 for a wealth of discussions about all aspects of and problems related to
13 encoding with <application>MEncoder</application>.
14 </para>
15
16 <sect1 id="menc-feat-divx4">
17 <title>Encoding 2 or 3-pass MPEG-4 (&quot;DivX&quot;)</title>
18
19 <formalpara>
20 <title>2-pass encoding</title>
21 <para>
22 The name comes from the fact that this method encodes the file <emphasis>twice</emphasis>.
23 The first encoding (dubbed pass) creates some temporary files
24 (<filename>*.log</filename>) with a size of few megabytes, do not delete
25 them yet (you can delete the AVI). In the second pass, the 2-pass output
26 file is created, using the bitrate data from the temporary files. The
27 resulting file will have much better image quality. If this is the first
28 time you heard about this, you should consult some guides available on the
29 Net.
30 </para>
31 </formalpara>
32
33 <para>
34 This example shows how to encode a DVD to a 2-pass MPEG-4 (&quot;DivX&quot;) AVI.
35 Just two commands are needed:
36 <screen>rm frameno.avi</screen>
37 remove this file, which can come from a previous 3-pass encoding (it interferes
38 with current one)
39 <screen>
40 mencoder -dvd 2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o movie.avi
41 mencoder -dvd 2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.avi
42 </screen>
43 </para>
44
45 <formalpara>
46 <title>3-pass encoding</title>
47 <para>
48 This is an extension of 2-pass encoding, where the audio encoding takes
49 place in a separate pass. This method enables estimation of recommended
50 video bitrate in order to fit on a CD. Also, the audio is encoded only
51 once, unlike in 2-pass mode. The schematics:
52 </para>
53 </formalpara>
54
55 <procedure>
56 <step><para>
57 Remove conflicting temporary file:
58 <screen>rm frameno.avi</screen>
59 </para></step>
60 <step><para>
61 <emphasis>First pass:</emphasis>
62
63 <screen>mencoder <replaceable>file/DVD</replaceable> -ovc frameno -oac mp3lame -lameopts vbr=3 -o frameno.avi</screen>
64
65 An audio-only avi file will be created, containing
66 <emphasis role="bold">only</emphasis> the requested audio stream. Don't forget
67 <option>-lameopts</option>, if you need to set it. If you were encoding a
68 long movie, <application>MEncoder</application> prints the recommended
69 bitrate values for 650Mb, 700Mb, and 800Mb destination sizes, after this
70 pass finishes.
71 </para></step>
72 <step><para>
73 <emphasis>Second pass:</emphasis>
74 <screen>
75 mencoder <replaceable>file/DVD</replaceable> -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=<replaceable>bitrate</replaceable><!--
76 --></screen>
77 This is the first pass of video encoding. Optionally specify the video
78 bitrate MEncoder printed at the end of the previous pass.
79 </para></step>
80 <step><para>
81 <emphasis>Third pass:</emphasis>
82 <screen>
83 mencoder <replaceable>file/DVD</replaceable> -oac copy -pass 2 \
84 -ovc divx4 -divx4opts br=<replaceable>bitrate</replaceable>
85 </screen>
86 This is the second pass of video encoding. Specify the same bitrate
87 as in the previous pass unless you really know what you are doing.
88 In this pass, audio from <filename>frameno.avi</filename> will be
89 inserted into the destination file...and it's all ready!
90 </para></step>
91 </procedure>
92
93 <example>
94 <title>Example of 3-pass encoding</title>
95 <para>
96 <screen>rm frameno.avi</screen>
97 remove this file, which can come from a previous 3-pass encoding
98 (it interferes with current one)
99 <screen>
100 mencoder -dvd 2 -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3
101 mencoder -dvd 2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o movie.avi
102 mencoder -dvd 2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.avi
103 </screen>
104 </para>
105 </example>
106 </sect1>
107
108 <sect1 id="menc-feat-mpeg">
109 <title>Encoding to MPEG format</title>
110 <para>
111 <application>MEncoder</application> can create MPEG (MPEG-PS) format output
112 files. It's probably useful only with libavcodec's <emphasis>mpeg1video</emphasis>
113 codec, because players - except <application>MPlayer</application> - expect MPEG1
114 video, and MPEG1 layer 2 (MP2) audio streams in MPEG files.
115 </para>
116
117 <para>
118 this feature is not very useful right now, aside that it probably has many bugs,
119 but the more importantly because MEncoder currently cannot encode MPEG1 layer 2
120 (MP2) audio, which all other players expect in MPEG files.
121 </para>
122
123 <para>
124 To change MEncoder's output file format, use the <option>-of mpeg</option> option.
125 </para>
126
127 <para>
128 Example:
129 <screen>
130 mencoder -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video -oac copy <replaceable>other options</replaceable> media.avi -o output.mpg
131 </screen>
132 </para>
133 </sect1>
134
135
136 <sect1 id="menc-feat-rescale">
137 <title>Rescaling movies</title>
138
139 <para>
140 Often the need to resize movie images' size emerges. Its reasons can be
141 many: decreasing file size, network bandwidth,etc. Most people even do
142 rescaling when converting DVDs or SVCDs to DivX AVI. This is <emphasis role="bold">bad</emphasis>.
143 Instead of even you doing so, read the <link linkend="aspect">Preserving aspect ratio</link>
144 section.
145 </para>
146
147 <para>
148 The scaling process is handled by the <literal>scale</literal> video filter:
149 <option>-vop scale=<replaceable>width</replaceable>:<replaceable>height</replaceable></option>.
150 Its quality can be set with the <option>-sws</option> option.
151 If it's not specified, <application>MEncoder</application> will use 0: fast
152 bilinear.
153 </para>
154
155 <para>
156 Usage:
157 <screen>
158 mencoder <replaceable>input.mpg</replaceable> -ovc lavc -lavcopts vcodec=mpeg4 -vop scale=640:480-o <replaceable>output.avi</replaceable>
159 </screen>
160 </para>
161 </sect1>
162
163
164 <sect1 id="menc-feat-streamcopy">
165 <title>Stream copying</title>
166
167 <para>
168 <application>MEncoder</application> can handle input streams in two ways:
169 <emphasis role="bold">encode</emphasis> or <emphasis role="bold">copy</emphasis>
170 them. This section is about <emphasis role="bold">copying</emphasis>.
171 </para>
172
173 <itemizedlist>
174 <listitem><para>
175 <emphasis role="bold">Video stream</emphasis> (option <option>-ovc copy</option>):
176 nice stuff can be done :) Like, putting (not converting!) FLI or VIVO or
177 MPEG1 video into an AVI file! Of course only
178 <application>MPlayer</application> can play such files :) And it probably
179 has no real life value at all. Rationally: video stream copying can be
180 useful for example when only the audio stream has to be encoded (like,
181 uncompressed PCM to MP3).
182 </para></listitem>
183 <listitem><para>
184 <emphasis role="bold">Audio stream</emphasis> (option <option>-oac copy</option>):
185 straightforward. It is possible to take an external audio file (MP3,
186 Vorbis) and mux it into the output stream. Use the
187 <option>-audiofile <replaceable>filename</replaceable></option> option
188 for this.
189 </para></listitem>
190 </itemizedlist>
191 </sect1>
192
193
194 <sect1 id="menc-feat-fix-avi">
195 <title>Fixing AVIs with broken index or interleaving</title>
196
197 <para>
198 Easiest thing. We simply copy the video and audio streams, and
199 <application>MEncoder</application> generates the index. Of course this cannot fix possible bugs in
200 the video and/or audio streams. It also fixes files with broken interleaving,
201 thus the <option>-ni</option> option won't be needed for them anymore.
202 </para>
203
204 <para>
205 Command:
206 <screen>
207 mencoder -idx <replaceable>input.avi</replaceable> -ovc copy -oac copy -o <replaceable>output.avi</replaceable><!--
208 --></screen>
209 </para>
210
211
212 <sect2 id="menc-feat-appending">
213 <title>Appending multiple AVI files</title>
214
215 <para>
216 As a side-effect, the broken AVI fixer function enables MEncoder to append
217 2 (or more) AVI files:
218 </para>
219
220 <para>
221 Command:
222 <screen>cat 1.avi 2.avi | mencoder -noidx -ovc copy -oac copy -o output.avi -</screen>
223 </para>
224
225 <note><para>
226 This expects <filename>1.avi</filename> and <filename>2.avi</filename> to use
227 the same codecs, resolution, stream rate etc, and at least <filename>1.avi</filename>
228 must not be broken. You may need to fix your input AVI files first, as described
229 <link linkend="menc-feat-fix-avi">above</link>.
230 </para></note>
231 </sect2>
232 </sect1>
233
234 <sect1 id="menc-feat-enc-libavcodec">
235 <title>Encoding with the libavcodec codec family</title>
236
237 <para>
238 <link linkend="ffmpeg">libavcodec</link> provides simple encoding to a lot
239 of interesting video and audio formats (currently its audio codecs are
240 unsupported). You can encode to the following codecs:
241
242 <informaltable frame="all">
243 <tgroup cols="2">
244 <thead>
245 <row><entry>Codec name</entry><entry>Description</entry></row>
246 </thead>
247 <tbody>
248 <row><entry>mjpeg</entry><entry>
249 Motion JPEG
250 </entry></row>
251 <row><entry>h263</entry><entry>
252 H263
253 </entry></row>
254 <row><entry>h263p</entry><entry>
255 H263 Plus
256 </entry></row>
257 <row><entry>mpeg4</entry><entry>
258 ISO standard MPEG-4 (DivX 5, XVID compatible)
259 </entry></row>
260 <row><entry>msmpeg4</entry><entry>
261 pre-standard MPEG-4 variant by MS, v3 (aka DivX3)
262 </entry></row>
263 <row><entry>msmpeg4v2</entry><entry>
264 pre-standard MPEG-4 by MS, v2 (used in old asf files)
265 </entry></row>
266 <row><entry>wmv1</entry><entry>
267 Windows Media Video, version 1 (aka WMV7)
268 </entry></row>
269 <row><entry>rv10</entry><entry>
270 an old RealVideo codec
271 </entry></row>
272 <row><entry>mpeg1video</entry><entry>
273 MPEG1 video :)
274 </entry></row>
275 <row><entry>huffyuv</entry><entry>
276 lossless compression
277 </entry></row>
278 </tbody>
279 </tgroup>
280 </informaltable>
281
282 The first column contains the codec names that should be passed after the
283 <literal>vcodec</literal> config, like: <option>-lavcopts vcodec=msmpeg4</option>
284 </para>
285
286 <informalexample>
287 <para>
288 An example, with MJPEG compression:
289 <screen>mencoder -dvd 2 -o title2.avi -ovc lavc -lavcopts vcodec=mjpeg -oac copy</screen>
290 </para>
291 </informalexample>
292 </sect1>
293
294
295 <sect1 id="menc-feat-enc-images">
296 <title>Encoding from multiple input image files (JPEGs,PNGs or TGAs)</title>
297
298 <para>
299 <application>MEncoder</application> is capable of creating movies from one
300 or more JPEG, PNG or TGA files. With simple framecopy it can create MJPEG
301 (Motion JPEG), MPNG (Motion PNG) or MTGA (Motion TGA) files.
302 </para>
303
304 <orderedlist>
305 <title>Explanation of the process:</title>
306 <listitem><para>
307 <application>MEncoder</application> <emphasis>decodes</emphasis> the input image(s) with
308 <systemitem class="library">libjpeg</systemitem> (when decoding PNGs, it
309 will use <systemitem class="library">libpng</systemitem>).
310 </para></listitem>
311 <listitem><para>
312 <application>MEncoder</application> then feeds the decoded image to the
313 chosen video compressor (DivX4, Xvid, ffmpeg msmpeg4, etc.).
314 </para></listitem>
315 </orderedlist>
316
317 <formalpara>
318 <title>Examples</title>
319 <para>
320 The explanation of the <option>-mf</option> option can be found below in
321 the man page.
322
323 <informalexample>
324 <para>
325 Creating a DivX4 file from all the JPEG files in the current dir:
326 <screen>
327 mencoder -mf on:w=800:h=600:fps=25 -ovc divx4 -o output.avi \*.jpg<!--
328 --></screen>
329 </para>
330 </informalexample>
331
332 <informalexample>
333 <para>
334 Creating a DivX4 file from some JPEG files in the current dir:
335 <screen>
336 mencoder -mf on:w=800:h=600:fps=25 -ovc divx4 -o output.avi frame001.jpg,frame002.jpg <!--
337 --></screen>
338 </para>
339 </informalexample>
340
341 <informalexample>
342 <para>
343 Creating a Motion JPEG (MJPEG) file from all the JPEG files in the current
344 dir:
345 <screen>
346 mencoder -mf on:w=800:h=600:fps=25 -ovc copy -o output.avi \*.jpg<!--
347 --></screen>
348 </para>
349 </informalexample>
350
351 <informalexample>
352 <para>
353 Creating an uncompressed file from all the PNG files in the current dir:
354 <screen>
355 mencoder -mf on:w=800:h=600:fps=25:type=png -ovc raw -o output.avi \*.png<!--
356 --></screen>
357 </para>
358 </informalexample>
359
360 <note><para>
361 Width must be integer multiple of 4, it's a limitation of the RAW RGB AVI format.
362 </para></note>
363
364 <informalexample>
365 <para>
366 Creating a Motion PNG (MPNG) file from all the PNG files in the current
367 dir:
368 <screen>
369 mencoder -mf on:w=800:h=600:fps=25:type=png -ovc copy -o output.avi \*.png<!--
370 --></screen>
371 </para>
372 </informalexample>
373
374 <informalexample>
375 <para>
376 Creating a Motion TGA (MTGA) file from all the TGA files in the current
377 dir:
378 <screen>
379 mencoder -mf on:w=800:h=600:fps=25:type=tga -ovc copy -o output.avi \*.tga<!--
380 --></screen>
381 </para>
382 </informalexample>
383
384 </para>
385 </formalpara>
386 </sect1>
387
388
389 <sect1 id="menc-feat-extractsub">
390 <title>Extracting DVD subtitles to Vobsub file</title>
391
392 <para>
393 <application>MEncoder</application> is capable of extracting subtitles from
394 a DVD into Vobsub fomat files. They consist of a pair of files ending in
395 <filename>.idx</filename> and <filename>.sub</filename> and are usually
396 packaged in a single <filename>.rar</filename> archive.
397 <application>MPlayer</application> can play these with the
398 <option>-vobsub</option> and <option>-vobsubid</option> options.
399 </para>
400
401 <para>
402 You specify the basename (i.e without the <filename>.idx</filename> or
403 <filename>.sub</filename> extension) of the output files with
404 <option>-vobsubout</option> and the index for this subtitle in the
405 resulting files with <option>-vobsuboutindex</option>.
406 </para>
407
408 <para>
409 If the input is not from a DVD you should use <option>-ifo</option> to
410 indicate the <filename>.ifo</filename> file needed to construct the
411 resulting <filename>.idx</filename> file.
412 </para>
413
414 <para>
415 If the input is not from a DVD and you do not have the
416 <filename>.ifo</filename> file you will need to use the
417 <option>-vobsubid</option> option to let it know what language id to put in
418 the <filename>.idx</filename> file.
419 </para>
420
421 <para>
422 Each run will append the running subtitle if the <filename>.idx</filename>
423 and <filename>.sub</filename> files already exist. So you should remove any
424 before starting.
425 </para>
426
427 <example>
428 <title>Copying two subtitles from a DVD while doing 3-pass encoding</title>
429 <screen>
430 rm subtitles.idx subtitles.sub
431 mencoder -dvd 1 -vobsubout subtitles -vobsuboutindex 0 -sid 2 -o frameno.avi -ovc frameno
432 mencoder -dvd 1 -oac copy -ovc divx4 -pass 1
433 mencoder -dvd 1 -oac copy -ovc divx4 -pass 2 -vobsubout subtitles -vobsuboutindex 1 -sid 5<!--
434 --></screen>
435 </example>
436
437 <example>
438 <title>Copying a french subtitle from an MPEG file</title>
439 <screen>
440 rm subtitles.idx subtitles.sub
441 mencoder movie.mpg -ifo movie.ifo -vobsubout subtitles -vobsuboutindex 0 -vobsuboutid fr -sid 1<!--
442 --></screen>
443 </example>
444
445 </sect1>
446
447 <sect1 id="aspect">
448 <title>Preserving aspect ratio</title>
449 <para>
450 DVDs and SVCDs (i.e. MPEG1/2) files contain an aspect ratio value, which
451 describes how should the player scale the video stream, so humans won't
452 have egg heads (ex.: 480x480 + 4:3 = 640x480). However when encoding to AVI
453 (DivX) files, you have be aware that AVI headers don't store this value.
454 Rescaling the movie is disgusting and time consuming, there must be a better
455 feature!
456 </para>
457
458 <para>There is</para>
459
460 <para>
461 MPEG4 has an unique feature: the video stream can contain its needed aspect
462 ratio. Yes, just like MPEG1/2 files (DVD, SVCD). Regretfully, there are
463 <emphasis role="bold">no</emphasis> video players outside which support this
464 attribute. Except <application>MPlayer</application>.
465 </para>
466
467 <para>
468 This feature can be used only with <emphasis role="bold">libavcodec</emphasis>'s
469 <systemitem>mpeg4</systemitem> codec. Keep in mind: although <application>MPlayer</application>
470 will correctly play the created file, other players will use the wrong aspect
471 ratio.
472 </para>
473
474 <para>
475 You seriously should crop the black bands over and below the movie image.
476 See the manpage about the usage of the <systemitem>cropdetect</systemitem> and
477 <systemitem>crop</systemitem> filters.
478 </para>
479
480 <formalpara>
481 <title>Usage</title>
482 <para>
483 <screen>mencoder sample-svcd.mpg -ovc lavc -lavcopts vcodec=mpeg4:aspect=16.0/9.0 -vop crop=714:548:0:14 -oac copy -o output.avi</screen>
484 </para>
485 </formalpara>
486 </sect1>
487
488 </chapter>