使用Camera Feed的GPUImageRawDataInput

时间:2017-11-07 18:51:46

标签: ios swift gpuimage cvpixelbuffer

我的实施可能有几个问题,但我觉得它很接近。

我正在尝试使用GPUImage录制相机Feed,并设置动态叠加层,每秒更新30(或60)次视频,同时录制。 希望在录制视频后完成此操作。

我有一个像素缓冲区,在这种情况下每秒更新30次,我正在从基地址(UnsafeMutablePointer<GLubyte>)创建一个GPUImageRawDataInput对象。使用GPUImageRawDataInput对象,我将它的目标设置为'filter'变量,它只是一个GPUImageFilter()。我不确定这是否是正确的设置方式。

目前它录制的视频只是相机输入,没有叠加。

func setupRecording() {
    movieWriter = GPUImageMovieWriter(movieURL: fileURL(), size: self.view.frame.size)
    movieWriter?.encodingLiveVideo = true

    videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSession.Preset.hd1920x1080.rawValue, cameraPosition: .back)
    videoCamera?.outputImageOrientation = .portrait
    videoCamera?.horizontallyMirrorFrontFacingCamera = true
    videoCamera?.horizontallyMirrorRearFacingCamera = false

    let userCameraView = gpuImageView
    userCameraView?.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;

    //filter's declaration up top - let filter = GPUImageFilter()
    videoCamera?.addTarget(filter)
    videoCamera?.audioEncodingTarget = movieWriter;
    filter.addTarget(userCameraView)

    filter.addTarget(movieWriter)
    videoCamera?.startCapture()
}

func shouldUpdateRawInput(_ data: UnsafeMutablePointer<GLubyte>!) {//updated 30x per second
    if let rawDataInput = rawDataInput {
        rawDataInput.updateData(fromBytes: data, size: self.view.frame.size)
        rawDataInput.processData()
    } else {
        //first time creating it
        rawDataInput = GPUImageRawDataInput(bytes: data, size: self.view.frame.size, pixelFormat: GPUPixelFormatBGRA)
        rawDataInput?.processData()
        rawDataInput?.addTarget(filter)
    }
}



//----------------------------------------
//this is my conversion of the pixel buffer to the GLubyte in another file

CVPixelBufferLockBaseAddress(pixelBuf, 0);
GLubyte* rawDataBytes=(GLubyte*)CVPixelBufferGetBaseAddress(pixelBuf);
[_delegate shouldUpdateRawInput:rawDataBytes];

0 个答案:

没有答案