comparison DOCS/tech/encoding-tips.txt @ 29263:0f1b5b68af32

whitespace cosmetics: Remove all trailing whitespace.
author diego
date Wed, 13 May 2009 02:58:57 +0000
parents 13061a6174b6
children
comparison
equal deleted inserted replaced
29262:7d545a6b8aff 29263:0f1b5b68af32
120 Let's further assume that the video is 100 minutes or 6000 seconds 120 Let's further assume that the video is 100 minutes or 6000 seconds
121 long, encoded at 25fps (those nasty NTSC fps values give me 121 long, encoded at 25fps (those nasty NTSC fps values give me
122 headaches. Adjust to your needs, of course!). This leaves you with 122 headaches. Adjust to your needs, of course!). This leaves you with
123 a video bitrate of: 123 a video bitrate of:
124 124
125 $videosize * 8 125 $videosize * 8
126 $videobitrate = -------------- 126 $videobitrate = --------------
127 $length * 1000 127 $length * 1000
128 128
129 $videosize in bytes, $length in seconds, $videobitrate in kbit/s. 129 $videosize in bytes, $length in seconds, $videobitrate in kbit/s.
130 In my example I end up with $videobitrate = 895. 130 In my example I end up with $videobitrate = 895.
150 But the two things that have the most influence on quality are 150 But the two things that have the most influence on quality are
151 vbitate and scale. Why? Because both together tell the codec how 151 vbitate and scale. Why? Because both together tell the codec how
152 many bits it may spend on each frame for each bit: and this is 152 many bits it may spend on each frame for each bit: and this is
153 the 'bpp' value (bits per pixel). It's simply defined as 153 the 'bpp' value (bits per pixel). It's simply defined as
154 154
155 $videobitrate * 1000 155 $videobitrate * 1000
156 $bpp = ----------------------- 156 $bpp = -----------------------
157 $width * $height * $fps 157 $width * $height * $fps
158 158
159 I've attached a small Perl script that calculates the $bpp for 159 I've attached a small Perl script that calculates the $bpp for
160 a movie. You'll have to give it four parameters: 160 a movie. You'll have to give it four parameters:
258 quantizers really lose quality. So if your distribution shows the 258 quantizers really lose quality. So if your distribution shows the
259 majority of quantizers at 4 and above then you should probably decrease 259 majority of quantizers at 4 and above then you should probably decrease
260 the resolution (you'll definitly see block artefacts). 260 the resolution (you'll definitly see block artefacts).
261 261
262 262
263 Well... Several people will probably disagree with me on certain 263 Well... Several people will probably disagree with me on certain
264 points here, especially when it comes down to hard values (like the 264 points here, especially when it comes down to hard values (like the
265 $bpp categories and the percentage of the quantizers used). But 265 $bpp categories and the percentage of the quantizers used). But
266 the idea is still valid. 266 the idea is still valid.
267 267
268 And that's why I think that there should NOT be presets in mencoder 268 And that's why I think that there should NOT be presets in mencoder
273 You cannot do it without mathematics. Oh well, you can, but you'll 273 You cannot do it without mathematics. Oh well, you can, but you'll
274 end up with movies that could certainly look better. 274 end up with movies that could certainly look better.
275 275
276 Now please shoot me if you have any complaints ;) 276 Now please shoot me if you have any complaints ;)
277 277
278 -- 278 --
279 ==> Ciao, Mosu (Moritz Bunkus) 279 ==> Ciao, Mosu (Moritz Bunkus)
280 280
281 =========== 281 ===========
282 ANOTHER APPROACH: BITS PER BLOCK: 282 ANOTHER APPROACH: BITS PER BLOCK:
283 283
284 > $videobitrate * 1000 284 > $videobitrate * 1000
285 > $bpp = ----------------------- 285 > $bpp = -----------------------
286 > $width * $height * $fps 286 > $width * $height * $fps
287 287
288 Well, I came to similar equation going through different route. Only I 288 Well, I came to similar equation going through different route. Only I
289 didn't use bits per pixel, in my case it was bits per block (BPB). The block 289 didn't use bits per pixel, in my case it was bits per block (BPB). The block
339 scale down again in desesperate need of some bandwidth :) 339 scale down again in desesperate need of some bandwidth :)
340 340
341 In my experience, don't try to go below a width of 576 without closely 341 In my experience, don't try to go below a width of 576 without closely
342 watching what's going on. 342 watching what's going on.
343 343
344 -- 344 --
345 Rémi 345 Rémi
346 346
347 =========== 347 ===========
348 TIPS FOR ENCODING 348 TIPS FOR ENCODING
349 349
486 486
487 I found myself that 4:3 B&W old movies are very hard to compress well. In 487 I found myself that 4:3 B&W old movies are very hard to compress well. In
488 addition to the 4:3 aspect ratio which eats lots of bits, those movies are 488 addition to the 4:3 aspect ratio which eats lots of bits, those movies are
489 typically very "noisy", which doesn't help at all. Anyway : 489 typically very "noisy", which doesn't help at all. Anyway :
490 490
491 > After a few tries I am 491 > After a few tries I am
492 > still a little bit disappointed with the video quality. Since it is a 492 > still a little bit disappointed with the video quality. Since it is a
493 > "dark" movies, there is a lot of black on the pictures, and on the 493 > "dark" movies, there is a lot of black on the pictures, and on the
494 > encoded avi I can see a lot of annoying "mpeg squares". I am using 494 > encoded avi I can see a lot of annoying "mpeg squares". I am using
495 > avifile codec, but the best I think is to give you the command line I 495 > avifile codec, but the best I think is to give you the command line I
496 > used to encode a preview of the result: 496 > used to encode a preview of the result:
497 497
498 > 498 >
499 > First pass: 499 > First pass:
500 > mencoder TITLE01-ANGLE1.VOB -oac copy -ovc lavc -lavcopts 500 > mencoder TITLE01-ANGLE1.VOB -oac copy -ovc lavc -lavcopts
501 > vcodec=mpeg4:vhq:vpass=1:vbitrate=800:keyint=48 -ofps 23.976 -npp lb 501 > vcodec=mpeg4:vhq:vpass=1:vbitrate=800:keyint=48 -ofps 23.976 -npp lb
502 > -ss 2:00 -endpos 0:30 -vf scale -zoom -xy 640 -o movie.avi 502 > -ss 2:00 -endpos 0:30 -vf scale -zoom -xy 640 -o movie.avi
503 503
504 1) keyint=48 is way too low. The default value is 250, this is in *frames* 504 1) keyint=48 is way too low. The default value is 250, this is in *frames*
505 not seconds. Keyframes are significantly larger than P or B frames, so the 505 not seconds. Keyframes are significantly larger than P or B frames, so the
506 less keyframes you have, better the overall movie will be. (huh, like Yoda 506 less keyframes you have, better the overall movie will be. (huh, like Yoda
507 I speak ;). Try keyint=300 or 350. Don't go beyond that if you want 507 I speak ;). Try keyint=300 or 350. Don't go beyond that if you want
553 lumi_mask=0.13:dark_mask=0.16:naq: 553 lumi_mask=0.13:dark_mask=0.16:naq:
554 Be warned that these options are really experimental and the result 554 Be warned that these options are really experimental and the result
555 could be very good or very bad depending on your visualization device 555 could be very good or very bad depending on your visualization device
556 (computer CRT, TV or TFT screen). Don't push too hard these options. 556 (computer CRT, TV or TFT screen). Don't push too hard these options.
557 557
558 > Second pass: 558 > Second pass:
559 > the same with vpass=2 559 > the same with vpass=2
560 560
561 7) I've found that lavc gives better results when the first pass is done 561 7) I've found that lavc gives better results when the first pass is done
562 with "vqscale=2" instead of a target bitrate. The statistics collected 562 with "vqscale=2" instead of a target bitrate. The statistics collected
563 seems to be more precise. YMMV. 563 seems to be more precise. YMMV.
564 564
565 > I am new to mencoder, so please tell me any idea you have even if it 565 > I am new to mencoder, so please tell me any idea you have even if it
566 > obvious. I also tried the "gray" option of lavc, to encode B&W only, 566 > obvious. I also tried the "gray" option of lavc, to encode B&W only,
567 > but strangely it gives me "pink" squares from time to time. 567 > but strangely it gives me "pink" squares from time to time.
568 568
569 Yes, I've seen that too. Playing the resulting file with "-lavdopts gray" 569 Yes, I've seen that too. Playing the resulting file with "-lavdopts gray"
570 fix the problem but it's not very nice ... 570 fix the problem but it's not very nice ...
571 571
572 > So if you could tell me what option of mencoder or lavc I should be 572 > So if you could tell me what option of mencoder or lavc I should be
573 > looking at to lower the number of "squares" on the image, it would be 573 > looking at to lower the number of "squares" on the image, it would be
574 > great. The version of mencoder i use is 0.90pre8 on a macos x PPC 574 > great. The version of mencoder i use is 0.90pre8 on a macos x PPC
575 > platform. I guess I would have the same problem by encoding anime 575 > platform. I guess I would have the same problem by encoding anime
576 > movies, where there are a lot of region of the image with the same 576 > movies, where there are a lot of region of the image with the same
577 > color. So if you managed to solve this problem... 577 > color. So if you managed to solve this problem...
578 578
579 You could also try the "mpeg_quant" flag. It selects a different set of 579 You could also try the "mpeg_quant" flag. It selects a different set of
580 quantizers and produce somewhat sharper pictures and less blocks on large 580 quantizers and produce somewhat sharper pictures and less blocks on large
581 zones with the same or similar luminance, at the expense of some bits. 581 zones with the same or similar luminance, at the expense of some bits.
582 582
583 > This is completely off topic, but do you know how I can create good 583 > This is completely off topic, but do you know how I can create good
584 > subtitles from vobsub subtitles ? I checked the -dumpmpsub option of 584 > subtitles from vobsub subtitles ? I checked the -dumpmpsub option of
585 > mplayer, but is there a way to do it really fast (ie without having to 585 > mplayer, but is there a way to do it really fast (ie without having to
586 > play the whole movie) ? 586 > play the whole movie) ?
587 587
588 I didn't find a way under *nix to produce reasonably good text subtitles 588 I didn't find a way under *nix to produce reasonably good text subtitles
589 from vobsubs. OCR *nix softwares seems either not suited to the task, not 589 from vobsubs. OCR *nix softwares seems either not suited to the task, not
590 powerful enough or both. I'm extracting the vobsub subtitles and simply use 590 powerful enough or both. I'm extracting the vobsub subtitles and simply use
591 them with the .ogm 591 them with the .ogm
599 mencoder -ovc copy -oac copy -o /dev/null -sid $f -vobsubout sous-titres 599 mencoder -ovc copy -oac copy -o /dev/null -sid $f -vobsubout sous-titres
600 +-vobsuboutindex $f -ifo vts_01_0.ifo stream.dump 600 +-vobsuboutindex $f -ifo vts_01_0.ifo stream.dump
601 done 601 done
602 602
603 (and yes, I've a DVD with 12 subtitles) 603 (and yes, I've a DVD with 12 subtitles)
604 -- 604 --
605 Rémi 605 Rémi
606 606
607 607
608 ================================================================================ 608 ================================================================================
609 609
610 610
611 TIPS FOR SMOKE & CLOUDS 611 TIPS FOR SMOKE & CLOUDS
612 612
613 Q: I'm trying to encode Dante's Peak and I'm having problems with clouds, 613 Q: I'm trying to encode Dante's Peak and I'm having problems with clouds,
614 fog and smoke: They don't look fine (they look very bad if I watch the 614 fog and smoke: They don't look fine (they look very bad if I watch the
615 movie in TV-out). There are some artifacts, white clouds looks as snow 615 movie in TV-out). There are some artifacts, white clouds looks as snow
616 mountains, there are things likes hip in the colors so one can see frontier 616 mountains, there are things likes hip in the colors so one can see frontier
618 can understand me, I want to mean that the colors don't change smoothly) 618 can understand me, I want to mean that the colors don't change smoothly)
619 In particular I'm using vqscale=2:vhq:v4mv 619 In particular I'm using vqscale=2:vhq:v4mv
620 620
621 A: Try adding "vqcomp=0.7:vqblur=0.2:mpeg_quant" to lavcopts. 621 A: Try adding "vqcomp=0.7:vqblur=0.2:mpeg_quant" to lavcopts.
622 622
623 Q: I tried your suggestion and it improved the image a little ... but not 623 Q: I tried your suggestion and it improved the image a little ... but not
624 enough. I was playing with different options and I couldn't find the way. 624 enough. I was playing with different options and I couldn't find the way.
625 I suppose that the vob is not so good (watching it in TV trough the 625 I suppose that the vob is not so good (watching it in TV trough the
626 computer looks better than my encoding, but it isn't a lot of better). 626 computer looks better than my encoding, but it isn't a lot of better).
627 627
628 A: Yes, those scenes with qscale=2 looks terrible :-( 628 A: Yes, those scenes with qscale=2 looks terrible :-(
629 629
630 Try with vqmin=1 in addition to mpeg_quant:vlelim=-4:vcelim=-7 (and maybe 630 Try with vqmin=1 in addition to mpeg_quant:vlelim=-4:vcelim=-7 (and maybe
631 with "-sws 10 -ssf ls=1" to sharpen a bit the image) and read about vqmin=1 631 with "-sws 10 -ssf ls=1" to sharpen a bit the image) and read about vqmin=1
650 ================================================================================ 650 ================================================================================
651 651
652 652
653 TIPS FOR TWEAKING RATECONTROL 653 TIPS FOR TWEAKING RATECONTROL
654 654
655 (For the purpose of this explanation, consider "2nd pass" to be any beyond 655 (For the purpose of this explanation, consider "2nd pass" to be any beyond
656 the 1st. The algorithm is run only on P-frames; I- and B-frames use QPs 656 the 1st. The algorithm is run only on P-frames; I- and B-frames use QPs
657 based on the adjacent P. While x264's 2pass ratecontrol is based on lavc's, 657 based on the adjacent P. While x264's 2pass ratecontrol is based on lavc's,
658 it has diverged somewhat and not all of this is valid for x264.) 658 it has diverged somewhat and not all of this is valid for x264.)
659 659
660 Consider the default ratecontrol equation in lavc: "tex^qComp". 660 Consider the default ratecontrol equation in lavc: "tex^qComp".
661 At the beginning of the 2nd pass, rc_eq is evaluated for each frame, and 661 At the beginning of the 2nd pass, rc_eq is evaluated for each frame, and
662 the result is the number of bits allocated to that frame (multiplied by 662 the result is the number of bits allocated to that frame (multiplied by
663 some constant as needed to match the total requested bitrate). 663 some constant as needed to match the total requested bitrate).
664 664
665 "tex" is the complexity of a frame, i.e. the estimated number of bits it 665 "tex" is the complexity of a frame, i.e. the estimated number of bits it
666 would take to encode at a given quantizer. (If the 1st pass was CQP and 666 would take to encode at a given quantizer. (If the 1st pass was CQP and
667 not turbo, then we know tex exactly. Otherwise it is calculated by 667 not turbo, then we know tex exactly. Otherwise it is calculated by
668 multiplying the 1st pass's bits by the QP of that frame. But that's not 668 multiplying the 1st pass's bits by the QP of that frame. But that's not
669 why CQP is potentially good; more on that later.) 669 why CQP is potentially good; more on that later.)
670 "qComp" is just a constant. It has no effect outside the rc_eq, and is 670 "qComp" is just a constant. It has no effect outside the rc_eq, and is
671 directly set by the vqcomp parameter. 671 directly set by the vqcomp parameter.
672 672
673 If vqcomp=1, then rc_eq=tex^1=tex, so 2pass allocates to each frame the 673 If vqcomp=1, then rc_eq=tex^1=tex, so 2pass allocates to each frame the
674 number of bits needed to encode them all at the same QP. 674 number of bits needed to encode them all at the same QP.
675 If vqcomp=0, then rc_eq=tex^0=1, so 2pass allocates the same number of 675 If vqcomp=0, then rc_eq=tex^0=1, so 2pass allocates the same number of
676 bits to each frame, i.e. CBR. (Actually, this is worse than 1pass CBR in 676 bits to each frame, i.e. CBR. (Actually, this is worse than 1pass CBR in
677 terms of quality; CBR can vary within its allowed buffer size, while 677 terms of quality; CBR can vary within its allowed buffer size, while
678 vqcomp=0 tries to make each frame exactly the same size.) 678 vqcomp=0 tries to make each frame exactly the same size.)
679 If vqcomp=0.5, then rc_eq=sqrt(tex), so the allocation is somewhere 679 If vqcomp=0.5, then rc_eq=sqrt(tex), so the allocation is somewhere
680 between CBR and CQP. High complexity frames get somewhat lower quality 680 between CBR and CQP. High complexity frames get somewhat lower quality
681 than low complexity, but still more bits. 681 than low complexity, but still more bits.
682 682
683 While the actual selection of a good value of vqcomp is experimental, the 683 While the actual selection of a good value of vqcomp is experimental, the
684 following underlying factors determine the result: 684 following underlying factors determine the result:
685 Arguing towards CQP: You want the movie to be somewhere approaching 685 Arguing towards CQP: You want the movie to be somewhere approaching
686 constant quality; oscillating quality is even more annoying than constant 686 constant quality; oscillating quality is even more annoying than constant
687 low quality. (However, constant quality does not mean constant PSNR nor 687 low quality. (However, constant quality does not mean constant PSNR nor
688 constant QP. Details are less noticeable in high-motion scenes, so you can 688 constant QP. Details are less noticeable in high-motion scenes, so you can
689 get away with somewhat higher QP in high-complexity frames for the same 689 get away with somewhat higher QP in high-complexity frames for the same
690 perceived quality.) 690 perceived quality.)
691 Arguing towards CBR: You get more quality per bit if you spend those bits 691 Arguing towards CBR: You get more quality per bit if you spend those bits
692 in frames where motion compensation works well (which tends to be 692 in frames where motion compensation works well (which tends to be
693 correlated with "tex"): A given artifact may stick around several seconds 693 correlated with "tex"): A given artifact may stick around several seconds
694 in a low-motion scene, and you only have to fix it in one frame to improve 694 in a low-motion scene, and you only have to fix it in one frame to improve
695 the quality of the whole sequence. 695 the quality of the whole sequence.
696 696
697 Now for why the 1st pass ratecontrol method matters: 697 Now for why the 1st pass ratecontrol method matters:
698 The number of bits at constant quant is as good a measure of complexity as 698 The number of bits at constant quant is as good a measure of complexity as
699 any other simple formula for the purpose of allocating bits. But it's not 699 any other simple formula for the purpose of allocating bits. But it's not