BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.88k stars 611 forks source link

Is there a way to record a video without a quick flash on the screen when starting and stopping the recording? #137

Open EriFisher opened 7 years ago

EriFisher commented 7 years ago

Hello, I am making a motion detector app that records when ever motion is detected and stops when no motion is detected. It would be perfect if I didn't have this problem where when ever i record and stop recording the screen flashes, therefore making an infinite loop of recordings unfortunately. However when it is not recording it works perfectly at detecting motion and knows when to record or not. I noticed this flash happening in the video recorder example too. Would anyone know a way to prevent this minor thing from happening?

garsdle commented 7 years ago

Are you trying to make something like this?

patthehuman commented 7 years ago

I am getting the same issue when I start recording, the screen flashes. When I stop recording, the screen flashes again.

bevbomb commented 7 years ago

I've been testing out a basic filter with recording and I'm seeing the same issue, it looks to be a focus issue because at the start of most my test videos I have a low lit dark video which fades back to the normal brightness

eliot1019 commented 7 years ago

Would greatly appreciate it if anyone who solved this problem could share their solution.

bevbomb commented 7 years ago

@eliot1019 I couldn't find a fix for this Unfortunately. I had to go back to the original GPUImage

EriFisher commented 7 years ago

The fix for my motion recording was to use a timer. I think in your situations that don't seem as much motion based, just the flash is on everything is to cut out the beginning of every recording, which I believe you probably can do this losslessly. Just put label on the screen like when you first start recording, "ready" then after one second change it to " Recording" on the screen. That way you let the user know what is usable. I noticed this flash on every swift based camera framework, so it might be something with swift rather than GPUimage2. I also saw the flash on apps like MSQRD.

ShivaHuang commented 7 years ago

Hi @SoundandStuff, what kind of flash do you mean? Some white frames at the beginning and the end? Or black frames?

I found the similar issue which occurred on the old GPUImage, and fortunately @zmzhuai found a solution. (https://github.com/BradLarson/GPUImage/pull/2410)

I've fix the issue based on @zmzhuai's work and created a PR (https://github.com/BradLarson/GPUImage2/pull/161), maybe you can give it a try?

ivanvelkov commented 7 years ago

We experienced the same issue when we had the camera working but not recording. Once we wanted to record we:

joshbernfeld commented 6 years ago

The problem here is that the audio inputs and outputs are being recreated each time you start and stop a video. Going off the SimpleVideoRecorder example, the solution I found was to expose addAudioInputsAndOutputs()on the Camera, and call that function right after you setup your Camera.

do {
    try self.camera?.addAudioInputsAndOutputs()
} catch {
    print("Could not initialize audio inputs and outputs: \(error)")
}

Lastly, the most important thing is to not allow your Camera's audio inputs and outputs to be destroyed when you set self.camera.audioEncodingTarget = nil after finishing recording. You can prevent this from happening by commenting out self.removeAudioInputsAndOuputs() in the setter

public var audioEncodingTarget:AudioEncodingTarget? {
    didSet {
        guard let audioEncodingTarget = audioEncodingTarget else {
            //This line below commented out
            //self.removeAudioInputsAndOutputs()
            return
        }
        do {
            try self.addAudioInputsAndOutputs()
            audioEncodingTarget.activateAudioTrack()
        } catch {
            fatalError("ERROR: Could not connect audio target with error: \(error)")
        }
    }
}