【问题标题】:Quickblox video chat savingQuickblox 视频聊天保存
【发布时间】:2014-08-29 09:10:33
【问题描述】:

我正在使用QuickBlox iOS SDK 在我的应用程序中进行视频聊天。它工作正常。现在我想录制聊天视频并将其保存在相机胶卷中。我怎样才能做到这一点。 我已经浏览了他们的文档并实现了这一点 -

 -(IBAction)record:(id)sender{


   // Create video Chat
   videoChat = [[QBChat instance] createAndRegisterVideoChatInstance];
   [videoChat setIsUseCustomVideoChatCaptureSession:YES];

   // Create capture session
    captureSession = [[AVCaptureSession alloc] init];

   // ... setup capture session here

   /*We create a serial queue to handle the processing of our frames*/
   dispatch_queue_t callbackQueue= dispatch_queue_create("cameraQueue", NULL);
  [videoCaptureOutput setSampleBufferDelegate:self queue:callbackQueue];

  /*We start the capture*/
  [captureSession startRunning];
   }

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

  // Do something with samples
  // ...

  // forward video samples to SDK
  [videoChat processVideoChatCaptureVideoSample:sampleBuffer];
 }

但我不知道从这里做什么。 如何获取视频数据?

【问题讨论】:

    标签: ios objective-c video chat quickblox


    【解决方案1】:

    来自 quickblox docs

    要设置自定义视频捕获会话,您只需按照以下步骤操作:

    创建一个 AVCaptureSession 的实例 设置输入和输出 实现帧回调并将所有帧转发到 QuickBlox iOS SDK 告诉 QuickBlox SDK 您将使用自己的捕获会话

    要设置自定义视频捕获会话,设置输入和输出:

    -(void) setupVideoCapture{
    self.captureSession = [[AVCaptureSession alloc] init];
    
    __block NSError *error = nil;
    
    // set preset
    [self.captureSession setSessionPreset:AVCaptureSessionPresetLow];
    
    
    // Setup the Video input
    AVCaptureDevice *videoDevice = [self frontFacingCamera];
    //
    AVCaptureDeviceInput *captureVideoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
    if(error){
        QBDLogEx(@"deviceInputWithDevice Video error: %@", error);
    }else{
        if ([self.captureSession  canAddInput:captureVideoInput]){
            [self.captureSession addInput:captureVideoInput];
        }else{
            QBDLogEx(@"cantAddInput Video");
        }
    }
    
    // Setup Video output
    AVCaptureVideoDataOutput *videoCaptureOutput = [[AVCaptureVideoDataOutput alloc] init];
    videoCaptureOutput.alwaysDiscardsLateVideoFrames = YES;
    //
    // Set the video output to store frame in BGRA (It is supposed to be faster)
    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
    [videoCaptureOutput setVideoSettings:videoSettings];
    /*And we create a capture session*/
    if([self.captureSession canAddOutput:videoCaptureOutput]){
        [self.captureSession addOutput:videoCaptureOutput];
    }else{
        QBDLogEx(@"cantAddOutput");
    }
    [videoCaptureOutput release];
    
    
    // set FPS
    int framesPerSecond = 3;
    AVCaptureConnection *conn = [videoCaptureOutput connectionWithMediaType:AVMediaTypeVideo];
    if (conn.isVideoMinFrameDurationSupported){
        conn.videoMinFrameDuration = CMTimeMake(1, framesPerSecond);
    }
    if (conn.isVideoMaxFrameDurationSupported){
        conn.videoMaxFrameDuration = CMTimeMake(1, framesPerSecond);
    }
    
    /*We create a serial queue to handle the processing of our frames*/
    dispatch_queue_t callbackQueue= dispatch_queue_create("cameraQueue", NULL);
    [videoCaptureOutput setSampleBufferDelegate:self queue:callbackQueue];
    dispatch_release(callbackQueue);
    
    // Add preview layer
    AVCaptureVideoPreviewLayer *prewLayer = [[[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession] autorelease];
    [prewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    CGRect layerRect = [[myVideoView layer] bounds];
    [prewLayer setBounds:layerRect];
    [prewLayer setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
    myVideoView.hidden = NO;
    [myVideoView.layer addSublayer:prewLayer];
    
    
    /*We start the capture*/
    [self.captureSession startRunning];
    }
    
    - (AVCaptureDevice *) cameraWithPosition:(AVCaptureDevicePosition) position{
        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
        for (AVCaptureDevice *device in devices) {
            if ([device position] == position) {
                return device;
            }
        }
        return nil;
    }
    
    
    - (AVCaptureDevice *) backFacingCamera{
        return [self cameraWithPosition:AVCaptureDevicePositionBack];
    }
    
    - (AVCaptureDevice *) frontFacingCamera{
        return [self cameraWithPosition:AVCaptureDevicePositionFront];
    }
    

    实现帧回调:

    - (void)captureOutput:(AVCaptureOutput *)captureOutput  didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    
        // Usually we just forward camera frames to QuickBlox SDK
        // But we also can do something with them before, for example - apply some video filters or so  
        [self.videoChat processVideoChatCaptureVideoSample:sampleBuffer];
    }
    

    告诉 QuickBlox iOS SDK 我们使用自己的视频捕获会话:

    self.videoChat = [[QBChat instance] createAndRegisterVideoChatInstance];
    self.videoChat.viewToRenderOpponentVideoStream = opponentVideoView;
    //
    // we use own video capture session
    self.videoChat.isUseCustomVideoChatCaptureSession = YES;
    

    【讨论】:

    • 您好,感谢您的回答。您能解释一下如何将这些视频数据保存在相机胶卷中吗?
    • @SplatterStrikes 这会捕获视频并使您能够播放它。您能否通过将其添加到“卷”来澄清您的意思?
    • 我的意思是点击一个按钮,我想将此视频保存在 iPhone 画廊中。
    • No no..从上面的代码我在哪里可以找到最终的视频数据?它还会捕捉声音吗?
    • @SplatterStrikes 它将录制声音。之后,您可以使用 Content 模块将文件上传到存储。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多