1

我的实现可能有几处问题,但我觉得它已经接近了。

我正在尝试使用 GPUImage 记录相机馈送,并设置一个动态叠加层,在视频录制时每秒更新 30 次(或 60 次)。我希望在录制视频后执行此操作。

在这种情况下,我有一个每秒更新 30 次的像素缓冲区,并且我正在从基地址 ( UnsafeMutablePointer<GLubyte>) 创建一个 GPUImageRawDataInput 对象。使用 GPUImageRawDataInput 对象,我将它的目标设置为“过滤器”变量,它只是一个 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];
4

0 回答 0