我试图通过 iphone 录制一个延时视频。我已经得到了它的慢动作(通过捕获最大帧可能),与 120 fps。
现在我试图扭转逻辑来捕获最少的帧可能,以实现超时功能。
代码流是这样的:
从 CaptureDevice 的可用设备格式中查询所有支持的帧范围。
检查帧速率是否低于或等于所需的 20 fps,并且尺寸是否等于或大于 1920 * 1080。
所有工作正常,除了,当我按下记录,我得到"CaptureMovieFileOutput - no active/enabled connections"
异常。我只使用提供的帧速率和范围之一,为什么我得到这个异常?
所有的作品为 30 fps。
#define kTimelapseRequiredFPS = 20
#define kMinRequiredDimensions (1920*1080)
- (void)configureCameraForSlowMoRecording:(CaptureDevice *)currentCaptureDevice
{
[_captureSession beginConfiguration];
CaptureDeviceFormat *bestFormat = nil;
FrameRateRange *bestFrameRateRange = nil;
for ( CaptureDeviceFormat *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 ( FrameRateRange *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 fps 的帧速率和范围的日志:
Format: <CaptureDeviceFormat: 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: <FrameRateRange: 0x176556d0 1 - 20>
Format: <CaptureDeviceFormat: 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: <FrameRateRange: 0x1750db10 1 - 20>
Format: <CaptureDeviceFormat: 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: <FrameRateRange: 0x1750dc80 1 - 20>
Format: <CaptureDeviceFormat: 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: <FrameRateRange: 0x1751a260 1 - 20>

不知道这是否解决了,但我正在努力使慢动作工作,并不断得到"CaptureMovieFileOutput - no active/enabled connections"
(所以我真的不知道你是如何得到它的工作:D)。
确保在设置activeFormat
之前设置了一些预设。原来 iOS 不会自动处理其他东西。我所做的是在将activeFormat
设置为 120fps 之前设置CaptureSession.Preset.hd1280x720
。
完成上述操作后,我开始得到Error Domain=FoundationErrorDomain Code=-11803 "Cannot Record" UserInfo=0x152e60 {NSLocalizedRecoverySuggestion=Try recording again., ErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Record}
。我找不到任何可能的原因-连接很好,会话正在运行。所以我再次按下记录按钮,它开始记录 (哇,真的吗?只是字面上的“再试一次”?) 我猜 iOS 只是有点脾气,不得不考虑更长一点的时间来记录。所以我添加了一个递归函数给movieFileOutput
一些时间来记录
fileprivate func startRecording(to moviePath: URL) {
sessionQueue.async {
self.movieFileOutput.startRecording(to: moviePath, recordingDelegate: self)
if self.movieFileOutput.isRecording {
self.sessionQueue.asyncAfter(deadline: .now() + self.duration) {
self.stopRecording()
}
} else {
self.startRecording(to: moviePath)
}
}
}
希望它会有所帮助(或者其他像我一样偶然发现这个线程的人。)
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(79条)