gpt4 book ai didi

ios - startRecordingToOutputFileURL 没有事件/启用的连接 ios

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:13 25 4
gpt4 key购买 nike

我想录制一个短片(30 秒),应该在 30 秒后自动停止。我使用 AVCAPTURESESSION 启动了相机,现在我想开始自动录制视频。

这是我的代码:

AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
[session addInput:input];

AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
newCaptureVideoPreviewLayer.frame = self.view.bounds;

[self.view.layer addSublayer:newCaptureVideoPreviewLayer];

[session startRunning];

如何录制 30 秒的视频。

我的尝试:

NSString *documentsDirPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSURL *documentsDirUrl = [NSURL fileURLWithPath:documentsDirPath isDirectory:YES];
NSURL *url = [NSURL URLWithString:@"out.mp4" relativeToURL:documentsDirUrl];
[self.movieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self];



- (AVCaptureMovieFileOutput *)movieFileOutput {
AVCaptureMovieFileOutput *_movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if (!_movieFileOutput) {
_movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];

Float64 TotalSeconds = 30; //Total seconds
int32_t preferredTimeScale = 30; //Frames per second
CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);
_movieFileOutput.maxRecordedDuration = maxDuration;
_movieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;
}

return _movieFileOutput;
}

但它给我错误,[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 没有事件/启用的连接。'

如何录制 30 秒的视频剪辑。

最佳答案

我找到了这个错误的原因。检查你session的“setSessionPreset”设置,照片的分辨率设置与视频不同,对于iPhone5,后置摄像头的视频分辨率为1920*1080,前置摄像头为1280*720,照片的最大分辨率为3264*2488,所以如果你将错误解决方案设置为视频,连接将不会被激活。

关于ios - startRecordingToOutputFileURL 没有事件/启用的连接 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com