title: How to find the highest resolution AVCaptureDeviceFormat suitable for recording to a file?
body: <p>I'm using AVFoundation to record from the device's camera to a movie file, using <code>AVCaptureMovieFileOutput</code>. I want to allow the user to switch between high frame rate and high resolution modes before recording begins, but I can't work out how you're supposed to know which <code>AVCaptureDeviceFormat</code> yields the highest resolution suitable for video recording.</p>
  
  <p>For example, on the iPod touch I'm testing on, it lists the following device formats for the rear camera:</p>
  
  <pre><code>&lt;AVCaptureDeviceFormat: 0x13108e260 'vide'/'420v'  192x 144, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @17.00), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310911a0 'vide'/'420f'  192x 144, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @17.00), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310afa60 'vide'/'420v'  352x 288, { 2- 30 fps}, HRSI:2992x2448, fov:49.745, max zoom:153.00 (upscales @8.50), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310af9b0 'vide'/'420f'  352x 288, { 2- 30 fps}, HRSI:2992x2448, fov:49.745, max zoom:153.00 (upscales @8.50), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x131092ad0 'vide'/'420v'  480x 360, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @6.80), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x13108f1c0 'vide'/'420f'  480x 360, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @6.80), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310af300 'vide'/'420v'  640x 480, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @5.10), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x131021990 'vide'/'420f'  640x 480, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @5.10), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310ac0f0 'vide'/'420v'  960x 540, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:104.38 (upscales @3.09), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310ac180 'vide'/'420f'  960x 540, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:104.38 (upscales @3.09), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x131091550 'vide'/'420v' 1280x 720, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:95.62 (upscales @2.32), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310ab800 'vide'/'420f' 1280x 720, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:95.62 (upscales @2.32), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x13100a350 'vide'/'420v' 1280x 720, { 3-120 fps}, fov:54.267, binned, supports vis, max zoom:52.12 (upscales @1.16), AF System:1, ISO:24.0-768.0, SS:0.000025-0.333333&gt;
  &lt;AVCaptureDeviceFormat: 0x131090270 'vide'/'420f' 1280x 720, { 3-120 fps}, fov:54.267, binned, supports vis, max zoom:52.12 (upscales @1.16), AF System:1, ISO:24.0-768.0, SS:0.000025-0.333333&gt;
  &lt;AVCaptureDeviceFormat: 0x131021510 'vide'/'420v' 1920x1080, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:95.62 (upscales @1.55), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x1310a2130 'vide'/'420f' 1920x1080, { 2- 30 fps}, HRSI:3264x1836, fov:54.267, supports vis, max zoom:95.62 (upscales @1.55), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x12fe17b90 'vide'/'420v' 2592x1936, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @1.26), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x13108e010 'vide'/'420f' 2592x1936, { 2- 30 fps}, HRSI:3264x2448, fov:54.267, max zoom:153.00 (upscales @1.26), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x12fe17be0 'vide'/'420v' 3264x2448, { 2- 30 fps}, fov:54.267, max zoom:153.00 (upscales @1.00), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  &lt;AVCaptureDeviceFormat: 0x12fe17c40 'vide'/'420f' 3264x2448, { 2- 30 fps}, fov:54.267, max zoom:153.00 (upscales @1.00), AF System:1, ISO:24.0-768.0, SS:0.000024-0.500000&gt;
  </code></pre>
  
  <p>Selecting the highest frame rate is fairly trivial (and an example is given in the documentation); you simply need to iterate through the formats and their supported frame rate ranges to find the one with the highest frame rate. As far as I can tell, the format with the highest frame rate can always be used to record to a video file.</p>
  
  <p>The problem occurs when I try to find the format with the highest resolution. 1080p is, in this case, the highest that you can record to, but formats are listed all the way up to 2448p; I can switch the camera hardware to this format but it refuses to record to a file with anything higher than 1080p. Of course I could hardcode it to only use 1080p, but we have devices which support recording in 4K now.</p>
  
  <p>My question is, how can I filter this list so that it only shows formats suitable for recording? I've looked through the documentation for <code>AVCaptureDeviceFormat</code> and <code>CMFormatDescription</code>, but can't find anything which indicates whether the given format is recordable. I've seen <a href="https://stackoverflow.com/questions/29730957/understand-if-an-avcapturedeviceformat-suits-video-recording">this question</a> which is similar, but constantly switching between formats until <code>isActive</code> is true seems like a bad way of doing it.</p>
  
  <p>Can I find the correct format to use without having to try them all to see which ones work?</p>