2

iOS에서 비디오를 녹화하는 더 간단한 방법은 AVCaptureSession.sessionPreset으로 설정하는 것입니다.미리 설정을 사용하지 않고 iOS에 비디오를 녹화하려면 어떻게해야합니까?

하지만 binning, stabilization (cinematic, standard, none) 및 ISO와 같은 매개 변수를 제어하고 싶으므로 저에게는 효과가 없습니다.

내가 원하는 형식을 찾아 activeFormat에 할당하지만 녹화를 시작하려고 할 때, 나는 오류 얻을 :

let device = AVCaptureDevice.defaultDevice(
    withDeviceType: .builtInWideAngleCamera, 
    mediaType: AVMediaTypeVideo, 
    position: .back)! 
let session = AVCaptureSession() 
session.addInput(try! AVCaptureDeviceInput(device: device)) 
output = AVCaptureMovieFileOutput() 
session.addOutput(output) 
device.setFormatWithHighestIso() 
session.startRunning() 

setFormatWithHighestIso() 다음은

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'*** -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] No active/enabled connections' 

내 초기화 코드를

extension AVCaptureDevice { 
    var goodVideoFormats: [AVCaptureDeviceFormat] { 
    return (formats as! [AVCaptureDeviceFormat]) 
     .filter { CMFormatDescriptionGetMediaSubType($0.formatDescription) != 875704422 } // 420f 
     .filter { $0.autoFocusSystem == .phaseDetection } 
    } 

    func setFormatWithHighestIso() { 
    let format = goodVideoFormats 
     .filter { $0.maxISO > 1759 } 
     .filter { $0.height < 1937 } 
     .first! 

    try! lockForConfiguration() 
    defer { unlockForConfiguration() } 
    activeFormat = format 
    NSLog("\(format)") 
    } 
} 

마지막 로그 문은 다음을 생성합니다.

<AVCaptureDeviceFormat: 0x1702027d0 'vide'/'420f' 2592x1936, { 3- 30 fps}, HRSI:4032x3024, fov:58.986, max zoom:189.00 (upscales @1.56), AF System:2, ISO:22.0-1760.0, SS:0.000005-0.333333, supports wide color> 

이것은 실제로 원하는 형식이므로 setFormatWithHighestIso()은 예상대로 작동합니다. Apple reference을 참조하십시오.


다른 어떤 일들이 내가 시도 :

  • 대신 420f로의 420V를 사용하여 == 875704422에 = 변경!를.
  • 카메라를 사진 모드에서 시작하는 대신 비디오 모드에서 시작한 다음 AVCapturePhotoOutput을 제거하고 AVCaptureMovieFileOutput을 추가하여 비디오 모드로 변경하십시오.
  • AVCaptureConnection이 활성화되어 있는지 확인하십시오.
  • 연결이 활성화되어 있는지 확인하지만, 그렇지 않은 :

    내버려 CONN = output.connection을 (withMediaType : AVMediaTypeVideo)!

을 (conn.isActive)를 확인 나는 또한 다른 AVCaptureDeviceFormats를 사용하여 시도, 그들은 작동 :

extension AVCaptureDevice { 
    func setFormatWithCinematicVS() { 
    let format = goodVideoFormats 
     .filter { $0.isVideoStabilizationModeSupported(.cinematic) } 
     .filter { $0.height == 720 } 
     .first! 

    try! lockForConfiguration() 
    defer { unlockForConfiguration() } 
    activeFormat = format 
    } 

    func setFormatWithStandardVS() { 
    let format = goodVideoFormats 
     .filter { $0.isVideoStabilizationModeSupported(.standard) } 
     .filter { $0.height == 540 } 
     .first! 

    try! lockForConfiguration() 
    defer { unlockForConfiguration() } 
    activeFormat = format 
    } 
} 

그것은 작동하지 않습니다 가장 높은 ISO 만 형식입니다. 이 형식의 특별한 점은 무엇입니까?

AVCaptureConnection을 수동으로 만들어야합니까? 그러나 이미 연결되어 있습니다. 그것은 단지 활동적이지 않습니다.

iOS 10.3.3을 실행하는 iPhone 7 Plus에 있습니다. 세션을 사용하지 않고 activeFormat을 설정하여 비디오를 특정 형식으로 기록하는 방법은 무엇입니까?

activeFormat에 할당하는 대신 sessionPreset을 사용하면 비디오를 성공적으로 기록합니다.


이 오류 메시지의 이야기 다른 질문이 있습니다,하지만 난 특별히 사전 설정을 사용하지 않고 비디오를 캡처해야하기 때문에이 그들 속는 사람이 아니다.

+0

나는 이걸 시험해보고 싶지만 7+이 없다. 다른 모델에는 유사한 오류가 없다. 오류 메시지를 추가 할 수 있습니까? 그리고 실행 가능한 재연에 대한 링크일까요? –

+0

질문에 오류가 있습니다. 실행 가능한 복제본을 만들려고 노력할 것입니다. 그러나 그 동안 어떤 장치가 있습니까? 나는 어떤 형식으로 복제하려고하는지 말해 줄거야. –

+0

나는 6s를 가지고있다 - 그 일할 것인가? –

답변

0

솔루션에 세션에 추가하기 전에 AVCaptureDevice를 구성하는 것으로 나타났습니다. 대신에 :

session.addInput(try! AVCaptureDeviceInput(device: device)) 
output = AVCaptureMovieFileOutput() 
session.addOutput(output) 
device.setFormatWithHighestIso() 

당신은 어떻게해야 : 장치가 세션에 추가됩니다

device.setFormatWithHighestIso() // Do this first! 
session.addInput(try! AVCaptureDeviceInput(device: device)) 
output = AVCaptureMovieFileOutput() 
session.addOutput(output) 

는 AVCaptureConnection가 생성되고 어떤 방식으로 구성되어있다. 나중에 장치의 해상도를 변경하면 구성이 더 이상 일치하지 않으므로 연결이 비활성화되고 비디오가 녹화되지 않습니다.

관련 문제