2016-12-12 7 views
2

카메라를 240FPS로 녹화하도록 설정하는 데 문제가있는 것 같지만 어떤 이유로 출력 파일이 30FPS에 불과합니다. 의 ViewController에 AVCameraFileOutput을 설정, 마지막으로AVFileCaptureOutput : 240fps로 녹화하지 않습니다.

class HFRCamera { 
public: 
    HFRCamera(); 

    AVCaptureDeviceInput *camera; 
    AVCaptureDeviceInput *microphone; 
    AVCaptureDevice *videoCam; 
    AVCaptureDevice *audioInput; 
    AVCaptureSession *capSession; 

    void start(); 
    void config(); 
    void stop(); 

}; 

HFRCamera::HFRCamera() { 

    // Set up capture session and add video camera and microphone 
    this->capSession = [[AVCaptureSession alloc] init]; 
    this->videoCam = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    this->config(); 


} 

void HFRCamera::start() { 
    [this->capSession startRunning]; 
} 

void HFRCamera::stop() { 
    [this->capSession stopRunning]; 
} 

void HFRCamera::config() { 

const CGFloat desiredFPS = 240; 
AVCaptureDeviceFormat *selectedFormat = nil; 
AVFrameRateRange *frameRateRange = nil; 
int32_t maxWidth = 0; 

for (AVCaptureDeviceFormat *format in [this->videoCam formats]) { 

    for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) { 

     CMFormatDescriptionRef desc = format.formatDescription; 
     CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(desc); 
     int32_t width = dimensions.width; 

     if (range.minFrameRate <= desiredFPS && desiredFPS <= range.maxFrameRate && width >= maxWidth) { 

      selectedFormat = format; 
      frameRateRange = range; 
      maxWidth = width; 
     } 
    } 
} 

if ([videoCam lockForConfiguration:nil]) { 
    std::cout << "HERE\n"; 
    NSLog(@"selected format:%@", selectedFormat); 
    this->videoCam.activeFormat = selectedFormat; 
    this->videoCam.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS); 
    this->videoCam.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS); 
    [this->videoCam unlockForConfiguration]; 

    NSLog(@"%s AVCaptureDevice: %@", __PRETTY_FUNCTION__, selectedFormat); 
} 



if (this->videoCam) { 
    NSError *err; 
    this->camera = [AVCaptureDeviceInput deviceInputWithDevice:this->videoCam error:&err]; 

    if (!err) { 
     if ([this->capSession canAddInput:this->camera]) 
      [this->capSession addInput:this->camera]; 
     else 
      NSLog(@"Could not add video input."); 
    } else 
     NSLog(@"Could not create video input"); 
} else { 
    NSLog(@"Could not create video capture device."); 
} 

this->audioInput = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; 
NSError *err = nil; 
this->microphone = [AVCaptureDeviceInput deviceInputWithDevice:this->audioInput error:&err]; 
if (this->microphone) 
    [this->capSession addInput:this->microphone]; 

// Configure camera 
[this->capSession setSessionPreset:AVCaptureSessionPresetHigh]; 

} 

을 그리고 : 어디에서 잘못 가고

// Configure the movie file output 
self.movieFile = [[AVCaptureMovieFileOutput alloc] init]; 
self.movieFile.minFreeDiskSpaceLimit = 1024 * 1024; 

CMTime maxDuration = CMTimeMakeWithSeconds(60*60, 240); // 1 hour at 240 fps should be more than enough 
self.movieFile.maxRecordedDuration = maxDuration; 
if ([self.camera.capSession canAddOutput:self.movieFile]) 
    [self.camera.capSession addOutput:self.movieFile]; 

여기

카메라를 설정하는 내 코드 (이 먼저 인스턴스화)입니까?

EDIT : 결과 파일에서 ffprobe의 출력입니다.

Stream #0:0(und): Video: h264 (High) (avc1/0x31637661), yuv420p(tv, bt709), 1920x1080, 15166 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)

그러나 아직이는 activeFormat 가정으로 무엇이다 : 세션 사전 설정 및 장치 형식 :

AVCaptureDevice: <AVCaptureDeviceFormat: 0x17401f780 'vide'/'420f' 1280x 720, { 6-240 fps}, fov:59.680, binned, supports vis, max zoom:65.50 (upscales @1.45), AF System:1, ISO:22.0-704.0, SS:0.000002-0.166667, supports wide color>

답변

0

나는 내 자신의 질문에 대답했다.

미리 설정을 사용하는 것 외에도 카메라 구성을 설정하려면 캡처 세션에 카메라를 추가하고 구성한 다음 캡처 세션을 즉시 시작해야합니다. 반면, 구성하기 전에 캡쳐 세션에 카메라를 추가하는 중이었습니다. 구성을 커밋하지 않는 것 같습니다.

관련 iOS 설명서 : https://developer.apple.com/reference/avfoundation/avcapturedevice/1387810-lockforconfiguration?language=objc

3

크게 호환되지 않는 두, 캡처 세션을 구성하는 방법이 있습니다. 사전 설정은 사전 설정이며 형식은 형식이며 절대로 충족되지 않습니다.

캡처 장치에 setActiveFormat을 지정하면 이전에 설정된 모든 세션 설정에서 제공된 설정보다 우선 적용됩니다 (최소/최대 프레임 기간과 같은 추가 사용자 지정). 이 경우 세션 미리 설정이 AVCaptureSessionPresetInputPriority으로 변경되어 세션 설정이 더 이상 모든 것을 제어하지 않음을 나타냅니다.

장치에서 활성 형식을 설정하고 장치 설정을 추가로 사용자 지정한 후 캡처 세션에서 setSessionPreset을 호출하면 새 사전 설정이 장치 형식 설정을 재정의하거나 취소합니다. 그것이 당신이하는 것처럼 보입니다. 이미 장치 형식을 설정하고 구성 했으므로 세션 미리 설정을 사용하지 않아도됩니다. 구성 기능 끝에 setSessionPreset 호출을 생략하면됩니다. 자세한 내용은


: 나는 장치 포맷 대 세션 사전에 본 최고의 개요 장치 형식의 API가 도입 this video from WWDC13이다. (즉, 비디오 activeFormat 대신 sessionPreset를 통해 구성 할 필요가 높은 FPS/슬로우 모 녹음과 같은 features 많이, 선행에도 불구하고.)

(와우, 나는 동일한 링크 내에서로 대답 할 수있는 두 가지 질문 내 클립 보드에 아직 그런 짧은 시간.)


또한

, 인식하는가에 을 선택이기 때문에, 항상 당신이 원하는 것을 얻지 못할 수도 원하는 형식을 찾기위한 루프 AVCaptureDevice.formats 원하는 fps 및 너비와 일치하는 배열. 예를 들어, 샘플 버퍼를 처리하는지 여부에 따라 420f 또는 420v 형식 중 무엇을 사용하는지 신경 쓸 수 있으며 출력 파일을 사용하여 수행하는 작업에 따라 와이드 컬러 가능 장치 (iPhone 7 및 iPad Pro 9.7-inch와 같은)은 sRGB 또는 P3에서 캡처됩니다. camera features의 전체 목록을보고 여러 기기에서 원하는 것을 얻고 있는지 확인하십시오.

+0

감사합니다. setSessionPreset 호출을 주석 처리했지만 여전히 30FPS의 파일 출력을 얻었습니다. 출력 형식에 대한 귀하의 의견은 240FPS라면 내 목적에 상관 없습니다. – NOP