ios – AVCaptureSession录制视频与音频

ios – AVCaptureSession录制视频与音频,第1张

概述我的应用程序设置为使用AVCaptureSession从相机录制视频,但是没有音频.我需要做什么来录制音频,然后将其添加到该文件的videoOutput?这是我录制视频的代码: AVCaptureSession *session = [[AVCaptureSession alloc] init];[session beginConfiguration];session.sessionPrese 我的应用程序设置为使用AVCaptureSession从相机录制视频,但是没有音频.我需要做什么来录制音频,然后将其添加到该文件的vIDeoOutput?这是我录制视频的代码:
AVCaptureSession *session = [[AVCaptureSession alloc] init];[session beginConfiguration];session.sessionPreset = AVCaptureSessionPresetMedium;CALayer *vIEwLayer = self.vImagePrevIEw.layer;NSLog(@"vIEwLayer = %@",vIEwLayer);AVCaptureVIDeoPrevIEwLayer *captureVIDeoPrevIEwLayer = [[AVCaptureVIDeoPrevIEwLayer alloc] initWithSession:session];captureVIDeoPrevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill;captureVIDeoPrevIEwLayer.frame = self.vImagePrevIEw.bounds;[self.vImagePrevIEw.layer addSublayer:captureVIDeoPrevIEwLayer];AVCaptureDevice *device = [self frontFacingCameraifAvailable];NSError *error = nil;AVCaptureDeviceinput *input = [AVCaptureDeviceinput deviceinputWithDevice:device error:&error];if (!input) {    // Handle the error appropriately.    NSLog(@"ERROR: trying to open camera: %@",error);}NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);Nsstring *documentsDirectoryPath = [paths objectAtIndex:0];AVCaptureMovIEfileOutput *movIEfileOutput = [[AVCaptureMovIEfileOutput alloc] init];Nsstring *archives = [documentsDirectoryPath stringByAppendingPathComponent:@"archives"];Nsstring *outputpathofmovIE = [[archives stringByAppendingPathComponent:@"Test"] stringByAppendingString:@".mp4"];NSURL *outputURL = [[NSURL alloc] initfileURLWithPath:outputpathofmovIE];[session addinput:input];[session addOutput:movIEfileOutput];[session commitConfiguration];[session startRunning];[movIEfileOutput startRecordingToOutputfileURL:outputURL recordingDelegate:self];

我为音频添加了另一个输入,但它不能与后台的mpmovIEplayercontroller一起使用.有什么想法可以播放一个视频,同时记录相机的音频和视频?

解决方法 您尚未包括音频设备:
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];AVCaptureDeviceinput * audioinput = [AVCaptureDeviceinput deviceinputWithDevice:audioDevice error:nil];[session addinput:audioinput]

在beginConfiguration和commitConfiguration之间.它会工作!

总结

以上是内存溢出为你收集整理的ios – AVCaptureSession录制视频与音频全部内容,希望文章能够帮你解决ios – AVCaptureSession录制视频与音频所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1110829.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存