You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to record a video without a quick flash on the screen when starting and stopping the recording? #137
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?
changed the title [-]Is there a way to record a video without it making a quick flash on the screen when starting and stopping the recording?[/-][+]Is there a way to record a video without a quick flash on the screen when starting and stopping the recording?[/+]on Mar 24, 2017
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
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.
We experienced the same issue when we had the camera working but not recording. Once we wanted to record we:
created an instance of MovieOutput
set camera.audioEncodingTarget = movieOutput
started recording via movie.start()
However the initialization processes caused a quick flash, we believe was caused by the setter of the audioEncodingTarget and specifically
removeAudioInputsAndOutputs()
addAudioInputsAndOutputs()
So what we ended up doing is-
camera.delegate = self;
where self implements AudioEncodingTarget and inside the public func processAudioBuffer(_ sampleBuffer:CMSampleBuffer) method we invoke movieOutput.processAudioBuffer(sampleBuffer)
That way the MovieOutput always receives the audio and video buffers and when the recording is started there is no initializations needed
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)")
}
}
}
Activity
[-]Is there a way to record a video without it making a quick flash on the screen when starting and stopping the recording?[/-][+]Is there a way to record a video without a quick flash on the screen when starting and stopping the recording?[/+]garsdle commentedon Apr 13, 2017
Are you trying to make something like this?
patthehuman commentedon Apr 13, 2017
I am getting the same issue when I start recording, the screen flashes. When I stop recording, the screen flashes again.
bevbomb commentedon Apr 19, 2017
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 commentedon May 25, 2017
Would greatly appreciate it if anyone who solved this problem could share their solution.
bevbomb commentedon May 25, 2017
@eliot1019 I couldn't find a fix for this Unfortunately. I had to go back to the original GPUImage
EriFisher commentedon May 25, 2017
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 commentedon May 30, 2017
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. (BradLarson/GPUImage#2410)
I've fix the issue based on @zmzhuai's work and created a PR (#161), maybe you can give it a try?
ivanvelkov commentedon Aug 31, 2017
We experienced the same issue when we had the camera working but not recording. Once we wanted to record we:
However the initialization processes caused a quick flash, we believe was caused by the setter of the audioEncodingTarget and specifically
So what we ended up doing is-
camera.delegate = self;
where self implements AudioEncodingTarget and inside the public func processAudioBuffer(_ sampleBuffer:CMSampleBuffer) method we invoke movieOutput.processAudioBuffer(sampleBuffer)
That way the MovieOutput always receives the audio and video buffers and when the recording is started there is no initializations needed
joshbernfeld commentedon Nov 21, 2017
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.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 = nilafter finishing recording. You can prevent this from happening by commenting outself.removeAudioInputsAndOuputs()in the setter