Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 29th December 2019, 04:33   #1  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
Libav/ffmpeg transcoding code showing MB rate (125337600) > level limit (2073600)

I'm writing a part of a tutorial of libav/ffmpeg that is focused at the transcoding process.

The code is working but it's showing the, I suppose from x264 lib, message:

Code:
MB rate (125337600) > level limit (983040)
What is it? I tried to setup levels and profile but this yellow message continues to pop up:

Code:
encoder_codec_context->profile = FF_PROFILE_H264_HIGH_422;
encoder_codec_context->level = 51;
leandro is offline   Reply With Quote
Old 29th December 2019, 10:10   #2  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,169
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.
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..
Selur is offline   Reply With Quote
Old 29th December 2019, 13:59   #3  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 526
What resolution and frame rate are you trying to encode? You MB rate number looks like greater than 4K@60fps.
MasterNobody is offline   Reply With Quote
Old 29th December 2019, 14:05   #4  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
Quote:
Originally Posted by Selur View Post
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 is offline   Reply With Quote
Old 29th December 2019, 14:06   #5  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
Quote:
Originally Posted by MasterNobody View Post
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.
leandro is offline   Reply With Quote
Old 29th December 2019, 15:35   #6  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,169
Quote:
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:
Code:
--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/blo.../h264_levels.c or h.264 specs for the base data.

Cu Selur
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..
Selur is offline   Reply With Quote
Old 29th December 2019, 16:05   #7  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
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.

Quote:
+ 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;
leandro is offline   Reply With Quote
Old 29th December 2019, 23:21   #8  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 526
Quote:
Originally Posted by leandro View Post
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.
MasterNobody is offline   Reply With Quote
Old 29th December 2019, 23:48   #9  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
Quote:
Originally Posted by MasterNobody View Post
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.


Quote:
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:

Quote:
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

Last edited by leandro; 30th December 2019 at 00:01.
leandro is offline   Reply With Quote
Old 30th December 2019, 01:22   #10  |  Link
MasterNobody
Registered User
 
Join Date: Jul 2007
Posts: 526
Code:
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:
Code:
MB rate = (width+15)/16 * (height+15)/16 * fr.num /  fr.den
MasterNobody is offline   Reply With Quote
Old 30th December 2019, 01:37   #11  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
Quote:
Originally Posted by MasterNobody View Post
Code:
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:
Code:
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) I wrote a debugger that is showing:

Code:
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: =================================================

Last edited by leandro; 30th December 2019 at 01:45.
leandro is offline   Reply With Quote
Old 30th December 2019, 02:08   #12  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
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.

Code:
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 is offline   Reply With Quote
Old 30th December 2019, 02:18   #13  |  Link
leandro
Registered User
 
Join Date: Feb 2017
Posts: 13
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.

Last edited by leandro; 30th December 2019 at 02:41.
leandro is offline   Reply With Quote
Reply

Tags
ffmpeg, h264, level, libav, profile

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:58.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.