SpaceDog SpaceDog - 2 months ago 20
iOS Question

Capturing video on iOS: what is the difference between capturing video using AVMovieFileOutput or AVAssetWriter?

I am following this tutorial on how to capture video on iOS.

When you download their sample code and run it, it shows two methods of capturing video, using

and using

What is the technical difference between the two methods? is one better than the other?


Both AVMovieFileOutput and AVAssetWriter (in conjunction with AVCaptureVideoDataOutput) allow you to capture media samples to files, but AVAssetWriter is the lower level and more configurable* of the two interfaces, so with AVAssetWriter / AVCaptureVideoDataOutput you can intercept and modify media samples before they are written which allows you to apply effects, and stream off the device, etc.

Last time I checked you couldn't add both AVMovieFileOutput and AVCaptureVideoDataOutput to an iOS capture session, so as soon as you want to examine and record the data flowing through the session in real time, you have no choice but to use AVAssetWriter / AVCaptureVideoDataOutput.

*in fact AVMovieFileOutput is probably implemented using AVAssetWriter.