Questions about H.264 encoding settings with low-latency rate control

Hi everyone,

I noticed that Apple recently added a few new beta sample codes related to video encoding:

Encoding video for low-latency conferencing Encoding video for live streaming

While experimenting with H.264 encoding, I came across some questions regarding certain configurations:

When I enable kVTVideoEncoderSpecification_EnableLowLatencyRateControl, is it still possible to use kVTCompressionPropertyKey_VariableBitRate? In my tests, I get an error.

It also seems that kVTVideoEncoderSpecification_EnableLowLatencyRateControl cannot be used together with kVTCompressionPropertyKey_ConstantBitRate when encoding H264. Is that expected?

When using kVTCompressionPropertyKey_ConstantBitRate with kVTCompressionPropertyKey_MaxKeyFrameInterval set to 2, the encoder outputs only keyframes, and the frame size keeps increasing, which doesn’t seem like the intended behavior.

Regarding the following code from the sample:

let byteLimit = (Double(bitrate) / 8) * 1.5 as CFNumber
let secLimit = Double(1.0) as CFNumber
let limitsArray = [ byteLimit, secLimit ] as CFArray // Each 1 second limit byte as bitrate
err = VTSessionSetProperty(session, key: kVTCompressionPropertyKey_DataRateLimits, value: limitsArray)

This DataRateLimits setting doesn’t seem to have any effect in my tests. Whether I set it or not, the values remain unchanged.

Since the documentation on developer.apple.com/documentation doesn’t clearly explain these cases, I’d like to ask if anyone has insights or recommendations about the proper usage of these settings.

Thanks in advance!

Hello @tim_yao_18,

When I enable kVTVideoEncoderSpecification_EnableLowLatencyRateControl, is it still possible to use kVTCompressionPropertyKey_VariableBitRate? In my tests, I get an error.

That error is expected. The documentation for kVTCompressionPropertyKey_VariableBitRate states that it is not compatible with VTVideoEncoderSpecification_EnableLowLatencyRateControl.

It also seems that kVTVideoEncoderSpecification_EnableLowLatencyRateControl cannot be used together with kVTCompressionPropertyKey_ConstantBitRate when encoding H264. Is that expected?

What error are you receiving when you attempt this? kVTCompressionPropertyKey_ConstantBitRate is documented as not being supported in all operating modes.

This DataRateLimits setting doesn’t seem to have any effect in my tests. Whether I set it or not, the values remain unchanged.

Are you saying that it has no effect in the sample code you linked to, or in a separate project you have?

--Greg

Hi Greg,

I found it will run without error even if VBR: using kVTVideoEncoderSpecification_EnableLowLatencyRateControl with:

VTSessionSetProperties(compressionSession, propertyDictionary: [kVTCompressionPropertyKey_ConstantBitRate: bitrate] as CFDictionary)

And it will get error -12900 if set kVTVideoEncoderSpecification_EnableLowLatencyRateControl with:

VTSessionSetProperty(compressionSession, key: kVTCompressionPropertyKey_ConstantBitRate, value: bitrate as CFNumber)

Are you saying that it has no effect in the sample code you linked to, or in a separate project you have?

I tried the sample code, and the first several frames were too large and exceeded the size limit. But the following frames seem okay, close to the data rate limit.

For low latency live streaming, would you recommend using ABR rather than CBR?

Questions about H.264 encoding settings with low-latency rate control
 
 
Q