如何使用AVCaptureDeviceFormat从iPhone录制timelapsevideo?

我试图通过iPhone录制一个timelapsevideo。 我已经得到它慢动作的工作(通过捕捉最大帧可能),120帧/秒。

现在我正试图颠倒逻辑来捕捉尽可能less的帧,以实现timelapsefunction。

代码stream是这样的:

  1. 从AVCaptureDevice的可用设备格式查询所有支持的帧范围。

  2. 检查帧速率是否低于或等于所需的20 fps,尺寸等于或大于1920 * 1080。

所有工作正常,除了当我按下logging,我得到"AVCaptureMovieFileOutput - no active/enabled connections"例外。 我只使用提供的帧速率和范围之一,为什么我得到这个exception?

所有的效果为30帧/秒。

  #define kTimelapseRequiredFPS = 20 #define kMinRequiredDimensions (1920*1080) - (void)configureCameraForSlowMoRecording:(AVCaptureDevice *)currentCaptureDevice { [_captureSession beginConfiguration]; AVCaptureDeviceFormat *bestFormat = nil; AVFrameRateRange *bestFrameRateRange = nil; for ( AVCaptureDeviceFormat *format in [currentCaptureDevice formats] ) { //NSLog(@"Format: %@", format); CMFormatDescriptionRef videoInfo = [format formatDescription]; double videoWidth = CMVideoFormatDescriptionGetDimensions(videoInfo).width; double videoHeight = CMVideoFormatDescriptionGetDimensions(videoInfo).height; double dimensions = videoWidth * videoHeight; for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) { //NSLog(@"Range: %@", range); if ((range.maxFrameRate <= kTimelapseRequiredFPS) && (dimensions >= kMinRequiredDimensions)) { bestFormat = format; bestFrameRateRange = range; } } } if ( bestFormat ) { NSLog(@"Final format: %@, Final range %@", bestFormat, bestFrameRateRange); if ( [currentCaptureDevice lockForConfiguration:NULL] == YES ) { currentCaptureDevice.activeFormat = bestFormat; currentCaptureDevice.activeVideoMinFrameDuration = bestFrameRateRange.minFrameDuration; currentCaptureDevice.activeVideoMaxFrameDuration = bestFrameRateRange.minFrameDuration; [currentCaptureDevice unlockForConfiguration]; } } [_captureSession commitConfiguration]; } 

这里是20帧的帧速率和范围的日志:

 Format: <AVCaptureDeviceFormat: 0x1765f7a0 'vide'/'420v' 2592x1936, { 1- 20 fps}, fov:56.700, max zoom:153.00 (upscales @1.26), AF System:1, ISO:46.0-736.0, SS:0.000018-1.000000> Range: <AVFrameRateRange: 0x176556d0 1 - 20> Format: <AVCaptureDeviceFormat: 0x1765f750 'vide'/'420f' 2592x1936, { 1- 20 fps}, fov:56.700, max zoom:153.00 (upscales @1.26), AF System:1, ISO:46.0-736.0, SS:0.000018-1.000000> Range: <AVFrameRateRange: 0x1750db10 1 - 20> Format: <AVCaptureDeviceFormat: 0x1765f740 'vide'/'420v' 3264x2448, { 1- 20 fps}, fov:56.700, max zoom:153.00 (upscales @1.00), AF System:1, ISO:46.0-736.0, SS:0.000018-1.000000> Range: <AVFrameRateRange: 0x1750dc80 1 - 20> Format: <AVCaptureDeviceFormat: 0x1765f6f0 'vide'/'420f' 3264x2448, { 1- 20 fps}, fov:56.700, max zoom:153.00 (upscales @1.00), AF System:1, ISO:46.0-736.0, SS:0.000018-1.000000> Range: <AVFrameRateRange: 0x1751a260 1 - 20>