Ios 使用AVFoundation录制视频的输出
我正在用AVFoundation录制视频。我正在使用下面的代码Ios 使用AVFoundation录制视频的输出,ios,iphone,objective-c,video,avfoundation,Ios,Iphone,Objective C,Video,Avfoundation,我正在用AVFoundation录制视频。我正在使用下面的代码 -(IBAction)record:(id)sender { AVCaptureSession *session = [[AVCaptureSession alloc] init]; [session setSessionPreset:AVCaptureSessionPresetHigh]; AVCaptureDevice *inputDevice = [AVCaptureDevice
-(IBAction)record:(id)sender
{
AVCaptureSession *session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetHigh];
AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
if ( [session canAddInput:deviceInput] )
[session addInput:deviceInput];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [[self view] layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:CGRectMake(-70, 0, rootLayer.bounds.size.height, rootLayer.bounds.size.height)];
[rootLayer insertSublayer:previewLayer atIndex:0];
[session startRunning];
}
我可以在previewlayer上看到视频,如何将其发送到NSData,以便在录制实况广播时立即将其发送到服务器。您需要创建AVCaptureVideoDataOutput并将其连接到会话,然后实现
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
在这里,sampleBuffer保存帧的数据
再次,我建议您看看RosyWriter示例应用程序,因为它有一个以像素为单位获取帧数据的示例