iOS: AVPlayer recording
This guide applies to all frameworks that create or generate iOS applications.
Support for recording video from AVPlayerLayer
or camera preview via AVCaptureVideoPreviewLayer
is not currently available.
Symptoms
- When user plays video with
AVPlayer
in layer or inAVPlayerViewController
, the video is not recorded and the background (video content) is black. - All camera previews are black (without content).
Technical reasons
Both layers use low-level API that serves data to these layers via pixel buffers. Graphic data from AVFoundation
are processed directly on-device GPU with hardware support, not in Core Graphics
framework like other GUI parts. For us are these low-level layers inaccessible.
AVPlayer
recording failure is obviously an architectural problem that has not been solved by Apple for a long time. Their ownReplayKit
framework behaves exactly the same, and Apple itself points this out in the documentation.In general, using the camera preview does not mean that the recording is not working. For example, in
ARKit
we do not have problems because internally usesMetalKit
.
Recommendations
Camera preview
Do not use AVCaptureVideoPreviewLayer
to render the data from the device camera. Instead, use MTKView
(MetalKit
) to preview the camera. Such a solution works, and it does not seem to have any performance impacts.
More details and sample implementation
Video playback
We don't have any recommended solution yet.
Updated almost 3 years ago