2

Use-case:

I'm trying to encode a video stream in real-time with VideoToolbox hardware encoder for video streaming.

Issue:

The VTCompressionOutputCallback is being called only after 2 or more frames have been passed to the encoder. The last sent frame is stored in the encoder buffer and gets emitted only after the next frame comes in. This behavior causes the 1 frame delay on the decoder side and thus there is no real-time streaming. I checked various encoder properties: kVTCompressionPropertyKey_RealTime, kVTCompressionPropertyKey_MaxFrameDelayCount, kVTCompressionPropertyKey_MoreFramesAfterEnd, but none of them seems to fix the problem. I am also aware of the CompleteFrames function but calling it after each frame forces encoder to emit keyframes only.

Question:

Is there a possibility to reduce the internal encoder frame buffer size to 0 and set the encoder to operate in a 1-in-1-out manner?

My default encoder settings:

EnableHardwareAcceleratedVideoEncoder = true
MoreFramesAfterEnd = false
MoreFramesBeforeStart = false
Profile = H264_Baseline_AutoLevel    
FrameReordering = false
RealTime = true
MaxFrameDelayCount = 0

Thanks

Tomek Gos
  • 41
  • 3
  • Anyone meet the problem with ending session hanging when calling VTCompressionSessionInvalidate under Big Sur? About your question, not sure if it could satisfy your goal if calling VTCompressionSessionCompleteFrames every time after you fed a frame. – Steven Nov 12 '20 at 23:21
  • Hey Steven. I'm testing VTC on Big Sur, but I don't face hanging on VTCompressionSessionInvalidate. Hope that you figured it out. Calling VTCompressionSessionCompleteFrames is not really useful. After every call encoder emits an I-frame (keyframe) and this is not the way the h.264 encoder should work. – Tomek Gos Jan 15 '21 at 09:50

0 Answers0