Bitrate is not getting limited for H.264 HW accelerated encode on iOS using the VideoToolbox API

839 Views Asked by At

Bitrate is not getting limited for H.264 HW accelerated encode on iOS using the VideoToolbox API with property kVTCompressionPropertyKey_AverageBitRate.

It is observed that the bitrate is shooting upto 4mbps(for both 1280x780, 640x360) at times for H.264 HW accelerated encode though the encoder's bitrate is configured rightly. This high bitrate value is not in the acceptable limits. *There is a single property for setting bitrate i.e kVTCompressionPropertyKey_AverageBitRate available in the videoToolbox. The documentation says "This is not a hard limit; the bit rate may peak above this".

I have tried below two things : 1. Set bitrate and Set Data rate to some hardcoded values, as a part of encoderSpec attribute of VTCompressionSessionCreate in the init. Removed any re configuring/setting of bitrate after the init. 2. Set bitrate and Set Data rate using VTSessionSetProperty run time

Both does not seem to work.

Is there any way to restrict the bitrate to certain limit ? Any help is greatly appreciated.

1

There are 1 best solutions below

0
On

If you deal with motion scene, 4 Mbps perhaps is a right value. In non-real time situation, I think you should try to configure Profile to High with Level 5, setting H264EntropyMode to CABAC and extend the value of MaxKeyFrameInterval key.