View Full Version : Libav/ffmpeg transcoding code showing MB rate (125337600) > level limit (2073600)
leandro
29th December 2019, 04:33
I'm writing a part of a tutorial of libav/ffmpeg (https://github.com/leandromoreira/ffmpeg-libav-tutorial/pull/52) that is focused at the transcoding process.
The code is working but it's showing the, I suppose from x264 lib, message:
MB rate (125337600) > level limit (983040)
What is it? I tried to setup levels and profile but this yellow message continues to pop up:
encoder_codec_context->profile = FF_PROFILE_H264_HIGH_422;
encoder_codec_context->level = 51;
Selur
29th December 2019, 10:10
Never used libav, but with x264 cli you need to set the vbv restrictions settings properly otherwise level&profile will only be signaled, but not really used.
-> my guess is you also need to properly set the vbv restrictions to avoid the message.
MasterNobody
29th December 2019, 13:59
What resolution and frame rate are you trying to encode? You MB rate number looks like greater than 4K@60fps.
leandro
29th December 2019, 14:05
Never used libav, but with x264 cli you need to set the vbv restrictions settings properly otherwise level&profile will only be signaled, but not really used.
-> my guess is you also need to properly set the vbv restrictions to avoid the message.
Thanks Selur can you post the command line options you use so I can see the API to try to use the same parameters?
leandro
29th December 2019, 14:06
What resolution and frame rate are you trying to encode? You MB rate number looks like greater than 4K@60fps.
I didn't change the resolution and also I'm not wanting to change the frame rate but maybe I need to inform libav about that, I just copied the decoder parameter to the encoder and thought that would work.
Selur
29th December 2019, 15:35
can you post the command line options you use so I can see the API to try to use the same parameters?
for profile High with level 5.1 I would use:
--profile high --level 5.1 --vbv-maxrate 300000--vbv-bufsize 300000
Basis for this is:
level;maxrate
5.2;240000
5.1;240000
5.0;135000
5;135000
4.2;62500
4.1;62500
4.0;25000
4;25000
3.2;20000
3.1;14000
3.0;10000
3;10000
2.2;4000
2.1;4000
2.0;2000
2;2000
1.3;2000
1.2;1000
1.1;500
1b;350
1.0;175
times 1.25 in case high is used.
see also https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/h264_levels.c or h.264 specs for the base data.
Cu Selur
leandro
29th December 2019, 16:05
Thanks, it makes sense. I tried to set manually the rc control but it didn't work, I'll continue researching to see if this is the right way to do it with libav.
+ av_opt_set(encoder_context->codec_context[index]->priv_data, "x264opts", "vbv-maxrate=3000000:vbv-bufsize=3000000:keyint=60:min-keyint=60:scenecut=-1", 0);
+
+ encoder_codec_context->rc_min_rate = 3000000;
+ encoder_codec_context->rc_max_rate = 3000000;
+ encoder_codec_context->rc_buffer_size = 3000000;
+ encoder_codec_context->rc_max_available_vbv_use = 3000000;
+ encoder_codec_context->rc_initial_buffer_occupancy = 3000000;
+
+ encoder_codec_context->profile = FF_PROFILE_H264_HIGH_422;
+ encoder_codec_context->level = 51;
MasterNobody
29th December 2019, 23:21
I didn't change the resolution and also I'm not wanting to change the frame rate but maybe I need to inform libav about that, I just copied the decoder parameter to the encoder and thought that would work.
This doesn't say me anything about which exact resolution and fps was your sample. This warining doesn't have anything todo with VBV and caused by too big or incorrect resolution*fps i.e. context fields: width, height, framerate.num, framerate.den (and time_base.den, time_base.num, ticks_per_frame if framerate field wasn't specified). By bet is that your framerate is not specified (i.e. zero and VFR timebase is used) or incorrect.
leandro
29th December 2019, 23:48
This doesn't say me anything about which exact resolution and fps was your sample. This warining doesn't have anything todo with VBV and caused by too big or incorrect resolution*fps i.e. context fields: width, height, framerate.num, framerate.den (and time_base.den, time_base.num, ticks_per_frame if framerate field wasn't specified). By bet is that your framerate is not specified (i.e. zero and VFR timebase is used) or incorrect.
Ohh sorry I didn't understand at first but now I'm logging what you asked for the input and output using the AVCodecContext as source of the info (https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding-debuging/3_transcoding_gop.c#L46).
input width=1920 height=1080 fr.num=0 fr.den=1 tb.num=0 tb.den=2 ticks=2
output width=1920 height=1080 fr.num=0 fr.den=1 tb.num=1 tb.den=15360 ticks=1
When I compare the timing info obtained from AVStream I get this:
input
LOG: Video
LOG: AVStream->time_base before open coded 1/15360
LOG: AVStream->r_frame_rate before open coded 60/1
LOG: AVStream->start_time 0
LOG: AVStream->duration 153600
output
LOG: Encoder Video
LOG: AVStream->time_base before open coded 1/15360
LOG: AVStream->r_frame_rate before open coded 0/0
LOG: AVStream->start_time -9223372036854775808
LOG: AVStream->duration -9223372036854775808
MasterNobody
30th December 2019, 01:22
MB rate = (width+15)/16 * (height+15)/16 * tb.den / (tb.num * ticks) = (1920+15)/16 * (1080+15)/16 * 15360 / (1 * 1) = 120 * 68 * 15360 = 125337600
So you should specify average fps (or if you source is hybrid CFR than max fps section) in fr.num and fr.den to change it to:
MB rate = (width+15)/16 * (height+15)/16 * fr.num / fr.den
leandro
30th December 2019, 01:37
MB rate = (width+15)/16 * (height+15)/16 * tb.den / (tb.num * ticks) = (1920+15)/16 * (1080+15)/16 * 15360 / (1 * 1) = 120 * 68 * 15360 = 125337600
So you should specify average fps (or if you source is hybrid CFR than max fps section) in fr.num and fr.den to change it to:
MB rate = (width+15)/16 * (height+15)/16 * fr.num / fr.den
Thanks I'm gonna try to set up the encoder avg_framerate, since you point that it could be a timming issue (with your help I build this logging timing specifics (https://github.com/leandromoreira/ffmpeg-libav-tutorial/pull/52/commits/fab644b2525e7652f411fc27966a538518880456)) I wrote a debugger that is showing:
LOG: Video
LOG: =================================================
LOG: decoder
LOG: AVFormatContext
LOG: start_time=0 duration=10022000 bit_rate=2631572 start_time_realtime=0
LOG: AVCodecContext
LOG: bit_rate=2228686 ticks_per_frame=2 width=1920 height=1080 gop_size=12 keyint_min=25 sample_rate=0 profile=100 level=42
LOG: avc->time_base=num/den 0/2
LOG: avc->framerate=num/den 0/1
LOG: avc->pkt_timebase=num/den 0/1
LOG: AVStream
LOG: index=0 start_time=0 duration=153600
LOG: avs->time_base=num/den 1/15360
LOG: avs->sample_aspect_ratio=num/den 1/1
LOG: avs->avg_frame_rate=num/den 60/1
LOG: avs->r_frame_rate=num/den 60/1
LOG: =================================================
LOG: Video
LOG: =================================================
LOG: encoder
LOG: AVFormatContext
LOG: start_time=0 duration=0 bit_rate=0 start_time_realtime=0
LOG: AVCodecContext
LOG: bit_rate=0 ticks_per_frame=1 width=1920 height=1080 gop_size=-1 keyint_min=-1 sample_rate=0 profile=-99 level=-99
LOG: avc->time_base=num/den 1/15360
LOG: avc->framerate=num/den 0/1
LOG: avc->pkt_timebase=num/den 0/1
LOG: AVStream
LOG: index=0 start_time=0 duration=0
LOG: avs->time_base=num/den 1/15360
LOG: avs->sample_aspect_ratio=num/den 0/1
LOG: avs->avg_frame_rate=num/den 0/0
LOG: avs->r_frame_rate=num/den 0/0
LOG: =================================================
LOG: =================================================
LOG: Audio
LOG: =================================================
LOG: decoder
LOG: AVFormatContext
LOG: start_time=0 duration=10022000 bit_rate=2631572 start_time_realtime=0
LOG: AVCodecContext
LOG: bit_rate=393736 ticks_per_frame=1 width=0 height=0 gop_size=0 keyint_min=0 sample_rate=48000 profile=1 level=-99
LOG: avc->time_base=num/den 1/48000
LOG: avc->framerate=num/den 0/1
LOG: avc->pkt_timebase=num/den 0/1
LOG: AVStream
LOG: index=1 start_time=0 duration=480000
LOG: avs->time_base=num/den 1/48000
LOG: avs->sample_aspect_ratio=num/den 0/1
LOG: avs->avg_frame_rate=num/den 0/0
LOG: avs->r_frame_rate=num/den 0/0
LOG: =================================================
LOG: =================================================
LOG: Audio
LOG: =================================================
LOG: encoder
LOG: AVFormatContext
LOG: start_time=0 duration=0 bit_rate=0 start_time_realtime=0
LOG: AVCodecContext
LOG: ->NULL
LOG: AVStream
LOG: index=1 start_time=0 duration=0
LOG: avs->time_base=num/den 0/0
LOG: avs->sample_aspect_ratio=num/den 0/1
LOG: avs->avg_frame_rate=num/den 0/0
LOG: avs->r_frame_rate=num/den 0/0
LOG: =================================================
leandro
30th December 2019, 02:08
Now the encoder AVStream is using the same timing parameters as the decoder but I'm still seeing the messages, I'm gonna try to equalize AVCodecContext next.
LOG: Video
LOG: =================================================
LOG: decoder
LOG: AVFormatContext
LOG: start_time=0 duration=10022000 bit_rate=2631572 start_time_realtime=0
LOG: AVCodecContext
LOG: bit_rate=2228686 ticks_per_frame=2 width=1920 height=1080 gop_size=12 keyint_min=25 sample_rate=0 profile=100 level=42
LOG: avc->time_base=num/den 0/2
LOG: avc->framerate=num/den 0/1
LOG: avc->pkt_timebase=num/den 0/1
LOG: AVStream
LOG: index=0 start_time=0 duration=153600
LOG: avs->time_base=num/den 1/15360
LOG: avs->sample_aspect_ratio=num/den 1/1
LOG: avs->avg_frame_rate=num/den 60/1
LOG: avs->r_frame_rate=num/den 60/1
LOG: =================================================
LOG: Video
LOG: =================================================
LOG: encoder
LOG: AVFormatContext
LOG: start_time=0 duration=0 bit_rate=0 start_time_realtime=0
LOG: AVCodecContext
LOG: bit_rate=0 ticks_per_frame=1 width=1920 height=1080 gop_size=-1 keyint_min=-1 sample_rate=0 profile=-99 level=-99
LOG: avc->time_base=num/den 1/15360
LOG: avc->framerate=num/den 0/1
LOG: avc->pkt_timebase=num/den 0/1
LOG: AVStream
LOG: index=0 start_time=0 duration=153600
LOG: avs->time_base=num/den 1/15360
LOG: avs->sample_aspect_ratio=num/den 1/1
LOG: avs->avg_frame_rate=num/den 60/1
LOG: avs->r_frame_rate=num/den 60/1
LOG: =================================================
leandro
30th December 2019, 02:18
The message MB rate (125337600) > level limit (983040) is gone. I first tried to equalize the timing parameters for AVStream but it didn't solve then I tried to replicate the AVCodecContext from the decoder to the encoder but I couldn't because its tb was `0/2` what I did was to set the AVCodecContext->tb = AVStream->avg_frame_rate it worked but I really didn't understand what I did and I'm not sure if that will cause another problem.
The message forced frame type (5) at 80 was changed to frame type (3) is still showing up but this seems to be a warning expected from the gop conversion.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.