我正在使用AV Foundation來處理來自攝像機(iPhone 4s,iOS 6.1.2)的幀。我正在根據AV Foundation編程指南設置AVCaptureSession,AVCaptureDeviceInput,AVCaptureVideoDataOutput。一切都按預期工作,我可以在captureOutput:didOutputSampleBuffer:fromConnection:
代表中接收幀。AV Foundation:AVCaptureVideoPreviewLayer和幀持續時間
我也有這樣設置的預覽層:
AVCaptureVideoPreviewLayer *videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
[videoPreviewLayer setFrame:self.view.bounds];
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer insertSublayer:videoPreviewLayer atIndex:0];
事情是,我不需要每秒30幀的幀我處理,我不能夠處理他們這麼快呢。所以我使用此代碼來限制幀持續時間:
// videoOutput is AVCaptureVideoDataOutput set earlier
AVCaptureConnection *conn = [videoOutput connectionWithMediaType:AVMediaTypeVideo];
[conn setVideoMinFrameDuration:CMTimeMake(1, 10)];
[conn setVideoMaxFrameDuration:CMTimeMake(1, 2)];
這工作得很好,並限制由captureOutput代表收到的幀。
但是,這也限制了預覽圖層上的每秒幀數,預覽視頻變得無法響應。
我從文檔中瞭解到,幀持續時間是在連接上獨立設置的,預覽層的確有不同的AVCaptureConnection。在[videoPreviewLayer connection]
上檢查混合/最大幀持續時間顯示它確實設置爲默認值(1/30和1/24),並且不同於連接AVCaptureVideoDataOutput時設置的持續時間。
那麼,是否有可能僅限於幀捕捉輸出限制幀持續時間,並且仍然在預覽視頻上看到1/24-1/30幀持續時間?怎麼樣?
謝謝。
「這並不容易。」誇張的 – aleclarson 2014-05-30 20:34:42
嗨@Wildaker你能幫忙解釋一下幀持續時間以及在這個問題中使用不同值的含義嗎?謝謝! http://stackoverflow.com/questions/34937008/exporting-videos-on-ios-understanding-and-setting-frame-duration-property – Crashalot 2016-01-22 00:36:21
對不起,但沒有試驗,我真的不能說,@Crashalot。這不是我所做的。 – Wildaker 2016-01-23 09:36:11