VideoHelp Forum




+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 39
  1. Anonymous543
    Guest
    i readed this guide of h264
    https://trac.ffmpeg.org/wiki/Encode/H.264

    but there is only crf and two pass examples

    how can i do average bitrate encoding where we specify bitrate not crf with only one line of code
    need one example code
    Quote Quote  
  2. define average bitrate... normally you can control bit rate by specyfying (vbv) buffer size, minimum bitrate and maximum bitrate - usually buffer size is specified to match destination medium characteristic.

    In case of libx264 there is 'vbv_maxrate=' and 'vbv_bufsize=' - if your buffer will be to low then quality will be poor, if too high then you may gain nothing in exchange...

    To control fine encoding aspects on libx264 i use 'x264opts=' structure and this may look in ffmpeg script as:

    Code:
    @setlocal
    
    @SET x264opts="crf=20:level=4.0:qpmin=16:vbv_maxrate=9984:vbv_bufsize=9984:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
    
    @ffmpeg.exe -hide_banner -v quiet -stats -y -i %name% -sn -dn -c:v libx264 -preset faster -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -flags:a +qscale -c:a libmp3lame -q:a 4 -f matroska "%~n1_.mkv"
    
    @endlocal
    @pause
    In above example buffer size is 1 second long - fair size for video but you can lower it so bitrate will be flatten - too small size will lead to buffer overflow, and too high as i said may give unnecessary latency and at worst case scenario lead to underflow errors.
    Quote Quote  
  3. Why don't you use MeGUI? You will see 2 pass-average bitrate option in H264 profiles. And you won't have to deal with command lines.

    Using ffmpeg won't you give any extra quality. I've done encodings with MeGUI, Handbrake, AVIDemux, VirtualDub, ffmpeg, each gave the same video quality - unless you use some special Avisynth scripts.
    Quote Quote  
  4. Anonymous543
    Guest
    Originally Posted by pandy View Post
    define average bitrate... normally you can control bit rate by specyfying (vbv) buffer size, minimum bitrate and maximum bitrate - usually buffer size is specified to match destination medium characteristic.

    In case of libx264 there is 'vbv_maxrate=' and 'vbv_bufsize=' - if your buffer will be to low then quality will be poor, if too high then you may gain nothing in exchange...

    To control fine encoding aspects on libx264 i use 'x264opts=' structure and this may look in ffmpeg script as:

    Code:
    @setlocal
    
    @SET x264opts="crf=20:level=4.0:qpmin=16:vbv_maxrate=9984:vbv_bufsize=9984:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1"
    
    @ffmpeg.exe -hide_banner -v quiet -stats -y -i %name% -sn -dn -c:v libx264 -preset faster -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -flags:a +qscale -c:a libmp3lame -q:a 4 -f matroska "%~n1_.mkv"
    
    @endlocal
    @pause
    In above example buffer size is 1 second long - fair size for video but you can lower it so bitrate will be flatten - too small size will lead to buffer overflow, and too high as i said may give unnecessary latency and at worst case scenario lead to underflow errors.



    If i make some change to crf example which is
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv


    Instead of specifying crf if i specify -b:v like this
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -b:v 1000k -c:a copy output.mkv
    Then will it work?
    Quote Quote  
  5. Originally Posted by kirito View Post
    If i make some change to crf example which is
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
    Instead of specifying crf if i specify -b:v like this
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -b:v 1000k -c:a copy output.mkv
    Then will it work?
    Yes, but crf focus on quality where bitrate will focus on bitrate not on quality - you may use crf and bitrate control trying to keep as much possible from crf.

    If your goal is o match file size for example use DVD disc as much as possible then you can follow this https://forum.videohelp.com/threads/380289-encode-with-X264-target-size

    But there is no warranty of course so you must be prepared to allocate some spare headroom.
    Quote Quote  
  6. Anonymous543
    Guest
    Originally Posted by pandy View Post
    Originally Posted by kirito View Post
    If i make some change to crf example which is
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
    Instead of specifying crf if i specify -b:v like this
    Code:
    ffmpeg -i input -c:v libx264 -preset slow -b:v 1000k -c:a copy output.mkv
    Then will it work?
    Yes, but crf focus on quality where bitrate will focus on bitrate not on quality - you may use crf and bitrate control trying to keep as much possible from crf.

    If your goal is o match file size for example use DVD disc as much as possible then you can follow this https://forum.videohelp.com/threads/380289-encode-with-X264-target-size

    But there is no warranty of course so you must be prepared to allocate some spare headroom.

    So the -b:v with libx264, will specify average bitrate or constant bitrate?am not sure about it because you said I have to specify bufsize minrate maxrate vbv etc too
    Quote Quote  
  7. Anonymous543
    Guest
    Originally Posted by ridibunda View Post
    Why don't you use MeGUI? You will see 2 pass-average bitrate option in H264 profiles. And you won't have to deal with command lines.

    Using ffmpeg won't you give any extra quality. I've done encodings with MeGUI, Handbrake, AVIDemux, VirtualDub, ffmpeg, each gave the same video quality - unless you use some special Avisynth scripts.
    because ffmpeg can do many options which gui encoders does not includes....like editing meta data ,adding subtitles , adding extra tracks etc

    so for encoding i prefer ffmpeg
    and for lossless cutting video clips, croping videos ,adding some filters for that kind of oprations i use gui softwares like avidemux
    Quote Quote  
  8. Originally Posted by kirito View Post
    So the -b:v with libx264, will specify average bitrate or constant bitrate?am not sure about it because you said I have to specify bufsize minrate maxrate vbv etc too
    It define your target bitrate but key to overall bitrate is bitrate control - constant bitrate is extreme case for variable (average) bitrate where bitrate control is very tight and strict so bitrate variability is minimized but still there is no such thing like constant bitrate - from practical perspective it is variable bitrate with very low bitrate variability. You can to constant bitrate for dynamic data compression - sometimes to get very strict constant bitrate, special data are added on top - those data are used to fill gaps and are called usually stuffing - this is common practice in broadcast industry for example for static multiplexing (popular in past but nowadays used only in very simplistic setups)
    Quote Quote  
  9. Anonymous543
    Guest
    Originally Posted by pandy View Post
    Originally Posted by kirito View Post
    So the -b:v with libx264, will specify average bitrate or constant bitrate?am not sure about it because you said I have to specify bufsize minrate maxrate vbv etc too
    It define your target bitrate but key to overall bitrate is bitrate control - constant bitrate is extreme case for variable (average) bitrate where bitrate control is very tight and strict so bitrate variability is minimized but still there is no such thing like constant bitrate - from practical perspective it is variable bitrate with very low bitrate variability. You can to constant bitrate for dynamic data compression - sometimes to get very strict constant bitrate, special data are added on top - those data are used to fill gaps and are called usually stuffing - this is common practice in broadcast industry for example for static multiplexing (popular in past but nowadays used only in very simplistic setups)

    So -b:v for libx264 specifies bitrate which is variable ,but very less?��
    Quote Quote  
  10. Originally Posted by kirito View Post
    So -b:v for libx264 specifies bitrate which is variable ,but very less?��
    In my personal opinion not - lib.x264 is rather difficult to be configured to produce more or less CBR video - it can be done with some limited success but this particular encoder was never designed to be able do CBR video. Using your examples it is rather closer to concept of the ABR than to the CBR.
    (btw ABR concept was introduced if i recall correctly by lame for MP3 encoding).
    Quote Quote  
  11. Anonymous543
    Guest
    I don't want cbr i just want my video bitrate goes high at complex sections and low during non complex sections
    how can I get that?
    Quote Quote  
  12. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Originally Posted by kirito View Post
    I don't want cbr i just want my video bitrate goes high at complex sections and low during non complex sections
    how can I get that?
    That's exactly what it does whether you use 2-pass or CRF. What did you think it was doing ?
    Last edited by davexnet; 6th Feb 2022 at 02:09.
    Quote Quote  
  13. Anonymous543
    Guest
    Originally Posted by davexnet View Post
    Originally Posted by kirito View Post
    I don't want cbr i just want my video bitrate goes high at complex sections and low during non complex sections
    how can I get that?
    That's exactly it does whether you use 2-pass or CRF. What did you think it was doing ?
    am not sure what is it doing ,as above pandy said for ABR encoding we have to specify vbv bufsize minrate maxrate...is it neccessory? for abr encoding? what if i only specify -b:v
    Quote Quote  
  14. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    ABR is a poor choice and is not advised.
    https://slhck.info/video/2017/03/01/rate-control.html
    Quote Quote  
  15. Originally Posted by kirito View Post
    because ffmpeg can do many options which gui encoders does not includes....like editing meta data ,adding subtitles , adding extra tracks etc
    so for encoding i prefer ffmpeg
    and for lossless cutting video clips, croping videos ,adding some filters for that kind of oprations i use gui softwares like avidemux
    MeGUI also does them. First, you can extract subtitle and audio tracks from original file (via "HD Streams Extractor", which is actually an inside-GUI to command-line tools like "eac3to"), and later add them to the encoded file while muxing.

    Remember that MeGUI is a package with all-needed encoding tools like dgindex, eac3to, ffmpeg, lsmash, tsmuxer, x264 and x265 encoders, etc... Most of them are command-line tools, but MeGUI offers you a graphical user interface, so you don't need to write or memorise any command lines. There are also many options for H264 in MeGUI.

    For "lossless cutting video clips", I guess you mean "cutting without re-encoding", the best to use is MKVToolnix, or VirtualDubMod (which is very old but still useful).

    Cropping is not recommended. You should leave them as original. Even you cut "black bars" on the top and bottom, you will see them again on your TV.

    Croppings also make "a small zoom" on the video, that zooming reduces the quality.
    Quote Quote  
  16. Originally Posted by kirito View Post
    am not sure what is it doing ,as above pandy said for ABR encoding we have to specify vbv bufsize minrate maxrate...is it neccessory? for abr encoding? what if i only specify -b:v
    No it is not necessary, you specifying those additional parameters to better control your encoding so you can be closer to final expectations but even guide you provided recommend to avoid ABR (from my perspective this is not ABR but just bitrate) mode - you control encoder by specifying what is your goal.
    For this and in many earlier threads you started it is not entirely clear what is your goal.

    If you trying to get some knowledge then do experiments - you not pay for anything except electricity...
    Quote Quote  
  17. Anonymous543
    Guest
    after reading this
    https://slhck.info/video/2017/03/01/rate-control.html

    my input has only video stream
    firstly i tried Average Bitrate (ABR, also “target bitrate”) method with this code
    Code:
    ffmpeg -i input.mp4 -vf scale=426:240 -c:v libx264 -preset ultrafast -b:v 260k output260k.mp4
    and i saw during encoding its bitrate goes higher and lower then 260k
    Image
    [Attachment 63215 - Click to enlarge]




    after that i tried Constrained Encoding (VBV) method with this code
    Code:
    ffmpeg -i input.mp4 -vf scale=426:240 -c:v libx264 -preset ultrafast -b:v 260k -maxrate 260k -bufsize 520k output.mp4
    actualy i dont know how much bufsize and maxrate should be set so i kept -maxrate same as my target birate and -bufsize double of -maxrate
    during encoding its bitrate never goes higher then 260k


    what is the major advantage and disadvantages of Average Bitrate (ABR, also “target bitrate”) method and Constrained Encoding (VBV) method
    trough experiment i know that in constrained encoding bitrate doesnot goes higher then maxrate but dont know what is the role of bufsize??

    when to use Average Bitrate (ABR, also “target bitrate”) method?? and also
    when to use Constrained Encoding (VBV) method??



    currently i have very low specification computer thats why i used ultrafast preset with higher bitrate you can check my pc specifications in my profile..
    Last edited by Anonymous543; 7th Feb 2022 at 01:49.
    Quote Quote  
  18. I saw that you use a gui to crop. You can crop with ffmpeg by first using -vf cropdetect til you get useful values and then run again with -vf crop.
    For one-pass average bitrate, your best bet is what you were using -b:v
    As mentioned above MeGUI is quite good for your purposes, Handbrake is fine but has to be tweaked from it's preset values, Staxrip does a really good job at a GUI, Hybrid does everything but has a learning curve, RipBot is great as well, but I've found it to be unstable sometimes.
    Last edited by blud7; 7th Feb 2022 at 10:10.
    Quote Quote  
  19. Originally Posted by kirito View Post
    currently i have very low specification computer that's why i used ultrafast preset with higher bitrate you can check my pc specifications in my profile..
    Go for baseline not high profile if your computer is slow or you can turn off CABAC in high profile... i would personally use preset 'faster' - this is more or less inline with some reports for example https://unrealaussies.com/tech/x264-presets-and-settings-quality-analysis-of-720p60-apex-legends/ - turning off CABAC you will loose few % but playout should be improved, you may try to turn off some other features - beware that provided link refer to computer graphics - this may be not entirely inline with regular movies.

    try this one - 426 is not dividable by 16 - allow encoder to breathe... sometimes scenes need more bits - see no audio settings

    Code:
    ffmpeg -i input.mp4 -vf scale=432:-2 -c:v libx264 -preset ultrafast -b:v 260k -maxrate 390k -bufsize 390k output.mp4
    crop shall precede scale in video filter chain
    Last edited by pandy; 7th Feb 2022 at 14:32.
    Quote Quote  
  20. Anonymous543
    Guest
    Originally Posted by pandy View Post
    Originally Posted by kirito View Post
    currently i have very low specification computer that's why i used ultrafast preset with higher bitrate you can check my pc specifications in my profile..
    Go for baseline not high profile if your computer is slow or you can turn off CABAC in high profile... i would personally use preset 'faster' - this is more or less inline with some reports for example https://unrealaussies.com/tech/x264-presets-and-settings-quality-analysis-of-720p60-apex-legends/ - turning off CABAC you will loose few % but playout should be improved, you may try to turn off some other features - beware that provided link refer to computer graphics - this may be not entirely inline with regular movies.

    try this one - 426 is not dividable by 16 - allow encoder to breathe... sometimes scenes need more bits - see no audio settings

    Code:
    ffmpeg -i input.mp4 -vf scale=432:-2 -c:v libx264 -preset ultrafast -b:v 260k -maxrate 390k -bufsize 390k output.mp4
    crop shall precede scale in video filter chain


    playback on my pc isnt problem..my computer can play videos smothly which is encoded at high profiles
    but it should be in under 720p resolution...
    main problem is encoding speed is too loww..and thats why i use ultrafast preset with libx264 codec which actually automaticaly selects constrained baseline video profile...thats why output video only contains I and P frames (no Bframes because constrained baseline profile doesnot supports Bframes i guess)

    i can go for higher bitrates to preserve quality of video and encoding speeds in constrained baseline profile

    but the question is which method shall i use for speedy encodes
    Average Bitrate (ABR, also “target bitrate”) method with only specifying -b:v
    or
    Constrained Encoding (VBV) method which requires additional settings whihch is -b:v -minrate -maxrate -bufsize etc
    and also i dont know properly how this -minrate -maxrate -bufsize affects the video quality



    Theoretically if i encode a video with both methods at same bitrate and same settings then which one will give better visaul quality??
    Practically it's too difficult (impossible)to know which one is giving better quality
    Last edited by Anonymous543; 8th Feb 2022 at 02:11.
    Quote Quote  
  21. Originally Posted by kirito View Post
    playback on my pc isnt problem..my computer can play videos smothly which is encoded at high profiles
    but it should be in under 720p resolution...
    main problem is encoding speed is too loww..and thats why i use ultrafast preset with libx264 codec which actually automaticaly selects constrained baseline video profile...thats why output video only contains I and P frames (no Bframes because constrained baseline profile doesnot supports Bframes i guess)

    i can go for higher bitrates to preserve quality of video and encoding speeds in constrained baseline profile

    but the question is which method shall i use for speedy encodes
    Average Bitrate (ABR, also “target bitrate”) method with only specifying -b:v
    or
    Constrained Encoding (VBV) method which requires additional settings whihch is -b:v -minrate -maxrate -bufsize etc
    and also i dont know properly how this -minrate -maxrate -bufsize affects the video quality

    Theoretically if i encode a video with both methods at same bitrate and same settings then which one will give better visaul quality??
    Practically it's too difficult (impossible)to know which one is giving better quality
    Best quality results are with CRF, you can add maxbitrate and buffer size to cap (limit) variability of bitrate.
    Buffer size IMHO should be around 1 second for max bitrate (but some people may disagree with this) i.e. maxbitrate = buffsize - alternatively you may try to use GOP length (or rather GOP/fps) to shape buffer size but then i would avoid anything higher than 5 seconds (once again other may disagree).
    IMHO most important baseline limitation beside to B frames is lack of CABAC - if your playout is OK then i would use B frames and CABAC - both are substantial features and quality benefits are obvious (both saving bitrate).

    It is unavoidable - video compression is computationally intensive task - if your GPU support HW video compression (IMHO best video compression in HW is offered by NVidia) then you can use dedicated HW for much faster compression (albeit reduced quality and/or increased bitrate).

    All above is purely my opinion and it doesn't try to address your playout environment (such as screen type and size, content etc).
    Last edited by pandy; 10th Feb 2022 at 12:24.
    Quote Quote  
  22. Anonymous543
    Guest
    but the question is which method shall i use for speedy encodes
    Average Bitrate (ABR, also “target bitrate”) method with only specifying -b:v
    or
    Constrained Encoding (VBV) method which requires additional settings whihch is -b:v -minrate -maxrate -bufsize etc
    and also i dont know properly how this -minrate -maxrate -bufsize affects the video quality



    Theoretically if i encode a video with both methods at same bitrate and same settings then which one will give better visaul quality??
    Practically it's too difficult (impossible)to know which one is giving better quality

    still this question is unanswered ,may be only the developers of x264 can know who will perform well ABR or constrained(VBV)
    where file quality is detemined by bitrate(filesize) not with CRF.
    Quote Quote  
  23. Abr delivers the worst quality. Use 2-pass vbr or crf.

    There's no reason to constrain bitrate unless you have hardware limitations (for example, Blu-ray) or streaming limitations (where you may want to limit peaks and buffer size).

    Presets ultrafast and superfast typically require ~2x more bitrate than veryfast or above. Avoid using them unless you can afford the extra bitrate or are constrained by realtime encoding.
    Quote Quote  
  24. Anonymous543
    Guest
    So..for offline usage ABR is used and for streaming purposes constrained bitrate used??
    Quote Quote  
  25. ABR with constraints is used for live broadcast/streaming -- it's live so you can't do two passes and you usually have bitrate constraints. Use CRF or 2-pass with everything else.

    With ABR the encoder doesn't know what's coming in the future (aside from the small lookahead buffer) and doesn't have a memory of what happened in the past. So it can't allocate bits optimally over an entire video. It just uses some conservative settings to keep the bitrate in the right ballpark for the small piece of video it's currently working on. Easily compressed portions of the video will end up with more bitrate than they need. Hard to compress sections will end up with less than they need.

    CRF encoding just compresses each frame with the quality you specify. It doesn't care about bitrate.

    2-pass encoding examines every frame during the first pass, determining how much bitrate each needs (it uses a CRF encoding for this). Then during the second pass it allocates bits to each frame based on that need and the overall average bitrate you specified.

    Use ABR encoding for live encoding. Use CRF encoding when you want a specific quality but don't care about the exact file size. Use 2-pass encoding when you need a specific file size but don't care about quality.
    Quote Quote  
  26. Anonymous543
    Guest
    Thanks for info i understand now which method will be good for my videos
    Quote Quote  
  27. Anonymous543
    Guest
    -bufsize is related to playback decoder or encoder related??
    Quote Quote  
  28. Originally Posted by kirito View Post
    -bufsize is related to playback decoder or encoder related??
    encoder - this is buffer used to shape bitrate during encoding process
    Quote Quote  
  29. It's both an encoding and decoding issue. The only time you care about the buffer size is when you must conform to some playback limitations. For example, Blu-ray players have a limited amount of memory so you need to limit the buffer size while encoding -- so as not to overflow that memory while decoding.
    Last edited by jagabo; 11th Feb 2022 at 20:54.
    Quote Quote  
  30. Anonymous543
    Guest
    As if i only specify -b:v without specifying -bufsize then will any default bufsize will be used??
    Quote Quote  



Similar Threads

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