Sample code that capture and encode video into HEVC (or H.264) with AVFoundation and VideoToolbox. The code is in Swift 4 and tested on XCode 9.2 / iOS 11.2.1 / iPhone X.
Based on tomisacat's VideoToolboxCompression project.
Brief instructions:
- Build and run on iPhone 7/7 Plus or up. Touch Click Me to begin recording. Touch again to finish.
- Download the result to Mac: XCode -> Window -> Devices and Simulators -> Select app and click the "gear" icon below -> Download Container.
- Among the container files,
tmp/temp.h265
is the raw HEVC data file. - Add a container around the file:
mp4box -add temp.h265 temp.h265.mp4
- Use QuickTime or VLC to play the mp4 file.
- For comparison, you could change
H265
tofalse
inViewController.swift
to do H.264 instead of HEVC encoding.