📄 encoding-tips.txt
字号:
TIPS FOR ENCODING OLD BLACK & WHITE MOVIES:I found myself that 4:3 B&W old movies are very hard to compress well. Inaddition to the 4:3 aspect ratio which eats lots of bits, those movies aretypically very "noisy", which doesn't help at all. Anyway :> After a few tries I am > still a little bit disappointed with the video quality. Since it is a > "dark" movies, there is a lot of black on the pictures, and on the > encoded avi I can see a lot of annoying "mpeg squares". I am using > avifile codec, but the best I think is to give you the command line I > used to encode a preview of the result: > > First pass: > mencoder TITLE01-ANGLE1.VOB -oac copy -ovc lavc -lavcopts > vcodec=mpeg4:vhq:vpass=1:vbitrate=800:keyint=48 -ofps 23.976 -npp lb > -ss 2:00 -endpos 0:30 -vf scale -zoom -xy 640 -o movie.avi 1) keyint=48 is way too low. The default value is 250, this is in *frames*not seconds. Keyframes are significantly larger than P or B frames, so theless keyframes you have, better the overall movie will be. (huh, like YodaI speak ;). Try keyint=300 or 350. Don't go beyond that if you wantrelatively precise seeking.2) you may want to play with vlelim and vcelim options. This can gives youa significant "quality" boost. Try one of these couples :vlelim=-2:vcelim=3vlelim=-3:vcelim=5vlelim=-4:vcelim=7(and yes, there's a minus)3) crop & rescale the movie before passing it to the codec. First crop themovie to not encode black bars if there's any. For a 1h40mn moviecompressed to a 700 MB file, I would try something between 512x384 and480x320. Don't go below that if you want something relatively sharp whenviewed fullscreen.4) I would recommend using the Ogg Vorbis audio codec with the .ogmcontainer format. Ogg Vorbis compress audio better than MP3. On a typicalold, mono-only audio stream, a 45 kbits/s Vorbis stream is ok. How toextract & compress an audio stream from a ripped DVD (mplayer dvd://1-dumpstream) :rm -f audiodump.pcm ; mkfifo -m 600 audiodump.pcmmplayer -quiet -vc null -vo null -aid 128 -ao pcm -nowaveheader stream.dump &oggenc --raw --raw-bits=16 --raw-chan=2 --raw-rate=48000 -q 1 -o audio-us.ogg+audiodump.pcm &waitFor a nice set of utilities to manager the .ogm format, see Moritz Bunkus'ogmtools (google is your friend).5) use the "v4mv" option. This could gives you a few more bits at theexpense of a slightly longer encoding. This is a "lossless" option, I meanwith this option you don't throw away some video information, it justselects a more precise motion estimation method. Be warned that on somevery un-typical scenes this option may gives you a longer file thanwithout, although it's very rare and on a whole film I think it's always awin.6) you can try the new luminance & darkness masking code. Playwith the "lumi_mask" and "dark_mask" options. I would recommend usingsomething like :lumi_mask=0.07:dark_mask=0.10:naq:lumi_mask=0.10:dark_mask=0.12:naq:lumi_mask=0.12:dark_mask=0.15:naqlumi_mask=0.13:dark_mask=0.16:naq:Be warned that these options are really experimental and the resultcould be very good or very bad depending on your visualization device(computer CRT, TV or TFT screen). Don't push too hard these options.> Second pass: > the same with vpass=2 7) I've found that lavc gives better results when the first pass is donewith "vqscale=2" instead of a target bitrate. The statistics collectedseems to be more precise. YMMV.> I am new to mencoder, so please tell me any idea you have even if it > obvious. I also tried the "gray" option of lavc, to encode B&W only, > but strangely it gives me "pink" squares from time to time. Yes, I've seen that too. Playing the resulting file with "-lavdopts gray"fix the problem but it's not very nice ...> So if you could tell me what option of mencoder or lavc I should be > looking at to lower the number of "squares" on the image, it would be > great. The version of mencoder i use is 0.90pre8 on a macos x PPC > platform. I guess I would have the same problem by encoding anime > movies, where there are a lot of region of the image with the same > color. So if you managed to solve this problem... You could also try the "mpeg_quant" flag. It selects a different set ofquantizers and produce somewhat sharper pictures and less blocks on largezones with the same or similar luminance, at the expense of some bits.> This is completely off topic, but do you know how I can create good > subtitles from vobsub subtitles ? I checked the -dumpmpsub option of > mplayer, but is there a way to do it really fast (ie without having to > play the whole movie) ? I didn't find a way under *nix to produce reasonably good text subtitlesfrom vobsubs. OCR *nix softwares seems either not suited to the task, notpowerful enough or both. I'm extracting the vobsub subtitles and simply usethem with the .ogm/ .avi :1) rip the DVD to harddisk with "mplayer dvd://1 -dumpstream"2) mount the DVD and copy the .ifo file2) extract all vobsubs to one single file with something like :for f in 0 1 2 3 4 5 6 7 8 9 10 11 ; do \ mencoder -ovc copy -oac copy -o /dev/null -sid $f -vobsubout sous-titres+-vobsuboutindex $f -ifo vts_01_0.ifo stream.dumpdone(and yes, I've a DVD with 12 subtitles)-- Rémi================================================================================TIPS FOR SMOKE & CLOUDS Q: I'm trying to encode Dante's Peak and I'm having problems with clouds,fog and smoke: They don't look fine (they look very bad if I watch themovie in TVout). There are some artifacts, white clouds looks as snowmountains, there are things likes hip in the colors so one can see frontiercurves between white and light gray and dark gray ... (I don't know if youcan understand me, I want to mean that the colors don't change smoothly)In particular I'm using vqscale=2:vhq:v4mvA: Try adding "vqcomp=0.7:vqblur=0.2:mpeg_quant" to lavcopts.Q: I tried your suggestion and it improved the image a little ... but not enough. I was playing with different options and I couldn't find the way. I suppose that the vob is not so good (watching it in TV trough the computer looks better than my encoding, but it isn't a lot of better). A: Yes, those scenes with qscale=2 looks terrible :-(Try with vqmin=1 in addition to mpeg_quant:vlelim=-4:vcelim=-7 (and maybewith "-sws 10 -ssf ls=1" to sharpen a bit the image) and read about vqmin=1in DOCS/tech/libavc-options.txt.If after the whole movie is encoded you still see the same problem, it willmeans that the second pass didn't picked-up q=1 for this scene. Force q=1with the "vrc_override" option.Q: By the way, is there a special difficult in encode clouds or smoke?A: I would say it depends on the sharpness of these clouds / smokes and thefact that they are mostly black/white/grey or colored. The codec will dothe right thing with vqmin=2 for example on a cigarette smoke (sharp) or ona red/yellow cloud (explosion, cloud of fire). But may not with a grey andvery fuzzy cloud like in the chocolat scene. Note that I don't know exactlywhy ;)A = Rémi================================================================================TIPS FOR TWEAKING RATECONTROL(For the purpose of this explanation, consider "2nd pass" to be any beyond the 1st. The algorithm is run only on P-frames; I- and B-frames use QPs based on the adjacent P. While x264's 2pass ratecontrol is based on lavc's, it has diverged somewhat and not all of this is valid for x264.)Consider the default ratecontrol equation in lavc: "tex^qComp".At the beginning of the 2nd pass, rc_eq is evaluated for each frame, and the result is the number of bits allocated to that frame (multiplied by some constant as needed to match the total requested bitrate)."tex" is the complexity of a frame, i.e. the estimated number of bits it would take to encode at a given quantizer. (If the 1st pass was CQP and not turbo, then we know tex exactly. Otherwise it is calculated by multiplying the 1st pass's bits by the QP of that frame. But that's not why CQP is potentially good; more on that later.)"qComp" is just a constant. It has no effect outside the rc_eq, and is directly set by the vqcomp parameter.If vqcomp=1, then rc_eq=tex^1=tex, so 2pass allocates to each frame the number of bits needed to encode them all at the same QP.If vqcomp=0, then rc_eq=tex^0=1, so 2pass allocates the same number of bits to each frame, i.e. CBR. (Actually, this is worse than 1pass CBR in terms of quality; CBR can vary within its allowed buffer size, while vqcomp=0 tries to make each frame exactly the same size.)If vqcomp=0.5, then rc_eq=sqrt(tex), so the allocation is somewhere between CBR and CQP. High complexity frames get somewhat lower quality than low complexity, but still more bits.While the actual selection of a good value of vqcomp is experimental, the following underlying factors determine the result:Arguing towards CQP: You want the movie to be somewhere approaching constant quality; oscillating quality is even more annoying than constant low quality. (However, constant quality does not mean constant PSNR nor constant QP. Details are less noticeable in high-motion scenes, so you can get away with somewhat higher QP in high-complexity frames for the same perceived quality.)Arguing towards CBR: You get more quality per bit if you spend those bits in frames where motion compensation works well (which tends to be correlated with "tex"): A given artifact may stick around several seconds in a low-motion scene, and you only have to fix it in one frame to improve the quality of the whole sequence.Now for why the 1st pass ratecontrol method matters:The number of bits at constant quant is as good a measure of complexity asany other simple formula for the purpose of allocating bits. But it's notperfect for predicting which QP will produce the desired number of bits.Bits are approximately inversely proportional to QP, but the exact scalingis non-linear, and depends on the amount of detail/noise, the complexity ofmotion, the quality of previous frames, and other stuff not measured by theratecontrol. So it predicts best when the QP used for a given frame in the2nd pass is close to the QP used in the 1st pass. When the prediction iswrong, lavc needs to distribute the surplus or deficit of bits among futureframes, which means that they too deviate from the planned distribution.Obviously, with vqcomp=1 you can get the 1st pass QPs very close by usingCQP, and with vqcomp=0 a CBR 1st pass is very close. But with vqcomp=0.5it's more ambiguous. The accepted wisdom is that CBR is better forvqcomp=0.5, mostly because you then don't have to guess a QP in advance.But with vqcomp=0.6 or 0.7, the 2nd pass QPs vary less, so a CQP 1st pass(with the right QP) will be a better predictor than CBR.To make it more confusing, 1pass CBR uses the same rc_eq with a differentmeaning. In CBR, we don't have a real encode to estimate from, so "tex" iscalculated from the full-pixel precision motion-compensation residual.While the number of bits allocated to a given frame is decided by the rc_eqjust like in 2nd pass, the target bitrate is constant (instead of being thesum of per-frame rc_eq values). So the scaling factor (which is constant in2nd pass) now varies in order to keep the local average bitrate near theCBR target. So vqcomp does affect CBR, though it only determines the localallocation of bits, not the long-term allocation.--Loren Merritt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -