AVAssetWriter Fails at iPhone X Resolution w/ h.264 but NOT w/ h.265

I'm using an AVAssetWriter to write realtime video, appending the stream of

CMSampleBufferRef
s.


One of my chosen output resolutions is 1376 x 2436 (for the iPhone X, adding some width so it meets a 1.77 aspect ratio).


Weird thing is... when I output it as HEVC, everything is great. But if I elect for h.264 (as only iPhone 7 onward can produce HEVC, yet someone on an iPhone 5s could be talking to someone on an iPhone X), the write fails.


Error Domain = AVFoundationErrorDomain Code = -11800 "The operation could not be completed" 
UserInfo = {
     NSLocalizedFailureReason=An unknown error occurred (-12902), 
     NSLocalizedDescription = The operation could not be completed, 
     NSUnderlyingError = 0x1c424b550 {
        Error Domain=NSOSStatusErrorDomain Code=-12902 "(null)"
     }
}


the h.264 settings work for all other output resolutions: 640x1136, 750x1334 and 1080x1920


h.264 output settings:

@{ AVVideoCodecKey:AVVideoCodecH264, 
   AVVideoWidthKey:@(mediaSize.width), 
   AVVideoHeightKey:@(mediaSize.height), 
   AVVideoCompressionPropertiesKey: @{ 
      AVVideoAverageBitRateKey: @4500000, 
      AVVideoAllowFrameReorderingKey:@NO, 
      AVVideoProfileLevelKey: AVVideoProfileLevelH264High41, 
      AVVideoH264EntropyModeKey:AVVideoH264EntropyModeCABAC, 
      AVVideoExpectedSourceFrameRateKey: @(30) 
   } 
};


hevc output settings:

@{ AVVideoCodecKey:AVVideoCodecTypeHEVC, 
   AVVideoWidthKey:@(mediaSize.width), 
   AVVideoHeightKey:@(mediaSize.height), 
   AVVideoCompressionPropertiesKey:@{ 
      AVVideoProfileLevelKey : (__bridge NSString *)kVTProfileLevel_HEVC_Main_AutoLevel, 
      AVVideoAverageBitRateKey: @4500000, 
      AVVideoAllowFrameReorderingKey:@NO, 
      AVVideoExpectedSourceFrameRateKey: @(30) 
   } 
};

Same here! Let me know if you find something out.

The hardware h.264/hevc encoders have a resolution limit. I don't know if there is a documentation on it, but usually it's the same as the max resolution the camera app can record video.

ya that's the conclusion I arrived that -> some imposed restriction that's undocumented. I just stuck with 1920x1080 h264 for that cirumstance!

AVAssetWriter Fails at iPhone X Resolution w/ h.264 but NOT w/ h.265
 
 
Q