无法使用 AVCaptureSession 获得任何视频预览
我像这样设置了我的 AVCaptureSession:
AVCaptureSession *newSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *newInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error];
if(error) {
NSLog([error localizedDescription]);
}
AVCaptureMovieFileOutput *newOutput = [[AVCaptureMovieFileOutput alloc] init];
if([newSession canAddInput:newInput])
[newSession addInput:newInput];
if ([newSession canAddOutput:newOutput])
[newSession addOutput:newOutput];
[self setSession:newSession];
[self setInput:newInput];
[self setOutput:newOutput];
然后我向我的视图添加了一个预览层:
AVCaptureVideoPreviewLayer *layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[recorder session]];
[layer setBounds:[recordingView bounds]];
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[[recordingView layer] insertSublayer:layer above:[recordingView layer]];
但我不会得到任何预览。
我使用的是 IOS 5 和第 4 代 iPod Touch。
谢谢。
I set up my AVCaptureSession
like so:
AVCaptureSession *newSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *newInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error];
if(error) {
NSLog([error localizedDescription]);
}
AVCaptureMovieFileOutput *newOutput = [[AVCaptureMovieFileOutput alloc] init];
if([newSession canAddInput:newInput])
[newSession addInput:newInput];
if ([newSession canAddOutput:newOutput])
[newSession addOutput:newOutput];
[self setSession:newSession];
[self setInput:newInput];
[self setOutput:newOutput];
And then I added a preview layer to my view:
AVCaptureVideoPreviewLayer *layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[recorder session]];
[layer setBounds:[recordingView bounds]];
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[[recordingView layer] insertSublayer:layer above:[recordingView layer]];
But I wont get any preview.
I'm on IOS 5 with an iPod Touch 4th Gen.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你的recordingView是如何定义的?
第二,
没有意义。 (您正在尝试在自己的图层内部添加一个图层在自己的图层之上 -> 呃?)
请尝试使用
[recordingView.layer addSublayer:layer];
代替。您在评论中发布的项目使用将弱指针归零。相反,将您的属性标记为强大,一切正常。
First of all, how is your
recordingView
defined?Second,
makes no sense. (you are trying to add a layer above the own layer inside the own layer ->duh?)
Try
[recordingView.layer addSublayer:layer];
instead.Your posted project in the comments uses zeroing weak pointers. mark your properties strong instead and everything works.