6

Aygıtın fotoğraf makinesinden bir film dosyasına AVCaptureMovieFileOutput kullanarak AVFoundation kullanıyorum. Kayıt başlamadan önce kullanıcının yüksek kare hızı ve yüksek çözünürlük modları arasında geçiş yapmasına izin vermek istiyorum, ancak video kayıt için uygun olan en yüksek çözünürlüğü hangi AVCaptureDeviceFormat verdiğini bilmeniz gereken şeyi çözemiyorum. Örneğin Bir dosyaya kaydetmek için en yüksek çözünürlüklü AVCaptureDeviceFormat nasıl bulunur?

, iPod touch Üzerinde test ediyorum, bu arka kamera için aşağıdaki cihaz biçimleri listelenmektedir:

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

en yüksek kare hızını seçme oldukça önemsiz (ve örnek verilmektedir Dökümantasyon); En yüksek kare hızına sahip olanı bulmak için formatlar ve desteklenen kare hızı aralıkları boyunca yinelemeniz yeterlidir. Anlayabildiğim kadarıyla, en yüksek kare hızına sahip format, bir video dosyasına kaydetmek için her zaman kullanılabilir.

En yüksek çözünürlüğe sahip biçimi bulmaya çalıştığımda sorun oluşuyor. Bu durumda 1080p, kaydedebileceğiniz en yüksek değerdir, ancak formatlar 2448p'ye kadar listelenir; Kamera donanımını bu formatta değiştirebilirim ancak 1080p'den yüksek bir dosyaya kayıt yapmayı reddediyor. Tabii ki bunu sadece 1080p kullanacak şekilde kodlayabiliyordum ama şimdi 4K'da kaydı destekleyen cihazlarımız var.

Sorum şu ki, bu listeyi yalnızca kayıt için uygun biçimleri gösterecek şekilde nasıl filtreleyebilirim? AVCaptureDeviceFormat ve CMFormatDescription belgelerine baktım, ancak verilen biçimin kaydedilip kaydedilemeyeceğini gösteren bir şey bulamadım. Ben benzer this question gördüm, ama sürekli isActive kadar doğru formatları arasında geçiş yapmak için kötü bir yol gibi görünüyor.

Hangisinin işe yaradığını görmek için hepsini denemek zorunda kalmadan kullanmak için doğru biçimi bulabilir miyim?

cevap

1

Çoğu durumda AVCaptureSession.sessionPreset ayarının AVCaptureSessionPreset... dan birine ayarlanması yeterlidir. Ön ayarın mevcut cihaz tarafından desteklenip desteklenmediğini kontrol etmek için canSetSessionPreset(preset:) kullanın.

En yüksek çözünürlüğü (genişlik) elde etmek istedim; varyant biraz garip ...

("420 v" karşıt olarak)

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 
} 

Kuşkusuz, " f 420 " alma: bakılmaksızın kare hızı, vb İşte benim çözümdür

Her aygıt AVCaptureDevice.formats için farklı biçimler döndürdüğünden, döndürülen biçimlerin geçerli aygıtta çalıştığını varsayalım. Bazı bilgiler Apple'dan bu technical note'da bulunabilir.

İlgili konular