📄 encoding-tips.txt
字号:
Some important URLs:~~~~~~~~~~~~~~~~~~~~http://mplayerhq.hu/~michael/codec-features.html <- lavc vs. divx5 vs. xvidhttp://www.ee.oulu.fi/~tuukkat/mplayer/tests/rguyom.ath.cx/ <- lavc benchmarks, optionshttp://ffdshow.sourceforge.net/tikiwiki/tiki-view_articles.php <- lavc for win32 :)http://www.bunkus.org/dvdripping4linux/index.html <- a nice tutorialhttp://forum.zhentarim.net/viewtopic.php?p=237 <- lavc option comparisonhttp://www.ee.oulu.fi/~tuukkat/mplayer/tests/readme.html <- series of benchmarkshttp://thread.gmane.org/gmane.comp.video.mencoder.user/1196 <- free codecs shoutout and recommended encoding settings================================================================================FIXING A/V SYNC WHEN ENCODINGI know this is a popular topic on the list, so I thought I'd share afew comments on my experience fixing a/v sync. As everyone seems toknow, mencoder unfortunately doesn't have a -delay option. But thatdoesn't mean you can't fix a/v sync. There are a couple ways to stilldo it.In example 1, we'll suppose you want to re-encode the audio anyway.This will be essential if your source audio isn't mp3, e.g. for DVD'sor nasty avi files with divx/wma audio. This approach makes thingsmuch easier.Step 1: Dump the audio with mplayer -ao pcm -nowaveheader. There arevarious options that can be used to speed this up, most notably -vonull, -vc null, and/or -hardframedrop. -benchmark also seemed to helpin the past. :)Step 2: Figure out what -delay value syncs the audio right in mplayer.If this number is positive, use a command like the following:dd if=audiodump.wav bs=1764 skip=[delay] | lame -x - out.mp3where [delay] is replaced by your delay amount in hundredths of asecond (1/10 the value you use with mplayer). Otherwise, if delay isnegative, use a command like this:( dd if=/dev/zero bs=1764 skip=[delay] ; cat audiodump.wav ) | lame -x - out.mp3Don't include the minus (-) sign in delay. Also, keep in mind you'llhave to change the 1764 number and provide additional options to lameif your audio stream isn't 44100/16bit/little-endian/stereo.Step 3: Use mencoder to remux your new mp3 file with the movie:mencoder -audiofile out.mp3 -oac copy ...You can either copy video as-is (with -ovc copy) or re-encode it atthe same time you merge in the audio like this.Finally, as a variation on this method (makes things a good bit fasterand doesn't use tons of temporary disk space) you can merge steps 1and 2 by making a named pipe called "audiodump.wav" (type mkfifoaudiodump.wav) and have mplayer write the audio to it at the same timeyou're running lame to encode.Now for example 2. This time we won't re-encode audio at all. Justdump the mp3 stream from the avi file with mplayer -dumpaudio. Then,you have to cut and paste the raw mp3 stream a bit...If delay is negative, things are easier. Just use lame to encodesilence for the duration of delay, at the same samplerate andsamplesize used in your avi file. Then, do something like:cat silence.mp3 stream.dump > out.mp3mencoder -audiofile out.mp3 -oac copy ...On the other hand, if delay is positive, you'll need to crop off partof the mp3 from the beginning. If it's (at least roughly) CBR this iseasy -- just take off the first (bitrate*delay/8) bytes of the file.You can use the excellent dd tool, or just your favoritebinary-friendly text editor to do this. Otherwise, you'll have toexperiment with cutting off different amounts. You can test withmplayer -audiofile before actually spending time remuxing/encodingwith mencoder to make sure you cut the right amount.I hope this has all been informative. If anyone would like to cleanthis message up a bit and make it into part of the docs, feel free. Ofcourse mencoder should eventually just get -delay. :)Rich================================================================================ENCODING QUALITY - OR WHY AUTOMATISM IS BAD.Hi everyone.Some days ago someone suggested adding some preset options to mencoder.At that time I replied 'don't do that', and now I decided to elaborateon that.Warning: this is rather long, and it involves mathematics. But if youdon't want to bother with either then why are you encoding in thefirst place? Go do something different!The good news is: it's all about the bpp (bits per pixel).The bad news is: it's not THAT easy ;)This mail is about encoding a DVD to MPEG4. It's about the videoquality, not (primarily) about the audio quality or some other fancythings like subtitles.The first step is to encode the audio. Why? Well if you encode theaudio prior to the video you'll have to make the video fit onto one(or two) CD(s). That way you can use oggenc's quality based encodingmode which is much more sophisticated than its ABR based mode.After encoding the audio you have a certain amount of space left tofill with video. Let's assume the audio takes 60M (no problem withVorbis), and you aim at a 700M CD. This leaves you 640M for the video.Let's further assume that the video is 100 minutes or 6000 secondslong, encoded at 25fps (those nasty NTSC fps values give meheadaches. Adjust to your needs, of course!). This leaves you witha video bitrate of: $videosize * 8 $videobitrate = -------------- $length * 1000$videosize in bytes, $length in seconds, $videobitrate in kbit/s.In my example I end up with $videobitrate = 895.And now comes the question: how do I chose my encoding parametersso that the results will be good? First let's take a look at atypical mencoder line:mencoder dvd://1 -o /dev/null -oac copy -ovc lavc \ -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vqmin=2:\ vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:vpass=1 \ -vf crop=716:572:2:2,scale=640:480Phew, all those parameters! Which ones should I change? NEVER leaveout 'vhq'. Never ever. 'vqmin=2' is always good if you aim for sanesettings - like 'normal length' movies on one CD, 'very long movies'on two CDs and so on. vcodec=mpeg4 is mandatory.The 'vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01' are parameterssuggested by D Richard Felker for non-animated movies, and theyimprove quality a bit.But the two things that have the most influence on quality arevbitate and scale. Why? Because both together tell the codec howmany bits it may spend on each frame for each bit: and this isthe 'bpp' value (bits per pixel). It's simply defined as $videobitrate * 1000 $bpp = ----------------------- $width * $height * $fpsI've attached a small Perl script that calculates the $bpp fora movie. You'll have to give it four parameters:a) the cropped but unscaled resolution (use '-vf cropdetect'),b) the encoded aspect ratio. All DVDs come at 720x576 but containa flag that tells the player wether it should display the DVD atan aspect ratio of 4/3 (1.333) or at 16/9 (1.777). Have a lookat mplayer's output - there's something about 'prescaling'. That'swhat you are looking for.c) the video bitrate in kbit/s andd) the fps.In my example the command line and calcbpp.pl's output would looklike this (warning - long lines ahead):mosu@anakin:~$ ./calcbpp.pl 720x440 16/9 896 25Prescaled picture: 1023x440, AR 2.33720x304, diff 5, new AR 2.37, AR error 1.74% scale=720:304 bpp: 0.164704x304, diff -1, new AR 2.32, AR error 0.50% scale=704:304 bpp: 0.167688x288, diff 8, new AR 2.39, AR error 2.58% scale=688:288 bpp: 0.181672x288, diff 1, new AR 2.33, AR error 0.26% scale=672:288 bpp: 0.185656x288, diff -6, new AR 2.28, AR error 2.17% scale=656:288 bpp: 0.190640x272, diff 3, new AR 2.35, AR error 1.09% scale=640:272 bpp: 0.206624x272, diff -4, new AR 2.29, AR error 1.45% scale=624:272 bpp: 0.211608x256, diff 5, new AR 2.38, AR error 2.01% scale=608:256 bpp: 0.230592x256, diff -2, new AR 2.31, AR error 0.64% scale=592:256 bpp: 0.236576x240, diff 8, new AR 2.40, AR error 3.03% scale=576:240 bpp: 0.259560x240, diff 1, new AR 2.33, AR error 0.26% scale=560:240 bpp: 0.267544x240, diff -6, new AR 2.27, AR error 2.67% scale=544:240 bpp: 0.275528x224, diff 3, new AR 2.36, AR error 1.27% scale=528:224 bpp: 0.303512x224, diff -4, new AR 2.29, AR error 1.82% scale=512:224 bpp: 0.312496x208, diff 5, new AR 2.38, AR error 2.40% scale=496:208 bpp: 0.347480x208, diff -2, new AR 2.31, AR error 0.85% scale=480:208 bpp: 0.359464x192, diff 7, new AR 2.42, AR error 3.70% scale=464:192 bpp: 0.402448x192, diff 1, new AR 2.33, AR error 0.26% scale=448:192 bpp: 0.417432x192, diff -6, new AR 2.25, AR error 3.43% scale=432:192 bpp: 0.432416x176, diff 3, new AR 2.36, AR error 1.54% scale=416:176 bpp: 0.490400x176, diff -4, new AR 2.27, AR error 2.40% scale=400:176 bpp: 0.509384x160, diff 5, new AR 2.40, AR error 3.03% scale=384:160 bpp: 0.583368x160, diff -2, new AR 2.30, AR error 1.19% scale=368:160 bpp: 0.609352x144, diff 7, new AR 2.44, AR error 4.79% scale=352:144 bpp: 0.707336x144, diff 0, new AR 2.33, AR error 0.26% scale=336:144 bpp: 0.741320x144, diff -6, new AR 2.22, AR error 4.73% scale=320:144 bpp: 0.778A word for the $bpp. For a fictional movie which is only black andwhite: if you have a $bpp of 1 then the movie would be storeduncompressed :) For a real life movie with 24bit color depth youneed compression of course. And the $bpp can be used to make thedecision easier.As you can see the resolutions suggested by the script are alldividable by 16. This will make the aspect ratio slightly wrong,but no one will notice.Now if you want to decide which resolution (and scaling parameters)to chose you can do that by looking at the $bpp:< 0.10: don't do it. Please. I beg you!< 0.15: It will look bad.< 0.20: You will notice blocks, but it will look ok.< 0.25: It will look really good.> 0.25: It won't really improve visually.> 0.30: Don't do that either - try a bigger resolution instead.Of course these values are not absolutes! For movies with really lotsof black areas 0.15 may look very good. Action movies with only highmotion scenes on the other hand may not look perfect at 0.25. But thesevalues give you a great idea about which resolution to chose.I see a lot of people always using 512 for the width and scalingthe height accordingly. For my (real-world-)example this would besimply a waste of bandwidth. The encoder would probably not evenneed the full bitrate, and the resulting file would be smallerthan my targetted 700M.After encoding you'll do your 'quality check'. First fire up the movieand see whether it looks good to you or not. But you can also do amore 'scientific' analysis. The second Perl script I attached countsthe quantizers used for the encoding. Simply call it withcountquant.pl < divx2pass.logIt will print out which quantizer was used how often. If you see thate.g. the lowest quantizer (vqmin=2) gets used for > 95% of the framesthen you can safely increase your picture size.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -