📄 encoding-tips.txt
字号:
> The "counting the quantesizer"-thing could improve the quality of> full automated scripts, as I understand ?Yes, the log file analysis can be used be tools to automatically adjustthe scaling parameters (if you'd do that you'd end up with a three-passencoding for the video only ;)), but it can also provide answers foryou as a human. From time to time there's a question like 'hey,mencoder creates files that are too small! I specified this bitrate andthe resulting file is 50megs short of the target file size!'. Thereason is probably that the codec already uses the minimum quantizerfor nearly all frames so it simply does not need more bits. A quickglance at the distribution of the quantizers can be enlightening.Another thing is that q=2 and q=3 look really good while the 'bigger'quantizers really lose quality. So if your distribution shows themajority of quantizers at 4 and above then you should probably decreasethe resolution (you'll definitly see block artefacts).Well... Several people will probably disagree with me on certain points here, especially when it comes down to hard values (like the$bpp categories and the percentage of the quantizers used). Butthe idea is still valid.And that's why I think that there should NOT be presets in mencoderlike the presets lame knows. 'Good quality' or 'perfect quality' areALWAYS relative. They always depend on a person's personal preferences.If you want good quality then spend some time reading and - moreimportant - understanding what steps are involved in video encoding.You cannot do it without mathematics. Oh well, you can, but you'llend up with movies that could certainly look better.Now please shoot me if you have any complaints ;)-- ==> Ciao, Mosu (Moritz Bunkus)===========ANOTHER APPROACH: BITS PER BLOCK:> $videobitrate * 1000 > $bpp = -----------------------> $width * $height * $fpsWell, I came to similar equation going through different route. Only Ididn't use bits per pixel, in my case it was bits per block (BPB). The blockis 16x16 because lots of software depends on video width/height beingdivisable by 16. And because I didn't like this 0.2 bit per pixel, whenbit is quite atomic ;)So the equation was something like: bitratebpb = ----------------- fps * ((width * height) / (16 * 16))(width and height are from destination video size, and bitrate is inbits (i.e. 900kbps is 900000))This way it apeared that the minimum bits per block is ~40, verygood results are with ~50, and everything above 60 is a waste of bandwidth.And what's actually funny is that it was independent of codec used. Theresults were exactly the same, whether I used DIV3 (with tricky nandub'smagick), ffmpeg odivx, DivX5 on Windows or XviD.Surprisingly there is one advantage of using nandub-DIV3 for bitratestarved encoding: ringing almost never apears this way.But I also found out, that the quality/BPB isn't constant fordrastically different resolutions. Smaller picture (like MPEG1 sizes)need more BPB to look good than say typical MPEG2 resolutions.Robert===========DON'T SCALE DOWN TOO MUCHSometimes I found that encoding to y-scaled only DVD qualty (ie 704 x288 for a 2.85 film) gives better visual quality than a scaled-downversion even if the quantizers are significantly higher than for thescaled-down version.Keep in mind that blocs, fuzzy parts and generaly mpeg artefacts in a704x288 image will be harder to spot in full-screen mode than on a512x208 image. In fact I've see example where the same movie looksbetter compressed to 704x288 with an average weighted quantizer of~3 than the same movie scaled to 576x240 with an average weightedquantizer of 2.4.Btw, a print of the weighted average quantizer would be nice incountquant.pl :)Another point in favor of not trying to scale down too much : on hardscaled-down movies, the MPEG codec will need to compress relativelyhigh frequencies rather than low frequencies and it doesn't like thatat all. You will see less and less returns while you scale down andscale down again in desesperate need of some bandwidth :)In my experience, don't try to go below a width of 576 without closelywatching what's going on.-- Rémi===========TIPS FOR ENCODINGThat being said, with video you have some tradeoffs you can make. Mostpeople seem to encode with really basic options, but if you play withsingle coefficient elimination and luma masking settings, you can save lotsof bits, resulting in lower quantizers, which means less blockiness andless ugly noise (ringing) around sharp borders. The tradeoff, however, isthat you'll get some "muddiness" in some parts of the image. Play aroundwith the settings and see for yourself. The options I typically use for(non-animated) movies are:vlelim=-4vcelim=9lumi_mask=0.05dark_mask=0.01If things look too muddy, making the numbers closer to 0. For anime andother animation, the above recommendations may not be so good.Another option that may be useful is allowing four motion vectors permacroblock (v4mv). This will increase encoding time quite a bit, andlast I checked it wasn't compatible with B frames. AFAIK, specifyingv4mv should never reduce quality, but it may prevent some old junkyversions of DivX from decoding it (can anyone conform?). Another issuemight be increased cpu time needed for decoding (again, can anyoneconfirm?).To get more fair distribution of bits between low-detail andhigh-detail scenes, you should probably try increasing vqcomp from thedefault (0.5) to something in the range 0.6-0.8.Of course you also want to make sure you crop ALL of the black border andany half-black pixels at the edge of the image, and make sure the finalimage dimensions after cropping and scaling are multiples of 16. Failing todo so will drastically reduce quality.Finally, if you can't seem to get good results, you can try scaling themovie down a bit smaller or applying a weak gaussian blur to reduce theamount of detail.Now, my personal success story! I just recently managed to fit a beautifulencode of Kundun (well over 2 hours long, but not too many high-motionscenes) on one cd at 640x304, with 66 kbit/sec abr ogg audio, using theoptions I described above. So, IMHO it's definitely possible to get verygood results with libavcodec (certainly MUCH better than all the idiot"release groups" using DivX3 make), as long as you take some time to playaround with the options.Rich============ABOUT VLELIM, VCELIM, LUMI_MASK AND DARK_MASK PART I: LUMA & CHROMAThe l/c in vlelim and vcelim stands for luma (brightness plane) and chroma(color planes). These are encoded separately in all mpeg-like algorithms.Anyway, the idea behind these options is (at least from what I understand)to use some good heuristics to determine when the change in a block is lessthan the threshold you specify, and in such a case, to just encode theblock as "no change". This saves bits and perhaps speeds up encoding. Usinga negative value for either one means the same thing as the correspondingpositive value, but the DC coefficient is also considered. UnfortunatelyI'm not familiar enough with the mpeg terminology to know what this means(my first guess would be that it's the constant term from the DCT), but itprobably makes the encoder less likely to apply single coefficientelimination in cases where it would look bad. It's presumably recommendedto use negative values for luma (which is more noticable) and positive forchroma.The other options -- lumi_mask and dark_mask -- control how the quantizeris adjusted for really dark or bright regions of the picture. You'reprobably already at least a bit familiar with the concept of quantizers(qscale, lower = more precision, higher quality, but more bits needed toencode). What not everyone seems to know is that the quantizer you see(e.g. in the 2pass logs) is just an average for the whole frame, and loweror higher quantizers may in fact be used in parts of the picture with moreor less detail. Increasing the values of lumi_mask and dark_mask will causelavc to aggressively increase the quantizer in very dark or very brightregions of the picture (which are presumably not as noticable to the humaneye) in order to save bits for use elsewhere.Rich===================ABOUT VLELIM, VCELIM, LUMI_MASK AND DARK_MASK PART II: VQSCALEOK, a quick explanation. The quantizer you set with vqscale=N is theper-frame quantizer parameter (aka qp). However, with mpeg4 it'sallowed (and recommended!) for the encoder to vary the quantizer on aper-macroblock (mb) basis (as I understand it, macroblocks are 16x16regions composed of 4 8x8 luma blocks and 2 8x8 chroma blocks, u andv). To do this, lavc scores each mb with a complexity value andweights the quantizer accordingly. However, you can control thisbehavior somewhat with scplx_mask, tcplx_mask, dark_mask, andlumi_mask.scplx_mask -- raise quantizer on mb's with lots of spacial complexity.Spacial complexity is measured by variance of the texture (this isjust the actual image for I blocks and the difference from theprevious coded frame for P blocks).tcplx_mask -- raise quantizer on mb's with lots of temporalcomplexity. Temporal complexity is measured according to motionvectors.dark_mask -- raise quantizer on very dark mb's.lumi_mask -- raise quantizer on very bright mb's.Somewhere around 0-0.15 is a safe range for these values, IMHO. Youmight try as high as 0.25 or 0.3. You should probably never go over0.5 or so.Now, about naq. When you adjust the quantizers on a per-mb basis likethis (called adaptive quantization), you might decrease or (morelikely) increase the average quantizer used, so that it no longermatches the requested average quantizer (qp) for the frame. This willresult in weird things happening with the bitrate, at least from myexperience. What naq does is "normalize adaptive quantization". Thatis, after the above masking parameters are applied on a per-mb basis,the quantizers of all the blocks are rescaled so that the averagestays fixed at the desired qp.So, if I used vqscale=4 with naq and fairly large values for themasking parameters, I might be likely to see lots of frames usingqscale 2,3,4,5,6,7 across different macroblocks as needed, but withthe average sticking around 4. However, I haven't actually tested sucha setup yet, so it's just speculation right now.Have fun playing around with it.Rich================================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -