VideoHelp Forum
+ Reply to Thread
Results 1 to 10 of 10
Thread
  1. I want to encode Blu-ray M2TS files with x264, my code is like this:
    enc_ctx = avcodec_alloc_context3(codec);
    enc_ctx->codec_id = AV_CODEC_ID_H264;
    enc_ctx->bit_rate = 20000000;

    When a video has a simple scene, such as 10 seconds, its encoding bitrate will be very small, only 1M or 2M bitrate. In order to achieve an average bitrate of 20M/s, the subsequent bitrate will be very large, sometimes reaching 150M/s. , at this time Blu-ray Player will freeze due to high bitrate.
    I set enc_ctx->rc_max_rate = 50000000;
    but it seems to have no effect. How can I limit the maximum bitrate? Thanks
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Seet this:
    https://www.videohelp.com/hd#tech
    and this:
    https://web.archive.org/web/20180227201628/http://www.x264bluray.com/ (There are links to subpages at the bottom with specific examples).
    Quote Quote  
  3. Originally Posted by moon_light View Post
    When a video has a simple scene, such as 10 seconds, its encoding bitrate will be very small, only 1M or 2M bitrate. In order to achieve an average bitrate of 20M/s, the subsequent bitrate will be very large, sometimes reaching 150M/s. , at this time Blu-ray Player will freeze due to high bitrate.
    I set enc_ctx->rc_max_rate = 50000000;
    but it seems to have no effect. How can I limit the maximum bitrate? Thanks
    Your expectations are bit contradictory - seem your goal is more like Constant BitRate. Maximum bitrate is described by your decoder capabilities - mostly by level supported by decoder. Definitely you should not go beyond this limitation. As you not providing any details about your decoder then i strongly recommends https://en.wikipedia.org/wiki/Advanced_Video_Coding?useskin=vector#Levels so you can set encoder to particular level supported by your decoder. By telling to encoder what is your goal i.e. level then it should automatically limit itself to not go beyond level.
    Quote Quote  
  4. Use CRF instead of bitrate with x264.
    Start with CRF 18 (visually lossless).
    Smaller values increase the quality, but also the bit rate and file size.
    Quote Quote  
  5. I don't know about the front end you are using but the x264 command line options are --vbv-bufsize 30000 --vbv-maxrate 30000. You will also need to limit other settings like reference frames, max consecutive b-frames Profile and Level, etc. There's also a blu-ray compatibility option --bluray-compat. I don't know if it automatically sets all those options for you.

    https://forum.videohelp.com/threads/377772-x264-compatible-settings#post2439267
    Quote Quote  
  6. Originally Posted by pandy View Post
    Originally Posted by moon_light View Post
    When a video has a simple scene, such as 10 seconds, its encoding bitrate will be very small, only 1M or 2M bitrate. In order to achieve an average bitrate of 20M/s, the subsequent bitrate will be very large, sometimes reaching 150M/s. , at this time Blu-ray Player will freeze due to high bitrate.
    I set enc_ctx->rc_max_rate = 50000000;
    but it seems to have no effect. How can I limit the maximum bitrate? Thanks
    Your expectations are bit contradictory - seem your goal is more like Constant BitRate. Maximum bitrate is described by your decoder capabilities - mostly by level supported by decoder. Definitely you should not go beyond this limitation. As you not providing any details about your decoder then i strongly recommends https://en.wikipedia.org/wiki/Advanced_Video_Coding?useskin=vector#Levels so you can set encoder to particular level supported by your decoder. By telling to encoder what is your goal i.e. level then it should automatically limit itself to not go beyond level.
    I want the bitrate to be variable, but not exceed a maximum value.
    Quote Quote  
  7. Originally Posted by ProWo View Post
    Use CRF instead of bitrate with x264.
    Start with CRF 18 (visually lossless).
    Smaller values increase the quality, but also the bit rate and file size.
    crf cannot control file size。
    Quote Quote  
  8. Bitrate peaks can be reduced by denoising the video. However, as has been pointed out, the way to go is via the VBV settings.
    Quote Quote  
  9. Member Ennio's Avatar
    Join Date
    May 2005
    Location
    Netherlands
    Search Comp PM
    Originally Posted by moon_light View Post
    I want the bitrate to be variable, but not exceed a maximum value.
    Using the aforementioned --bluray-compat argument will a.o. set a max bitrate and VBV params within blu-ray specs. Where you still can encode in variable bitrate.
    In my experience, with --bluray-compat set, there's still more than enough headroom for high-quality encodes.

    [EDIT]

    I overlooked, sorry. To control filesize, you can use 2-pass encoding (setting average bitrate). In some frontends the filesize can be set.
    For quality, enter --preset <value>. This value has to be set to one of the following phrases, from lowest to highest quality:
    ultrafast - superfast - veryfast - faster - fast - slow - slower - veryslow - placebo (forget this last, encoding time would take forever).
    When the --preset argument is not used, x264 defaults to "medium", which merits lie between fast and slow.

    I hardly use 2-pass anymore. Encoding with crf has my preference eventhough exact size in outcome isn't guaranteed.
    My preferred --preset values are slower and veryslow, but try & find out for yourself.
    Last edited by Ennio; 24th Jan 2024 at 11:01.
    Quote Quote  
  10. Originally Posted by moon_light View Post
    I want the bitrate to be variable, but not exceed a maximum value.
    You need as it was already pointed multiple times guide encoder about your requirements - for example excerpt from one of my ffmpeg scripts:
    Code:
    @SET x264opts="crf=16:vbv_maxrate=19999:vbv_bufsize=9999:level=4.0:qpmin=4:ref=3:cabac=1:tff=1:interlaced=0:fake-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"
    as you see max bitrate is 19999k and vbv buffer size is 9999k (i.e. approx 0.5 second for maximum bitrate - this is quite tight so encoder will be less vbr) - feel free to experiment.
    Quote Quote  



Similar Threads

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