VideoHelp Forum
+ Reply to Thread
Results 1 to 19 of 19
Thread
  1. I've been trying to find a definitive answer to this question for some time now, but without much success. Any insight would be greatly appreciated.

    I do all of my video transcoding with ffmpeg, mainly using a single pass, however for some videos I want to go the extra mile and use 2 pass encoding. I can do that well enough, however, I would like to improve the transcoding times.

    My question is, does the first pass only care about the source (input) file as is, which would mean that I need not apply various filters (such as scale, hqdn3d, unsharp, gradfun, etc) in the first pass? Or does it work on the video stream *after* it's been processed by the filters and bitrate specifiers?

    I have tried pass 1 with no filters and pass 2 with filters and the result does look pretty good, but I'd prefer to do it properly, even if it does take longer.

    Thanks in advance.
    Quote Quote  
  2. You must perform the filtering for each pass. ffmpeg doesn't remember the actual frames from the first pass, just some information about them. For that information to remain valid the two passes must receive the same video.

    2 pass VBR encoding will not give you better image quality than CRF encoding. It gives you the ability to specify the file size. Or are you using single pass CBR encoding?
    Quote Quote  
  3. Thanks for the reply jagabo. It's funny, I did some testing by transcoding both ways - with filters (including a scale change) in pass 1 and without filters. I played both videos at the same time and could not perceive any difference by eye. I even extracted the same frame from both videos and compared them in an image editor using various distortions to enhance any differences between the two, but did not find any. Would you expect there to be a difference?

    With respect to 2 pass vs single pass quality, I've noticed that for some videos (perhaps that start off with high bitrates?) that the first few seconds in the transcoded video can appear blocky and even a frame stutter can occur (viewed through Media Player Classic - Home Cinema).

    If I do a 2 pass transcode, none of those problems are evident. It plays smoothly and no initial blockiness.

    I'm not sure exactly what you mean by CBR encoding - I don't specify anything explicitly, I just use the presets, eg:

    HTML Code:
    ffmpeg -i input.mkv -an -c:v libx264 -preset:v slow -profile:v high -level:v 4.0 -b:v %VBitRate% -aspect %Aspect% -vf "filters" -threads 0 output.mkv
    I used to muck around with detailed settings before, but found the presets to be just as good. Can you explain/provide a sample of what you mean? Thanks.
    Quote Quote  
  4. Originally Posted by DamienS View Post
    Thanks for the reply jagabo. It's funny, I did some testing by transcoding both ways - with filters (including a scale change) in pass 1 and without filters. I played both videos at the same time and could not perceive any difference by eye. I even extracted the same frame from both videos and compared them in an image editor using various distortions to enhance any differences between the two, but did not find any. Would you expect there to be a difference?
    Well, it will depend on the particular video and the filters being used. For example, suppose you were running a strong noise reduction filter on a video that had little noise except for a section in the middle. If you don't use the filter during the first pass the encoder will see that noisy section in the middle and decide that section needs a lot of bitrate (noise needs more bitrate). Then during the second pass that noise would be gone but the encoder would still give that section a lot of bitrate, meaning there's less bitrate available for the rest of the video.

    Originally Posted by DamienS View Post
    With respect to 2 pass vs single pass quality, I've noticed that for some videos (perhaps that start off with high bitrates?) that the first few seconds in the transcoded video can appear blocky and even a frame stutter can occur (viewed through Media Player Classic - Home Cinema).

    If I do a 2 pass transcode, none of those problems are evident. It plays smoothly and no initial blockiness.

    I'm not sure exactly what you mean by CBR encoding - I don't specify anything explicitly, I just use the presets, eg:

    HTML Code:
    ffmpeg -i input.mkv -an -c:v libx264 -preset:v slow -profile:v high -level:v 4.0 -b:v %VBitRate% -aspect %Aspect% -vf "filters" -threads 0 output.mkv
    I'm not exactly sure how ffmpeg settings are applied to the x264 encoder but I think that is using single pass variable bitrate. In that mode x264 varies the bitrate based on the compressibility of the each frame -- but it has to be very conservative about how much more or less than the average it can use because it doesn't know what future frames will look like. (Keep in mind that for every shot that gets more than the average bitrate some other shot(s) will have to get less.) That can lead to problems like you describe, a shot at the start not getting enough bitrate because the encoder doesn't know if future shots will be just as hard to compress or or easily compressed. In a case like this, 2-pass encoding can give you better results because during the second pass (where the actual encoding is being done) the encoder knows it can dedicate a lot of bits to that section because there are later shots that don't need a lot of bitrate.

    You can avoid that type of problem and still encode in a single pass by using Constant Rate Factor encoding. In that mode you specify what "quality" you want and the encoder uses whatever bitrate is necessary at each frame to deliver that quality. The down side of CRF encoding is that you don't know what the final file size will be (and hence the average bitrate -- since Size = Bitrate * Time). You use "-crf X" on the ffmpeg command line to specify CRF encoding. Where X is a number between 0 (lossless but very large files) and 51 (very poor quality but very small files). Most people that use CRF encoding will use between 18 and 25 or thereabouts.

    If you compress a video in CRF mode, then go back and compress the source again in 2-pass VBR mode at an average bitrate that matches the CRF result, the two videos will look nearly identical.

    Basically, you have two methods of encoding. Bitrate and Quality. In Bitrate mode you know what the file size will be but you don't know what the quality will be. In Quality mode you know what the quality will be but you don't know what the bitrate will be.
    Quote Quote  
  5. Thanks again for an informative reply jagabo. I did some further tests with 2-pass encoding. I used some five filters in both the 1st and 2nd pass (case A) and compared the result with using no filters in pass 1 and full filters in pass 2 (case B).

    The results were striking. Case A looked pretty bad, while case B looked pretty good. In case A, it looked like the filters were applied twice (even though encoding takes place only in pass 2). I think I will stick with case B...

    I also carried out some tests with CRF, and as you say, it's somewhat of a lottery as to how big the resulting video will end up being and what the average bitrate will be. I tried to match a target bitrate and eventually came close by changing CRF values. The resulting video quality was of the same order as the 2-pass case B, and while it was just a single pass, the encoding time was slower - probably not much different than the 2-pass overall.

    I guess my preference is to select an average bitrate, and therefore file size, than to be 'surprised' by what I get with CRF. This is especially so when I'm transcoding seasons of TV show episodes - I prefer them to be roughly the same size.

    Thanks again.
    Quote Quote  
  6. Originally Posted by DamienS View Post
    I did some further tests with 2-pass encoding. I used some five filters in both the 1st and 2nd pass (case A) and compared the result with using no filters in pass 1 and full filters in pass 2 (case B).

    The results were striking. Case A looked pretty bad, while case B looked pretty good. In case A, it looked like the filters were applied twice (even though encoding takes place only in pass 2). I think I will stick with case B...
    Then something isn't working right. Not using the same filters on both passes should never look better than when using all filters on both passes.

    Originally Posted by DamienS View Post
    when I'm transcoding seasons of TV show episodes - I prefer them to be roughly the same size.
    I prefer to know that all the videos I compress will have an acceptable quality level, without using more disk space than necessary. Typically, I see about a two fold difference between the smallest and largest episodes when encoding a series.

    To each his own, of course.
    Last edited by jagabo; 29th Nov 2013 at 22:25.
    Quote Quote  
  7. Originally Posted by DamienS View Post
    I also carried out some tests with CRF, ....., it's somewhat of a lottery as to how big the resulting video will end up being and what the average bitrate will be.
    Only first time looking for that CRF number - quantizer, then you just can use that number all the time , even with different filters applied, different video content, .., But 2pass is lottery every time, quality fluctuates in any direction depending on filtering or video content.
    Quote Quote  
  8. Originally Posted by jagabo View Post
    Then something isn't working right. Not using the same filters on both passes should never look better than when using all filters on both passes.
    You're right, I misspoke - I was comparing wrong files! But, after comparing the correct files, I could see no difference in quality (as per my first post). So I might stick with no filter pass-1, for 2-pass encoding.

    Originally Posted by _AI_
    But 2pass is lottery every time, quality fluctuates in any direction depending on filtering or video content.
    In my experience with single pass CBR (and I've been doing this for years), I've never found quality to be an issue (except the odd case as I've mentioned above, and if that happens I do a 2-pass encode). I always ensure I select a respectable bitrate compared to the source file, so 99 times out 100 I win the lottery!

    Anyway, I'll still do some more experimenting with various settings, etc.
    Quote Quote  
  9. Using CBR is a colossal waste of bitrate, but sure some use it every day, using editing softwares or even backing up TV, movies, but anyway using CBR, there could be scenes that need more bitrate.
    Originally Posted by DamienS View Post
    I always ensure I select a respectable bitrate compared to the source file
    To ensure means to overshoot your bitrate to do it only once or to test it a bit especially in your case changing filters, not mentioning video content, but anyway you still likely be off for a scene, chances that you choose average same as your encoder would set using certain CRF is not high.

    Try this: take some clips from your videos, different video content, with filtering or without, so you have four videos. Encode them all CRF 18. In this case you should get balanced, relative quality the same in all clips. The only thing that is going to be different is bitrate. Now, how do you do that using 2pass encoding to average? Imposible, you can do it half a day and still not getting optimal bitrate.

    CRF encoding can teach us what bitrate is needed for a scene, video content, for x264 encoder, very handy.

    With 2pass VBR to average is difficult to guess how your encoder distributes bitrate. After denoising there is much less bitrate needed, sometimes drastically, difficult to guess how much. Good example is using very good bob deinterlacer QTGMC (creates double frame rate) , there was shock for me that less bitrate was needed than what I'd get encoding just interlace. It sounds like a joke first, but QTGMC uses a touch of denoise too, so hard to guess first. Using 2pass VBR with double frame rate filter , I'd still encode with too much higher bitrate until today because I'd just guess and it would look good. Not the end of the World sure, but again, no guessing now.
    Quote Quote  
  10. I do understand what you are saying _Al_ and I do agree with the theoretical basis. But I make a judgment based on what I can actually see while playing the content back, not so much on what the optimal bitrate should be for any second of content. If I can't tell the difference between say a DVD file and a transcoded version, then it's good enough for me. I'm not one of those people who fret about having 'lossless' quality or avoiding scaling away from 1:1, etc as any minor differences will either not be perceivable and/or be smeared out by the viewing distance from the screen, etc.

    Sure, the more obvious differences will be in motion handling, especially fast motion, but if even those scenes look fine, then I'm happy with the encode.

    However, it's nice to know that there is a fallback option (CRF) if I really need it. One further question I have is what role does "-b:v bitrate" play, if any, when using CRF?
    Quote Quote  
  11. I'm still not sure you get this 100%, CRF doesn't mean super quality, choosing something like CRF 25 and up will cause visual degradation more and more obvious, point is it is you who decides what quality you want, and that algorithm is watching it for you.

    There is a switch needed in thinking, just take one episode, encode part of it with CRF 18, .., 20,..., 22 and watch it,...,Whatever number barely passes for you as OK you choose it. You reliaze that 21 works, 22 makes it visually somehow not that good for you so you choose 21. After this you have discovered YOUR number (quantizer) for your type of videos. Then you use that number all the time and you have constant watchdog quality/size working for you. No more guessing average 2pass. You can test filters and still using same CRF number. After filtering CRF just gives it less bitrate but keeps quality you decided that works for you.
    Last edited by _Al_; 30th Nov 2013 at 21:33.
    Quote Quote  
  12. Originally Posted by DamienS View Post
    I make a judgment based on what I can actually see while playing the content back, not so much on what the optimal bitrate should be for any second of content. If I can't tell the difference between say a DVD file and a transcoded version, then it's good enough for me.
    His point is that if you are using a bitrate that gives "good" quality for the most demanding of your videos, then you are using too much bitrate for the others. That's the reason for CRF encoding. Each video gets just the bitrate it needs to deliver the quality you specify.
    Quote Quote  
  13. Originally Posted by _Al_ View Post
    I'm still not sure you get this 100%, CRF doesn't mean super quality, choosing something like CRF 25 and up will cause visual degradation more and more obvious, point is it is you who decides what quality you want, and that algorithm is watching it for you.

    There is a switch needed in thinking, just take one episode, encode part of it with CRF 18, .., 20,..., 22 and watch it,...,Whatever number barely passes for you as OK you choose it.
    No, I do get it. I did precisely this. I encoded 10mins of an ep with a predefined bitrate using the 2-pass method. Then I did the same with CRF20,21,22 and with different presets. None of the CRF encodes looked any better than the 2-pass - NONE (even when comparing them frame-by-frame). The only differences were in the file sizes and bitrates - the CRF versions had almost double my nominated 2-pass bitrate.

    So given that I can not perceive any visual improvement in quality between the various CRF settings and the 2-pass version, I see not reason to pay the penalty in file sizes that are nearly doubled.

    Originally Posted by jagabo
    His point is that if you are using a bitrate that gives "good" quality for the most demanding of your videos, then you are using too much bitrate for the others. That's the reason for CRF encoding.
    Well... I may be using more than I need in 'quiet' places, true, but then again, my final file sizes are still way smaller than with CRF and with no discernible (perceptible) difference in quality. So why worry about some bitrate overkill when I still end up with much smaller files?

    If you could limit the maximum bitrate while still using CRF, that might be a suitable compromise for me, but it seems that you can't really do this. I've tried playing around with maxbitrate and bufsize settings etc, however it still doesn't really respect the constraints (as I imagine these are somewhat mutually exclusive requirements for CRF encoding).
    Quote Quote  
  14. Originally Posted by DamienS View Post
    Originally Posted by _Al_ View Post
    I'm still not sure you get this 100%, CRF doesn't mean super quality, choosing something like CRF 25 and up will cause visual degradation more and more obvious, point is it is you who decides what quality you want, and that algorithm is watching it for you.

    There is a switch needed in thinking, just take one episode, encode part of it with CRF 18, .., 20,..., 22 and watch it,...,Whatever number barely passes for you as OK you choose it.
    No, I do get it. I did precisely this. I encoded 10mins of an ep with a predefined bitrate using the 2-pass method. Then I did the same with CRF20,21,22 and with different presets. None of the CRF encodes looked any better than the 2-pass - NONE (even when comparing them frame-by-frame). The only differences were in the file sizes and bitrates - the CRF versions had almost double my nominated 2-pass bitrate.

    So given that I can not perceive any visual improvement in quality between the various CRF settings and the 2-pass version, I see not reason to pay the penalty in file sizes that are nearly doubled.

    Originally Posted by jagabo
    His point is that if you are using a bitrate that gives "good" quality for the most demanding of your videos, then you are using too much bitrate for the others. That's the reason for CRF encoding.
    Well... I may be using more than I need in 'quiet' places, true, but then again, my final file sizes are still way smaller than with CRF and with no discernible (perceptible) difference in quality. So why worry about some bitrate overkill when I still end up with much smaller files?

    If you could limit the maximum bitrate while still using CRF, that might be a suitable compromise for me, but it seems that you can't really do this. I've tried playing around with maxbitrate and bufsize settings etc, however it still doesn't really respect the constraints (as I imagine these are somewhat mutually exclusive requirements for CRF encoding).





    If the size is too large then use higher CRF value. Once you settle on a "quality" level that is good enough for you , that's all you need. People tend to use 2pass only when they need a specific filesize or bitrate (e.g. fixed media limits like blu-ray , or bandwidth restrictions like streaming)

    You cannot make valid comparisons on "quality" at different bitrates . CRF won't look better than 2pass at the same bitrate. The point is it will look almost the same as 2pass at the same bitrate - with the benefit being faster since it's 1 pass instead of 2, and certainly better than 1pass ABR . Even though the 1st pass in a 2pass encode is usually done with quick settings (so it's not 2x faster), it's still much faster.

    If you were to use CRF and achieve "x" bitrate , then encode 2pass with "x" bitrate and same settings otherwise - the video will look almost identical .

    VBV certainly works with CRF using x264 . That's probably an issue with ffmpeg libx264 , or your binary has an issue. Personally I think that' s not the way to do it. Using VBV to "cap" can only reduce quality . I would just use a CRF value that's in the range of acceptable quality for you. If in your tests, the filesize was 2x of your 2pass bitrate runs when using CRF20-22 - that tells me right away your "acceptable" CRF value is going to be very high and you're not a very discerning or picky person

    It sounds like there are other issues with your filtering as well. They should be applied to both passes. Just stop and think about it - how can the encoder properly allocate bitrate and frametypes if the 1st pass doesn't even receive those filters ? Something doesn't make sense about your observations
    Quote Quote  
  15. Originally Posted by DamienS View Post
    I encoded 10mins of an ep with a predefined bitrate using the 2-pass method. Then I did the same with CRF20,21,22 and with different presets. None of the CRF encodes looked any better than the 2-pass - NONE
    You did not finish your test,

    you need to go higher with that CRF, higher number - you get less quality. x264 encoders allows to set that number for CRF from 0 (lossless) to 52 (almost garbage) .Not sure what ffmpeg can do and not sure if CRF can be zero now, maybe CQ mode only, but that is not important here,

    you need to find CRF that is ok and other CRF that is not ok for you, only then you know that "your" CRF number is in between , so narrow it down.
    Last edited by _Al_; 1st Dec 2013 at 01:34.
    Quote Quote  
  16. Look in dark grainy areas -- that's one of x264 weakest points. You'll start seeing posterization artifacts there when you don't use sufficient bitrate. See the videos in this post as an example:

    https://forum.videohelp.com/threads/345427-Handbrake-Should-i-leave-it-on?p=2156674&vie...=1#post2156674
    Quote Quote  
  17. Originally Posted by poisondeathray
    If you were to use CRF and achieve "x" bitrate , then encode 2pass with "x" bitrate and same settings otherwise - the video will look almost identical
    My point was (well, one of them) that I could not achieve the same (lower) bitrate with CRF, no matter how high a CRF number I used (well, at least to the point where the quality looked crappy, but the bitrate was still quite a bit higher than what I set with 2-pass, so I saw no point in going to even higher CRFs).

    Originally Posted by poisondeathray
    If in your tests, the filesize was 2x of your 2pass bitrate runs when using CRF20-22 - that tells me right away your "acceptable" CRF value is going to be very high and you're not a very discerning or picky person
    You couldn't be further from the truth. I've worked in computer graphic arts all my professional life and I'm anything but picky. However, I let my eyes decide what is acceptable rather than a theoretical ideal.

    Originally Posted by _AI_
    You did not finish your test, you need to go higher with that CRF, higher number ...
    I did go higher, as mentioned above, to the point where the video looked visibly worse, but the average bitrate for that encode was still quite a bit higher then with my 2-pass encode.

    Originally Posted by jagabo
    Look in dark grainy areas -- that's one of x264 weakest points. You'll start seeing posterization artifacts there when you don't use sufficient bitrate. See the videos in this post as an example:

    https://forum.videohelp.com/threads/345427-Handbrake-Should-i-leave-it-on?p=2156674&vie...=1#post2156674
    I'll have a look at it - cheers.
    Quote Quote  
  18. Originally Posted by DamienS View Post
    Originally Posted by _AI_
    You did not finish your test, you need to go higher with that CRF, higher number ...
    I did go higher, as mentioned above, to the point where the video looked visibly worse, but the average bitrate for that encode was still quite a bit higher then with my 2-pass encode.
    Please post some samples that show that. I've never seen 2-pass deliver noticeably better quality than CRF with both at the same average bitrate (and otherwise similar settings).
    Quote Quote  
  19. You must have set different settings or filtering, .., or ffmpeg works differently. Using x264 encoder gives very similar, almost the same results using CRF or 2pass and getting file that has the same volume.

    Bitrate viewer shows bitrate distribution that tends to be exactly the same, except 2pass distribution seems to be somehow tiny bit smoother where scene changes (as if encoder knew what is going to follow). Not sure if this is good or bad thing. And also bitrate could be different at the times but margin is not that big at all to say something is visibly worse or better.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!