3

我想減慢iPhone 4S上的視頻設備的幀速率,以便didOutputSampleBuffer委託的調用頻率降低。這是爲了提高性能,因爲我處理每個幀,並需要一個大框架的細節。iPhone如何設置幀速率和減速AVCapture didOutputSampleBuffer委託人

我嘗試使用以下方法來做到這一點,當我安裝我的AVSession:

AVCaptureConnection *conn = [self.output connectionWithMediaType:AVMediaTypeVideo]; 
[conn setVideoMinFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 
[conn setVideoMaxFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 

但這並沒有影響,我可以從1更改CAPTURE_FRAMES_PER_SECOND到60,看看在性能上沒有差異或減緩下來視頻拍攝。爲什麼這不起作用?如何減慢視頻設備的捕獲幀速率?

設置我的會話使用下面的代碼:

// Define the devices and the session and the settings 
self.session = [[AVCaptureSession alloc] init]; 

//self.session.sessionPreset = AVCaptureSessionPresetPhoto; 
//self.session.sessionPreset = AVCaptureSessionPresetHigh; 
self.session.sessionPreset = AVCaptureSessionPreset1280x720; 

self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil]; 

// Add the video frame output 
self.output = [[AVCaptureVideoDataOutput alloc] init]; 
[self.output setAlwaysDiscardsLateVideoFrames:YES]; 
self.output.videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] 
                 forKey:(id)kCVPixelBufferPixelFormatTypeKey]; 

// A dispatch queue to get frames 
dispatch_queue_t queue; 
queue = dispatch_queue_create("frame_queue", NULL); 

// Setup the frame rate  
AVCaptureConnection *conn = [self.output connectionWithMediaType:AVMediaTypeVideo]; 
[conn setVideoMinFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 
[conn setVideoMaxFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 

// Setup input and output and set the delegate to self 
[self.output setSampleBufferDelegate:self queue:queue]; 
[self.session addInput:self.input]; 
[self.session addOutput:self.output]; 

// Start the session 
[self.session startRunning]; 

我捕捉使用「didOutputSampleBuffer」委託下面的實施框架:

// The delegate method where we get our image data frames from 
- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 

    // Extract a UImage 
    CVPixelBufferRef pixel_buffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
    CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixel_buffer]; 

    // Capture the image 
    CGImageRef ref = [self.context createCGImage:ciImage fromRect:ciImage.extent]; 

    // This sets the captured image orientation correctly 
    UIImage *image = [UIImage imageWithCGImage:ref scale:1.0 orientation:UIImageOrientationLeft]; 

    // Release the CGImage 
    CGImageRelease(ref); 

    // Update the UI on the main thread but throttle the processing 
    [self performSelectorOnMainThread:@selector(updateUIWithCapturedImageAndProcessWithImage:) withObject:image waitUntilDone:YES]; 

} 

回答

1

我不知道是什麼的iOS您正在運行,但括號你這樣的代碼:

AVCaptureConnection *conn = [self.output connectionWithMediaType:AVMediaTypeVideo]; 
if ([conn isVideoMaxFrameDurationSupported] && [conn isVideoMinFrameDurationSupported]) 
{ 
    [conn setVideoMinFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 
    [conn setVideoMaxFrameDuration:CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND)]; 
} 

else 
    NSLog(@"Setting Max and/or Min frame duration is unsupported"; 

然後再從那裏。我懷疑它在您的iOS上不受支持。

+0

太好了。如果這有效,請將其標記爲正確答案。謝謝 – Spectravideo328 2013-02-25 17:37:08

1

這是一個局部的答案:我認爲, iOS 5和iOS 6之間的Quicktime視頻捕捉引擎發生了變化。在iOS 5中,可以以60 FPS捕捉視頻,並且有些應用程序利用此功能以平滑慢動作錄製回放(例如SloPro應用程序)。在iOS 6中,使用相同的方法不再可能達到60 FPS。有關於這個問題在加拿大家園論壇線程長時間的討論:

Will jailbreak of iPhone 4S, iOS 6.1, allow recording of 60 FPS video?

希望你能在那裏找到一些信息,可能會提供一個解決您的問題。如果有人能夠再次進行這項工作,我會非常感興趣。我想念記錄在60 FPS ...