High Frame Rate Video Format And Codec

I want to find out which AVCaptureDevice.Format are compatible with what AVVideoCodecType, so to enable or disable possible configurations in the app's UI. As of today, for example, 1080p @ 240 is not compatible with h264, nor is 4K@60. But, I know this because Apple's Camera configuration explains it so in the options to choose between "High Efficiency" and "Most Compatible".


What is the sanctioned way to determine if a certain video format can be used with a certain codec?. The way I am thinking about is a bit convoluted. To find the video codecs compatible with a video format I need to:


- Create and configure a AVCaptureSession

- Add a AVCaptureVideoDataOutput to the video session

- Set the AVCaptureDeviceInput's device active format.

- Query the AVCaptureVideoDataOutput availableVideoCodecTypesForAssetWriter to obtain the supported codecs (h264, hevc, ...).


On the iPhone 11, the wide angle alone camera supports 17 420f video formats. Do I need to loop through all of them in order to obtain the supported codecs (set active format, query for each) or is there a better way?


Thanks!

Accepted Reply

You're on the right track. Here's the most efficient way:

- Create AVCaptureSession.

- Add AVCaptureDeviceInput for the camera you care about.

- Add AVCaptureMovieFileOutput.

- For each AVCaptureDeviceFormat in deviceInput.device.formats

- set format as deviceInput.device.activeFormat (remember to lock device for configuration first, then unlock afterwards)

- query the movie file output's availableVideoCodecTypes property.

Replies

You're on the right track. Here's the most efficient way:

- Create AVCaptureSession.

- Add AVCaptureDeviceInput for the camera you care about.

- Add AVCaptureMovieFileOutput.

- For each AVCaptureDeviceFormat in deviceInput.device.formats

- set format as deviceInput.device.activeFormat (remember to lock device for configuration first, then unlock afterwards)

- query the movie file output's availableVideoCodecTypes property.

I am using AVCaptureVideoDataOutput because I use an AVAssetWriter instead of AVCaptureMovieFileOutput, for the added flexibility.


Thank you, Brad.