h264 encoder with wrong frame order

I use VideoToolbox HW h.264 encoder with M1 MacBook for screen mirroring. I need run encoder with minimal delay mode.

I use these values as encoderSpecification kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder:true kVTCompressionPropertyKey_ProfileLevel:kVTProfileLevel_H264_Baseline_AutoLevel kVTCompressionPropertyKey_RealTime:true kVTCompressionPropertyKey_AllowFrameReordering:false

I set presentation timestamp with current time. In compressed callback, I got encoded frame with wrong order.

[13.930533]encode pts=...13.930511 [13.997633]encode pts=...13.997617 [14.013678]compress callback with pts=...13.997617 dts=...13.930511 [14.023443]compress callback with pts=...13.930511 dts=...13.997617

in[]:log time, pts:presentation timestamp, dts:decode timestamp

AllowFrameReordering is not working as I expected. If I need to set other property, please let me know.

I also does not like buffering 2 video frames. If you know settings for no buffering frame, please let me know.

Presentation time stamp order on encode() : 0 1 2 3 4 5 DidCompress callback order : 1 0 3 2 5 4

I pass setting by encoderSpec dictionary wrong way with value:false. I need to use kCFBooleanFalse.

Better way is calling VTSessionSetProperty and check status.

status = VTSessionSetProperty(vtCompressionSession, key: kVTCompressionPropertyKey_AllowFrameReordering, value: kCFBooleanFalse)

h264 encoder with wrong frame order
 
 
Q