6

Ich benutze AVFoundation, um von der Kamera des Geräts in eine Filmdatei aufzunehmen, mit AVCaptureMovieFileOutput. Ich möchte dem Benutzer erlauben, zwischen hoher Bildrate und hoher Auflösung zu wechseln, bevor die Aufnahme beginnt, aber ich kann nicht herausfinden, wie Sie wissen sollen, welche AVCaptureDeviceFormat die höchste Auflösung ergibt, die für Videoaufnahmen geeignet ist.Wie findet man das AVCaptureDeviceFormat mit der höchsten Auflösung, das für die Aufnahme in eine Datei geeignet ist?

Zum Beispiel auf dem iPod touch Ich teste auf, es sind die folgenden Geräteformate für die Rückfahrkamera:

<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 
<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> 

die höchste Framerate Auswahl ist ziemlich trivial (und ein Beispiel gegeben in die Dokumentation); Sie müssen lediglich die Formate und ihre unterstützten Bildratenbereiche durchlaufen, um die mit der höchsten Bildrate zu finden. Soweit ich das beurteilen kann, kann immer das Format mit der höchsten Bildrate für die Aufnahme in eine Videodatei verwendet werden.

Das Problem tritt auf, wenn ich versuche, das Format mit der höchsten Auflösung zu finden. 1080p ist in diesem Fall der höchste, auf den Sie aufnehmen können, aber Formate werden bis zu 2448p aufgelistet; Ich kann die Kamera-Hardware auf dieses Format umstellen, aber sie weigert sich, eine Datei mit etwas höher als 1080p aufzunehmen. Natürlich könnte ich es hart codieren, um nur 1080p zu verwenden, aber wir haben Geräte, die Aufnahme in 4K jetzt unterstützen.

Meine Frage ist, wie kann ich diese Liste filtern, so dass es nur für die Aufnahme geeignete Formate zeigt? Ich habe die Dokumentation für AVCaptureDeviceFormat und CMFormatDescription durchgesehen, kann aber nichts finden, das angibt, ob das angegebene Format beschreibbar ist. Ich habe this question gesehen, die ähnlich ist, aber ständig zwischen Formaten zu wechseln, bis isActive wahr ist, scheint eine schlechte Art, es zu tun.

Kann ich das richtige Format finden, ohne sie alle ausprobieren zu müssen, um zu sehen, welche funktionieren?

Antwort

1

In den meisten Fällen sollte die Einstellung AVCaptureSession.sessionPreset zu einem von AVCaptureSessionPreset... ausreichen. Verwenden Sie canSetSessionPreset(preset:), um zu überprüfen, ob das Preset vom aktuellen Gerät unterstützt wird.

Ich wollte die höchstmögliche Auflösung (Breite) erreichen; unabhängig von Frame-Rate usw. Hier ist meine Lösung:

captureSession.sessionPreset = AVCaptureSessionPresetInputPriority // Required for the "activeFormat" of the device to be used 
let highresFormat = (device.formats as! [AVCaptureDeviceFormat]) 
    .filter { CMFormatDescriptionGetMediaSubType($0.formatDescription) == 875704422 } // Full range 420f 
    .maxElement { a, b in CMVideoFormatDescriptionGetDimensions(a.formatDescription).width < CMVideoFormatDescriptionGetDimensions(b.formatDescription).width } 
if let format = highresFormat { 
    device.activeFormat = format 
} 

Zugegeben, die "420 f" immer ein bisschen seltsam ist Variante (im Gegensatz zu "420 v" gegen) ...

Da jedes Gerät verschiedene Formate für AVCaptureDevice.formats zurückgeben würde ich annehmen, dass alle zurückgegebenen Formate auf dem aktuellen Gerät funktionieren. Einige Informationen finden Sie in diesem technical note von Apple.

Verwandte Themen