Photo by Thomas William on Unsplash

See update 5 below, for the reason for this issue!

…

One of the highly anticipated features of iOS 11 was support for HEVC (or H.265) encoded video. HEVC brings about ~50% reduction in file sizes from H.264 without a loss in quality. Initial impressions of the new encoder have been good in the included camera app, but there seems to a be a problem with the encoder used by AVAssetWriter when setting the video codec to HEVC.

To see the issue, clone or download my Git repository here. Alternatively, if you have a project that already writes frames to video using another codec, simply replace the AVVideoCodecKey you were using with AVVideoCodecType.hevc (AVVideoCodecHEVC on older versions of Swift) like so:

In comparing files output with the HEVC codec vs H.264, I have seen the files output with HEVC be about three times the size of the files encoded with H.264 while the quality appears to be the same. I have filed a bug with Apple and will update this post when I hear back from them, but, in the meantime, I would recommend not jumping into using HEVC if you need to write frame by frame using AVFoundation.

Update: The issue is still present in iOS 11.0.1 — the file size of the HEVC encoded file is just over three times that of the H.264 encoded one.

Update 2: Still not fixed in iOS 11.0.2

Update 3: Still not fixed in iOS 11.0.3

Update 4: Still not fixed in iOS 11.2

Update 5: According to Brad Ford the problem is that the HEVC encoder defaults to a much higher bitrate (30mbit) than the H.264 one does (5mit). It’s not clear why this is, and this isn’t apparent from the documentation, but more details are needed to understand what bitrate provides a comparable quality with the two different encoders.