Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用AVFoundation录制视频的输出_Ios_Iphone_Objective C_Video_Avfoundation - Fatal编程技术网

Ios 使用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

我正在用AVFoundation录制视频。我正在使用下面的代码

  -(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示例应用程序,因为它有一个以像素为单位获取帧数据的示例