libavcodec provides simple encoding to a lot of interesting video and audio formats. You can encode to the following codecs (more or less up to date):
Video codec name | Description |
mjpeg | Motion JPEG |
ljpeg | lossless JPEG |
h261 | H.261 |
h263 | H.263 |
h263p | H.263+ |
mpeg4 | ISO standard MPEG-4 (DivX 5, XviD compatible) |
msmpeg4 | pre-standard MPEG-4 variant by MS, v3 (AKA DivX3) |
msmpeg4v2 | pre-standard MPEG-4 by MS, v2 (used in old ASF files) |
wmv1 | Windows Media Video, version 1 (AKA WMV7) |
wmv2 | Windows Media Video, version 2 (AKA WMV8) |
rv10 | RealVideo 1.0 |
rv20 | RealVideo 2.0 |
mpeg1video | MPEG-1 video |
mpeg2video | MPEG-2 video |
huffyuv | lossless compression |
asv1 | ASUS Video v1 |
asv2 | ASUS Video v2 |
ffv1 | FFmpeg's lossless video codec |
svq1 | Sorenson video 1 |
flv | Sorenson H.263 used in Flash Video |
dvvideo | Sony Digital Video |
snow | FFmpeg's experimental wavelet-based codec |
The first column contains the codec names that should be passed after the vcodec config, like: -lavcopts vcodec=msmpeg4
An example with MJPEG compression:
mencoder dvd://2 -o title2.avi -ovc lavc -lavcopts vcodec=mjpeg -oac copy
Audio codec name | Description |
mp2 | MPEG Layer 2 |
ac3 | AC3, AKA Dolby Digital |
adpcm_ima_wav | IMA adaptive PCM (4 bits per sample, 4:1 compression) |
sonic | experimental lossy/lossless codec |
The first column contains the codec names that should be passed after the acodec option, like: -lavcopts acodec=ac3
An example with AC3 compression:
mencoder dvd://2 -o title2.avi -oac lavc -lavcopts acodec=ac3 -ovc copy
Contrary to libavcodec's video codecs, its audio codecs do not make a wise usage of the bits they are given as they lack some minimal psychoacoustic model (if at all) which most other codec implementations feature. However, note that all these audio codecs are very fast and work out-of-the-box everywhere MEncoder has been compiled with libavcodec (which is the case most of time), and do not depend on external libraries.
Ideally, you would probably want to be able to just tell the encoder to switch into "high quality" mode and move on. That would probably be nice, but unfortunately hard to implement as different encoding options yield different quality results depending on the source material. That is because compression depends on the visual properties of the video in question. For example, anime and live action have very different properties and thus require different options to obtain optimum encoding. The good news is that some options should never be left out, like mbd=2, trell, and v4mv. See below for a detailed description of common encoding options.
Options to adjust:
Options not recommended to play with:
The following settings are examples of different encoding option combinations that affect the speed vs quality tradeoff at the same target bitrate.
All the encoding settings were tested on a 720x448 @30000/1001 fps video sample, the target bitrate was 900kbps, and the machine was an AMD-64 3400+ at 2400 MHz in 64 bits mode. Each encoding setting features the measured encoding speed (in frames per second) and the PSNR loss (in dB) compared to the "very high quality" setting. Please understand that depending on your source, your machine type and development advancements, you may get very different results.
Description | Encoding options | speed (in fps) | Relative PSNR loss (in dB) |
Very high quality | 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 | 6fps | 0dB |
High quality | 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 | 15fps | -0.5dB |
Fast | vcodec=mpeg4:mbd=2:trell:v4mv:turbo | 42fps | -0.74dB |
Realtime | vcodec=mpeg4:mbd=2:turbo | 54fps | -1.21dB |
With this feature of libavcodec(http://www.mplayerhq.hu/DOCS/HTML/en/video-codecs.html#ffmpeg) you are able to set custom inter (I-frames/keyframes) and intra (P-frames/predicted frames) matrices. It is supported by many of the codecs: mpeg1video and mpeg2video are reported as working.
A typical usage of this feature is to set the matrices preferred by the KVCD(http://www.kvcd.net/) specifications.
The KVCD "Notch" Quantization Matrix:
Intra:
8 9 12 22 26 27 29 34 9 10 14 26 27 29 34 37 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 29 34 37 38 40 48 58 29 34 37 38 40 48 58 69 34 37 38 40 48 58 69 79
Inter:
16 18 20 22 24 26 28 30 18 20 22 24 26 28 30 32 20 22 24 26 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 36 38 40 28 30 32 34 36 38 42 42 30 32 34 36 38 40 42 44
Usage:
$ mencoder input.avi -o output.avi -oac copy -ovc lavc -lavcopts inter_matrix=...:intra_matrix=...
$ mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg2video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37, 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, 29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79 :inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26, 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, 36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -oac copy -o svcd.mpg
So, you have just bought your shiny new copy of Harry Potter and the Chamber of Secrets (widescreen edition, of course), and you want to rip this DVD so that you can add it to your Home Theatre PC. This is a region 1 DVD, so it is NTSC. The example below will still apply to PAL, except you will omit -ofps 24000/1001 (because the output framerate is the same as the input framerate), and of course the crop dimensions will be different.
After running mplayer dvd://1, we follow the process detailed in the section How to deal with telecine and interlacing in NTSC DVDs(http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-telecine.html) and discover that it is 24000/1001 fps progressive video, which means that we need not use an inverse telecine filter, such as pullup or filmdint.
Next, we want to determine the appropriate crop rectangle, so we use the cropdetect filter:
mplayer dvd://1 -vf cropdetect
Make sure you seek to a fully filled frame (such as a bright scene), and you will see in MPlayer's console output:
crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)
We then play the movie back with this filter to test its correctness:
mplayer dvd://1 -vf crop=720:362:0:58
And we see that it looks perfectly fine. Next, we ensure the width and height are a multiple of 16. The width is fine, however the height is not. Since we did not fail 7th grade math, we know that the nearest multiple of 16 lower than 362 is 352.
We could just use crop=720:352:0:58, but it would be nice to take a little off the top and a little off the bottom so that we retain the center. We have shrunk the height by 10 pixels, but we do not want to increase the y-offset by 5-pixels since that is an odd number and will adversely affect quality. Instead, we will increase the y-offset by 4 pixels:
mplayer dvd://1 -vf crop=720:352:0:62
Another reason to shave pixels from both the top and the bottom is that we ensure we have eliminated any half-black pixels if they exist. Note that if your video is telecined, make sure the pullup filter (or whichever inverse telecine filter you decide to use) appears in the filter chain before you crop. If it is interlaced, deinterlace before cropping. (If you choose to preserve the interlaced video, then make sure your vertical crop offset is a multiple of 4.)
If you are really concerned about losing those 10 pixels, you might prefer instead to scale the dimensions down to the nearest multiple of 16. The filter chain would look like:
-vf crop=720:362:0:58,scale=720:352
Scaling the video down like this will mean that some small amount of detail is lost, though it probably will not be perceptible. Scaling up will result in lower quality (unless you increase the bitrate). Cropping discards those pixels altogether. It is a tradeoff that you will want to consider for each circumstance. For example, if the DVD video was made for television, you might want to avoid vertical scaling, since the line sampling corresponds to the way the content was originally recorded.
On inspection, we see that our movie has a fair bit of action and high amounts of detail, so we pick 2400Kbit for our bitrate.
We are now ready to do the two pass encode. Pass one:
mencoder dvd://1 -ofps 24000/1001 -oac copy -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \ -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=1 \ -o Harry_Potter_2.avi
And pass two is the same, except that we specify vpass=2:
mencoder dvd://1 -ofps 24000/1001 -oac copy -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \ -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=2 \ -o Harry_Potter_2.avi
The options v4mv:mbd=2:trell will greatly increase the quality at the expense of encoding time. There is little reason to leave these options out when the primary goal is quality. The options cmp=3:subcmp=3:mbcmp=3 select a comparison function that yields higher quality than the defaults. You might try experimenting with this parameter (refer to the man page for the possible values) as different functions can have a large impact on quality depending on the source material. For example, if you find libavcodec produces too much blocky artifacting, you could try selecting the experimental NSSE as comparison function via *cmp=10.
For this movie, the resulting AVI will be 138 minutes long and nearly 3GB. And because you said that file size does not matter, this is a perfectly acceptable size. However, if you had wanted it smaller, you could try a lower bitrate. Increasing bitrates have diminishing returns, so while we might clearly see an improvement from 1800Kbit to 2000Kbit, it might not be so noticeable above 2000Kbit. Feel free to experiment until you are happy.
Because we passed the source video through a denoise filter, you may want to add some of it back during playback. This, along with the spp post-processing filter, drastically improves the perception of quality and helps eliminate blocky artifacts in the video. With MPlayer's autoq option, you can vary the amount of post-processing done by the spp filter depending on available CPU. Also, at this point, you may want to apply gamma and/or color correction to best suit your display. For example:
mplayer Harry_Potter_2.avi -vf spp,noise=9ah:5ah,eq2=1.2 -autoq 3
Documents
読み方
イントロ
インストール
使い方
CD/DVD使い方
FAQ
コンテナ
コデック
Videoデバイス
Audioデバイス
TV入力
Radio入力
Ports
MEncoder基礎
エンコガイド
Doc/bugreports?
FrontPage
■MPlayer
├Manuals
├Documents
└カテゴリ
■GENERAL
├MEMO
├LINK
├雑談所
├最近の更新
└popular
■Other Tools
├ffmpeg
├mkvmerge
├mp4box
├MPEG Streamclip
├QTCoffee
└x264cli
■About
└About Wiki
本日 | 2 |
昨日 | 1 |
累積 | 3040 |