我想寫一個相機應用程序,使用iPhone的相機錄製視頻,但我找不到改變錄製視頻幀率的方法。例如,我想以每秒25幀而不是默認值30錄製。如何在iPhone上錄製視頻時設置幀速率?
是否可以以任何方式設置此幀速率,如果是,如何?
我想寫一個相機應用程序,使用iPhone的相機錄製視頻,但我找不到改變錄製視頻幀率的方法。例如,我想以每秒25幀而不是默認值30錄製。如何在iPhone上錄製視頻時設置幀速率?
是否可以以任何方式設置此幀速率,如果是,如何?
據我所知,您不能設置FPS進行錄製。查看AVFoundation的WWDC 2010視頻。這似乎表明,只要我可以說,只能用於捕獲幀數據。
我很想被證明是錯誤的,但我敢肯定,你不能。抱歉!
您可以使用AVCaptureConnection的videoMaxFrameDuration和videoMinFrameDuration屬性。見http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureConnection_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009522
此外,還有一個問題,SO,解決這個(具有良好的代碼示例): I want to throttle video capture frame rate in AVCapture framework
您需要AVCaptureDevice.h
這裏在這裏工作代碼:
- (void)attemptToConfigureFPS
{
NSError *error;
if (![self lockForConfiguration:&error]) {
NSLog(@"Could not lock device %@ for configuration: %@", self, error);
return;
}
AVCaptureDeviceFormat *format = self.activeFormat;
double epsilon = 0.00000001;
int desiredFrameRate = 30;
for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
NSLog(@"Pre Minimum frame rate: %f Max = %f", range.minFrameRate, range.maxFrameRate);
if (range.minFrameRate <= (desiredFrameRate + epsilon) &&
range.maxFrameRate >= (desiredFrameRate - epsilon)) {
NSLog(@"Setting Frame Rate.");
self.activeVideoMaxFrameDuration = (CMTime){
.value = 1,
.timescale = desiredFrameRate,
.flags = kCMTimeFlags_Valid,
.epoch = 0,
};
self.activeVideoMinFrameDuration = (CMTime){
.value = 1,
.timescale = desiredFrameRate,
.flags = kCMTimeFlags_Valid,
.epoch = 0,
};
// self.activeVideoMinFrameDuration = self.activeVideoMaxFrameDuration;
// NSLog(@"Post Minimum frame rate: %f Max = %f", range.minFrameRate, range.maxFrameRate);
break;
}
}
[self unlockForConfiguration];
// Audit the changes
for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
NSLog(@"Post Minimum frame rate: %f Max = %f", range.minFrameRate, range.maxFrameRate);
}
}
這太爛了:(這裏歐羅巴我們不想記錄30幀/秒,所以我想改變它到25 :(流血蘋果 – Tammo 2010-12-19 22:49:31
你絕對可以改變記錄的FPS。下面的代碼。 – Praxiteles 2015-07-14 22:31:45
https://github.com/shu223/SlowMotionVideoRecorder – 2015-07-28 12:00:20