comparison DOCS/xml/en/encoding-guide.xml @ 21843:7e5c4075fcdf

explain how to use MEncoder to create QuickTime-compatible files Mainly based on a patch by Mark Pilgrim % pilgrim A gmail P com % Original thread: Date: Oct 19, 2006 9:50 PM Subject: [MPlayer-DOCS] Interested in contributing case studies
author gpoirier
date Wed, 10 Jan 2007 00:08:16 +0000
parents 88c9d0f343e7
children 0d7fe401a5a7
comparison
equal deleted inserted replaced
21842:f0040ff1ba40 21843:7e5c4075fcdf
2896 24000/1001 fps progressive video, which means that we need not use an inverse 2896 24000/1001 fps progressive video, which means that we need not use an inverse
2897 telecine filter, such as <option>pullup</option> or 2897 telecine filter, such as <option>pullup</option> or
2898 <option>filmdint</option>. 2898 <option>filmdint</option>.
2899 </para> 2899 </para>
2900 2900
2901 <para> 2901 <para id="menc-feat-dvd-mpeg4-example-crop">
2902 Next, we want to determine the appropriate crop rectangle, so we use the 2902 Next, we want to determine the appropriate crop rectangle, so we use the
2903 cropdetect filter: 2903 cropdetect filter:
2904 <screen>mplayer dvd://1 -vf cropdetect</screen> 2904 <screen>mplayer dvd://1 -vf cropdetect</screen>
2905 Make sure you seek to a fully filled frame (such as a bright scene), and 2905 Make sure you seek to a fully filled frame (such as a bright scene,
2906 past the opening credits and logos), and
2906 you will see in <application>MPlayer</application>'s console output: 2907 you will see in <application>MPlayer</application>'s console output:
2907 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen> 2908 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen>
2908 We then play the movie back with this filter to test its correctness: 2909 We then play the movie back with this filter to test its correctness:
2909 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen> 2910 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen>
2910 And we see that it looks perfectly fine. Next, we ensure the width and 2911 And we see that it looks perfectly fine. Next, we ensure the width and
4080 4081
4081 4082
4082 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 4083 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4083 4084
4084 4085
4086 <sect1 id="menc-feat-quicktime-7">
4087 <title>Using <application>MEncoder</application> to create
4088 <application>QuickTime</application>-compatible files</title>
4089
4090
4091 <sect2 id="menc-feat-quicktime-7-why-use-it">
4092 <title>Why would one want to produce <application>QuickTime</application>-compatible Files?</title>
4093
4094 <para>
4095 There are several reasons why producing
4096 <application>QuickTime</application>-compatible files can be desirable.
4097 </para>
4098 <itemizedlist>
4099 <listitem><para>
4100 You want any computer illiterate to be able to watch your encode on
4101 any major platform (Windows, Mac OSX, Unices &hellip;).
4102 </para></listitem>
4103 <listitem><para>
4104 <application>QuickTime</application> is able to take advantage of more
4105 hardware and software acceleration features of Mac OSX than
4106 platform-independent players like <application>MPlayer</application>
4107 or <application>VLC</application>.
4108 That means that your encodes have a chance to be played smoothly by older
4109 G4-powered machines.
4110 </para></listitem>
4111 <listitem><para>
4112 <application>QuickTime</application> 7 support the next-generation codec H.264,
4113 which yields significantly better picture quality than previous codec
4114 generations (MPEG-2, MPEG-4 &hellip;).
4115 </para></listitem>
4116 </itemizedlist>
4117 </sect2>
4118
4119 <sect2 id="menc-feat-quicktime-7-constraints">
4120 <title><application>QuickTime</application> 7 limitations</title>
4121
4122 <para>
4123 <application>QuickTime</application> 7 supports H.264 video and AAC audio,
4124 but it does not support them muxed in AVI container format.
4125 However, you can use <application>MEncoder</application> to encode
4126 the video and audio, and then use an external program such as
4127 <application>mp4creator</application> (part of the
4128 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>)
4129 to remux the video and audio tracks into an MP4 container.
4130 </para>
4131
4132 <para>
4133 <application>QuickTime</application>'s support for H.264 is limited,
4134 so you will need to drop some advanced features.
4135 If you encode your video with features that
4136 <application>QuickTime</application> 7 does not support,
4137 <application>QuickTime</application>-based players will show you a pretty
4138 white screen instead of your expected video.
4139 </para>
4140
4141 <itemizedlist>
4142 <listitem><para>
4143 <emphasis role="bold">B-frames</emphasis>:
4144 <application>QuickTime</application> 7 supports a maximum of 1 B-frame, i.e.
4145 <option>-x264encopts bframes=1</option>. This means that
4146 <option>b_pyramid</option> and <option>weight_b</option> will have no
4147 effect, since they require <option>bframes</option> to be greater than 1.
4148 </para></listitem>
4149 <listitem><para>
4150 <emphasis role="bold">Macroblocks</emphasis>:
4151 <application>QuickTime</application> 7 does not support 8x8 DCT macroblocks.
4152 This option (<option>8x8dct</option>) is off by default, so just be sure
4153 not to explicitly enable it. This also means that the <option>i8x8</option>
4154 option will have no effect, since it requires <option>8x8dct</option>.
4155 </para></listitem>
4156 <listitem><para>
4157 <emphasis role="bold">Aspect ratio</emphasis>:
4158 <application>QuickTime</application> 7 does not support SAR (sample
4159 aspect ratio) information in MPEG-4 files; it assumes that SAR=1. Read
4160 <link linkend="menc-feat-quicktime-7-scale">the section on scaling</link>
4161 for a workaround.
4162 </para></listitem>
4163 </itemizedlist>
4164
4165 </sect2>
4166
4167 <sect2 id="menc-feat-quicktime-7-crop">
4168 <title>Cropping</title>
4169 <para>
4170 Suppose you want to rip your freshly bought copy of "The Chronicles of
4171 Narnia" Your DVD is region 1,
4172 which means it is NTSC. The example below would still apply to PAL,
4173 except you would omit <option>-ofps 24000/1001</option> and use slightly
4174 different <option>crop</option> and <option>scale</option> dimensions.
4175 </para>
4176
4177 <para>
4178 After running <option>mplayer dvd://1</option>, you follow the process
4179 detailed in the section <link linkend="menc-feat-telecine">How to deal
4180 with telecine and interlacing in NTSC DVDs</link> and discover that it is
4181 24000/1001 fps progressive video. This simplifies the process somewhat,
4182 since you do not need to use an inverse telecine filter such as
4183 <option>pullup</option> or a deinterlacing filter such as
4184 <option>yadif</option>.
4185 </para>
4186
4187 <para>
4188 Next, you need to crop out the black bars from the top and bottom of the
4189 video, as detailed in <link linkend="menc-feat-dvd-mpeg4-example-crop">this</link>
4190 previous section.
4191 </para>
4192
4193 </sect2>
4194
4195 <sect2 id="menc-feat-quicktime-7-scale">
4196 <title>Scaling</title>
4197
4198 <para>
4199 The next step is truly heartbreaking.
4200 <application>QuickTime</application> 7 does not support MPEG-4 videos
4201 with a sample aspect ratio other than 1, so you will need to upscale
4202 (which wastes a lot of disk space) or downscale (which loses some
4203 details of the source) the video to square pixels.
4204 Either way you do it, this is highly inefficient, but simply can not
4205 be avoided if you want your video to be playable by
4206 <application>QuickTime</application> 7.
4207 <application>MEncoder</application> can apply the appropriate upscaling
4208 or downscaling by specifying respectively <option>-vf scale=-10:-1</option>
4209 or <option>-vf scale=-1:-10</option>.
4210 This will scale your video to the correct width for the cropped height,
4211 rounded to the closest multiple of 16 for optimal compression.
4212 Remember that if you are cropping, you should crop first, then scale:
4213
4214 <screen>-vf crop=720:352:0:62,scale=-10:-1</screen>
4215 </para>
4216
4217 </sect2>
4218
4219 <sect2 id="menc-feat-quicktime-7-avsync">
4220 <title>A/V sync</title>
4221
4222 <para>
4223 Because you will be remuxing into a different container, you should
4224 always use the <option>harddup</option> option to ensure that duplicated
4225 frames are actually duplicated in the video output. Without this option,
4226 <application>MEncoder</application> will simply put a marker in the video
4227 stream that a frame was duplicated, and rely on the client software to
4228 show the same frame twice. Unfortunately, this "soft duplication" does
4229 not survive remuxing, so the audio would slowly lose sync with the video.
4230 </para>
4231
4232 <para>
4233 The final filter chain looks like this:
4234 <screen>-vf crop=720:352:0:62,scale=-10:-1,harddup</screen>
4235 </para>
4236
4237 </sect2>
4238
4239 <sect2 id="menc-feat-quicktime-7-bitrate">
4240 <title>Bitrate</title>
4241
4242 <para>
4243 As always, the selection of bitrate is a matter the technical properties
4244 of the source, as explained
4245 <link linkend="menc-feat-dvd-mpeg4-resolution-bitrate">here</link>, as
4246 well as a matter of taste.
4247 This movie has a fair bit of action and lots of detail, but H.264 video
4248 looks good at much lower bitrates than XviD or other MPEG-4 codecs.
4249 After much experimentation, the author of this guide chose to encode
4250 this movie at 900kbps, and thought that it looked very good.
4251 You may decrease bitrate if you need to save more space, or increase
4252 it if you need to improve quality.
4253 </para>
4254
4255 </sect2>
4256
4257 <sect2 id="menc-feat-quicktime-7-example">
4258 <title>Encoding example</title>
4259
4260 <para>
4261 You are now ready to encode the video. Since you care about
4262 quality, of course you will be doing a two-pass encode. To shave off
4263 some encoding time, you can specify the <option>turbo</option> option
4264 on the first pass; this reduces <option>subq</option> and
4265 <option>frameref</option> to 1. To save some disk space, you can
4266 use the <option>ss</option> option to strip off the first few seconds
4267 of the video. (I found that this particular movie has 32 seconds of
4268 credits and logos.) <option>bframes</option> can be 0 or 1.
4269 The other options are documented in <link
4270 linkend="menc-feat-x264-encoding-options-speedvquality">Encoding with
4271 the <systemitem class="library">x264</systemitem> codec</link> and
4272 the man page.
4273
4274 <screen>mencoder dvd://1 -o /dev/null -ss 32 -ovc x264 \
4275 -x264encopts pass=1:turbo:bitrate=900:bframes=1:\
4276 me=umh:4x4mv:trellis=1:qp_step=4:qcomp=0.7:direct_pred=3:keyint=300 \
4277 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4278 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 \
4279 -ofps 24000/1001</screen>
4280
4281 If you have multi-processor machine, you can add
4282 <option>threads=auto</option>. This increases encoding speed by about
4283 94% per CPU core, with very little quality penalty (about 0.005dB for
4284 dual processor, about 0.01dB for a quad processor machine).
4285 </para>
4286
4287 <para>
4288 The second pass is the same, except that you specify the output file
4289 and set <option>pass=2</option>.
4290
4291 <screen>mencoder dvd://1 <emphasis role="bold">-o narnia.avi</emphasis> -ss 32 -ovc x264 \
4292 -x264encopts <emphasis role="bold">pass=2</emphasis>:turbo:bitrate=900:frameref=5:bframes=1:\
4293 me=umh:4x4mv:trellis=1:qp_step=4:qcomp=0.7:direct_pred=3:keyint=300 \
4294 -vf crop=720:352:0:62,scale=-10:-1,harddup \
4295 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 \
4296 -ofps 24000/1001</screen>
4297 </para>
4298
4299 <para>
4300 The resulting AVI should play perfectly in
4301 <application>MPlayer</application>, but of course
4302 <application>QuickTime</application> can not play it because it does
4303 not support H.264 muxed in AVI.
4304 So the next step is to remux the video into an MP4 container.
4305 </para>
4306 </sect2>
4307
4308 <sect2 id="menc-feat-quicktime-7-remux">
4309 <title>Remuxing as MP4</title>
4310
4311 <para>
4312 There are several ways to remux AVI files to MP4. You can use
4313 <application>mp4creator</application>, which is part of the
4314 <ulink url="http://mpeg4ip.sourceforge.net/">MPEG4IP suite</ulink>.
4315 </para>
4316
4317 <para>
4318 First, demux the AVI into separate audio and video streams using
4319 <application>MPlayer</application>.
4320
4321 <screen>mplayer narnia.avi -dumpaudio -dumpfile narnia.aac
4322 mplayer narnia.avi -dumpvideo -dumpfile narnia.h264</screen>
4323
4324 The filenames are important; <application>mp4creator</application>
4325 requires that AAC audio streams be named <systemitem>.aac</systemitem>
4326 and H.264 video streams be named <systemitem>.h264</systemitem>.
4327 </para>
4328
4329 <para>
4330 Now use <application>mp4creator</application> to create a new
4331 MP4 file out of the audio and video streams.
4332
4333 <screen>mp4creator -create=narnia.aac narnia.mp4
4334 mp4creator -create=narnia.h264 -rate=23.976 narnia.mp4</screen>
4335
4336 Unlike the encoding step, you must specify the framerate as a
4337 decimal (such as 23.976), not a fraction (such as 24000/1001).
4338 </para>
4339
4340 <para>
4341 This <systemitem>narnia.mp4</systemitem> file should now be playable
4342 with any <application>QuickTime</application> 7 application, such as
4343 <application>QuickTime Player</application> or
4344 <application>iTunes</application>. If you are planning to view the
4345 video in a web browser with the <application>QuickTime</application>
4346 plugin, you should also hint the movie so that the
4347 <application>QuickTime</application> plugin can start playing it
4348 while it is still downloading. <application>mp4creator</application>
4349 can create these hint tracks:
4350
4351 <screen>mp4creator -hint=1 narnia.mp4
4352 mp4creator -hint=2 narnia.mp4
4353 mp4creator -optimize narnia.mp4</screen>
4354
4355 You can check the final result to ensure that the hint tracks were
4356 created successfully:
4357
4358 <screen>mp4creator -list narnia.mp4</screen>
4359
4360 You should see a list of tracks: 1 audio, 1 video, and 2 hint tracks.
4361
4362 <screen>Track Type Info
4363 1 audio MPEG-4 AAC LC, 8548.714 secs, 190 kbps, 48000 Hz
4364 2 video H264 Main@5.1, 8549.132 secs, 899 kbps, 848x352 @ 23.976001 fps
4365 3 hint Payload mpeg4-generic for track 1
4366 4 hint Payload H264 for track 2
4367 </screen>
4368 </para>
4369
4370 </sect2>
4371
4372 <sect2 id="menc-feat-quicktime-7-metadata">
4373 <title>Adding metadata tags</title>
4374
4375 <para>
4376 If you want to add tags to your video that show up in iTunes, you can use
4377 <ulink url="http://atomicparsley.sourceforge.net/">AtomicParsley</ulink>.
4378
4379 <screen>AtomicParsley narnia.mp4 --metaEnema --title "The Chronicles of Narnia" --year 2005 --stik Movie --freefree --overWrite</screen>
4380
4381 The <option>--metaEnema</option> option removes any existing metadata
4382 (<application>mp4creator</application> inserts its name in the
4383 "encoding tool" tag), and <option>--freefree</option> reclaims the
4384 space from the deleted metadata.
4385 The <option>--stik</option> option sets the type of video (such as Movie
4386 or TV Show), which iTunes uses to group related video files.
4387 The <option>--overWrite</option> option overwrites the original file;
4388 without it, <application>AtomicParsley</application> creates a new
4389 auto-named file in the same directory and leaves the original file
4390 untouched.
4391 </para>
4392
4393 </sect2>
4394
4395 </sect1>
4396
4397
4398 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
4399
4400
4085 <sect1 id="menc-feat-video-for-windows"> 4401 <sect1 id="menc-feat-video-for-windows">
4086 <title> 4402 <title>
4087 Encoding with the <systemitem class="library">Video For Windows</systemitem> 4403 Encoding with the <systemitem class="library">Video For Windows</systemitem>
4088 codec family 4404 codec family
4089 </title> 4405 </title>