Media (Intel® oneAPI Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK

How to set bit-rates correctly

nematjon_r_
Beginner
275 Views

Hi.

I'm using Intel Media SDK 2014 Directshow filters for encoding (h264 + aac) . 

When i encode 15 fps video , stream size almost twice bigger than 30 fps video.

Am i missing something  ? 

How to set bit-rates correctly ?

Thanks.

 

0 Kudos
7 Replies
Surbhi_M_Intel
Employee
275 Views

Hi,

You can set the frame rate and the bitrate in the default params to the get desired output in the code. Let us know if I have got your question right.

Thanks,
-Surbhi

0 Kudos
nematjon_r_
Beginner
275 Views

Hi .

Thanks for your quick response Surbhi.

My code like that :

        typedef IConfigureVideoEncoder::Params Params;
        Params par;
        ZeroMemory(&par, sizeof(Params));


        par.profile_idc = Params::PF_H264_BASELINE;
        par.level_idc = Params::LL_40;
        par.rc_control.rc_method = Params::RCControl::RC_CBR;

        par.pc_control = Params::PC_FRAME; // frame
        par.frame_control.width =1920;
        par.frame_control.height = 1080;
        // par.throttle_control =  ?

        // RESET_USER_DEFINED(0)
        // PRESET_BALANCED(1)
        // PRESET_BEST_QUALITY(2)
        par.preset = 0;//0

        // MFX_TARGETUSAGE_BEST_QUALITY(1)
        // MFX_TARGETUSAGE_BALANCED(4)
        // MFX_TARGETUSAGE_BEST_SPEED(7)
        par.target_usage =1;
      

      // bitrate (in kilobits per sec)

        par.rc_control.bitrate=1024*4; // 4 Kb/s

       pVideoEncProperty->SetParams(&par); // interface IConfigureVideoEncoder : public IUnknown
       pVideoEncProperty->Release();

 

When i encode 15 fps video , i got  4137 Kbps stream. 

MediaInfo :

Format                           : MPEG-TS
File size                        : 13.9 MiB
Duration                         : 28s 162ms
Overall bit rate                 : 4 137 Kbps

Video
ID                               : 113 (0x71)
Menu ID                          : 1 (0x1)
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : Baseline@L4.0
Format settings, CABAC           : No
Format settings, ReFrames        : 3 frames
Duration                         : 28s 162ms
Width                            : 1 920 pixels
Height                           : 1 080 pixels
Display aspect ratio             : 16/9
Frame rate                       : 15.000 fps
Resolution                       : 24 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive

 

 

And when 30 fps , i got about 2 877 Kbps stream.

MediaInfo :

Format                           : MPEG-TS
File size                        : 9.47 MiB
Duration                         : 27s 616ms
Overall bit rate                 : 2 877 Kbps

Video
ID                               : 113 (0x71)
Menu ID                          : 1 (0x1)
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : Baseline@L4.0
Format settings, CABAC           : No
Format settings, ReFrames        : 3 frames
Duration                         : 27s 616ms
Width                            : 1 920 pixels
Height                           : 1 080 pixels
Display aspect ratio             : 16/9
Frame rate                       : 30.000 fps
Resolution                       : 24 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive

 

Why my bit-rate setting not working when i encode 30 fps video ?

Thanks.

 

0 Kudos
Surbhi_M_Intel
Employee
275 Views

Hi there, 

Thank you for explaining your question better. Now I understand what you mean't when you asked how to set bitrate correctly. 
Can you please check the bitrate instead of Overall bitrate with Media Info tool?
I tried with 1080p yuv and encoded for both 15 and 30fps with the existing sample sample_encode to check if I see the same behavior. And this is what I did - 
sample_encode.exe h264 -i Joy_1080p.yuv" -o out.h264 -w 1920 -h 1080 -b 5000 -f 15 -hw
And the o/p I have got is 5000 Kbps(checked from Media Info) and the file size is 20,742,950 bytes which would be 4978.8Kbps for 15fps Video Same thing I have done for 30fps encode and the output I have got is 5000 Kbps(checked from Media Info) size is 10,594,159 bytes which would be 5087.23 Kbps. In general I believe to check the o/p size to find the bitrate to get the correct bitrate. 

My advice would be to try the existing sample which can be downloaded from here - https://software.intel.com/en-us/media-solutions-portal and check if you can replicate the behavior. If not, then please send us a reproducer code which can replicate the issue you have explained with the input YUV.

Thanks,
-Surbhi

 

0 Kudos
nematjon_r_
Beginner
275 Views

Hi.

I always checking overall bitrate with MediaInfo tool.

What is your output (encoded) duration  on 15 fps and 30 fps? Both of them same duration ?

I think , media info tool calculated overall bit rate based on this formula :

over_bit_rate= 8 * file_size_in_bytes / duration_in_sec ; 

Lets calculate overall bitrates :

15 fps encoded video :

File size                        : 13.9 MiB
Duration                         : 28s 162ms
Overall bit rate                 : 4 137 Kbps

over_bit_rate=8*13.9 * 1024*1024 / 28.162 = 4139507 bits per sec . Almost same bitrate with 4137 Kbps.

 

30 fps encoded video :

File size                        : 9.47 MiB
Duration                         : 27s 616ms
Overall bit rate                 : 2 877 Kbps

over_bit_rate=8*9.47 * 1024*1024 / 27.616 = 2876597 bits per sec . 

 I think , your 15 fps output stream duration is 33 sec , 30 fps video is 16 sec.  So , you are comparing 33 sec video bit-rate and 15 sec video bit-rate.

In my case , durations almost same ( 28.162 sec vs 27.616 sec), not twice difference .

Looks like , when i use higher frame-rate , quality goes down. Other settings are same. 

What is intel media sdk releationship beetwen bit-rate and frame-rate ?

Thanks.

0 Kudos
Surbhi_M_Intel
Employee
275 Views

Hi,

I believe the way you are calculating seems right to me. Yes o/p at 15fps is twice the length as compared to 30fps o/p(expected) 
Can you please reproduce the same result with the existing sample of Media SDK (details in the previous post) or if you can give us a reproducer code which can help us debug  to figure out why we getting same duration o/p. Also please send us your input also.
If you use a higher frame rate, giving same amount of bitrate then it is expected per frame quality would go down. 


Thanks,
-Surbhi

0 Kudos
nematjon_r_
Beginner
275 Views

Hi.

Thanks for your response.

I'm using directshow filters.

I have screen capture filter , which produced rgb32 stream and it is connected to MainConcept ColorConverter filter. ColorConverter filter connected to "Intel® Media SDK H.264 Encoder" . After that Intel Mpeg-2 TS Muxer and FileWriter filter. 

I can control framerate with screen_capture filter. 

Also i set Encoder options like that:

bool SetEncoderParams(IBaseFilter * pVideoEncoder)
{
	IConfigureVideoEncoder * pVideoEncProperty = NULL;
	hr = pVideoEncoder->QueryInterface(IID_IConfigureVideoEncoder, (void **)&pVideoEncProperty);
	if (hr != S_OK || !pVideoEncProperty)
	{
		LogError("QueryInterface:%d", hr);
		return false;
	}

	typedef IConfigureVideoEncoder::Params Params;
	Params par;
	ZeroMemory(&par, sizeof(Params));

	par.profile_idc = Params::PF_H264_BASELINE;
	par.level_idc = Params::LL_4;
	par.rc_control.rc_method = Params::RCControl::RC_CBR;

	// par.ps_control = ?
	par.pc_control = Params::PC_FRAME; 
	par.frame_control.width = 1920;
	par.frame_control.height = 1080;
	// par.throttle_control =  ?

	// RESET_USER_DEFINED(0)
	// PRESET_BALANCED(1)
	// PRESET_BEST_QUALITY(2)
	par.preset = 0;

	// MFX_TARGETUSAGE_BEST_QUALITY(1)
	// MFX_TARGETUSAGE_BALANCED(4)
	// MFX_TARGETUSAGE_BEST_SPEED(7)
	par.target_usage = 1;//4

	// bitrate (in kilobits per sec)
	par.rc_control.bitrate = 1024 * 4000;

	// gop size control 
	par.ps_control.GopRefDist = 2;
	par.ps_control.GopPicSize = 23;

	hr = pVideoEncProperty->SetParams(&par);
	pVideoEncProperty->Release();
	if (hr != S_OK)
	{
		return false;
	}

	return true;
}

 

Maybe i should use another value , instead of  Params::PC_FRAME , when i set par.pc_control ?

How 	par.rc_control.bitrate  works ? Is it per frame bit-rate or stream overal bitrate ?

 

Thanks.

 

0 Kudos
Surbhi_M_Intel
Employee
275 Views

Thanks for sending the info, I feel that adding lot of variants might be causing some issue, so would advice you to just set the bitrate first and not add variants like GopRefDist, GopPicSize, target_usage, preset and etc. Chose Preset to be balance or fast. Please check with default parameters and see if you are seeing the problem. Also can you let us know the i/p you are using. I can check that just on H264 Media SDK encoder to see if I can replicate the behavior. 
Also, can you give us the system analyzer and tracer logs, info about them can be found here - Suggested Format for Forum Questions

Thanks, 
​-Surbhi

 

0 Kudos
Reply