1

There could be several things wrong with my implementation, but I feel like it’s close.

I'm trying to record the camera feed using GPUImage, as well as set a dynamic overlay that updates 30 (or 60) times per second onto the video while it's recording. I don't want this to be done after the video has been recorded.

I have a pixel buffer that is updated 30 times a second in this case, and I'm creating a GPUImageRawDataInput object from the base address (UnsafeMutablePointer<GLubyte>). With the GPUImageRawDataInput object, I'm setting it's target to the 'filter' variable, which is just a GPUImageFilter(). I'm not sure if this is the correct way to set it up.

Currently the video it’s recording is just the camera feed, there’s no overlay.

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];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mary211534
  • 11
  • 1

0 Answers0