【问题标题】:Output from video recording with AVFoundation使用 AVFoundation 录制视频的输出
【发布时间】:2014-02-12 23:54:11
【问题描述】:

我正在使用 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];

 }

我可以在我的预览层上看到视频,如何将其制作到 NSData,以便我可以在录制直播时将其即时发送到服务器。

【问题讨论】:

    标签: ios iphone objective-c video avfoundation


    【解决方案1】:

    您需要创建一个AVCaptureVideoDataOutput 并将其连接到您的会话,然后实施

    - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
    

    这里sampleBuffer里面保存着frame的数据

    再次,我建议您查看 RosyWriter 示例应用程序,因为它有一个以像素为单位获取帧数据的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      相关资源
      最近更新 更多