gpuimage - GPUImageMovieWriter - black frame caused by audioEncodingTarget -
i'm trying record video using gpuimage library. recorded clip ends black frame. know caused audioencodingtarget expensive operation. has been discussed lot, still don't find solution. here code:
gpucamerarecorder class init
videocamera = gpuimagevideocamera(sessionpreset: avcapturesessionpresetiframe960x540, cameraposition: .back) videocamera.outputimageorientation = .landscaperight; videocamera.horizontallymirrorfrontfacingcamera = true filter = gpuimagefilter() videocamera.addtarget(filter) view = gpuimageview(frame: frame) view.fillmode = kgpuimagefillmodepreserveaspectratioandfill moviewriter = gpuimagemoviewriter(movieurl: output, size: view.frame.size) moviewriter?.encodinglivevideo = true filter?.addtarget(moviewriter!) filter?.addtarget(view gpuimageview) videocamera.audioencodingtarget = self.moviewriter! videocamera.startcameracapture()
start recording function
func startrecording(){ println("start recording.") recording = true dispatch_async(dispatch_get_main_queue()) { var res = self.videocamera.addaudioinputsandoutputs() println(res) self.moviewriter!.startrecording() } }
end recording function
func stoprecording(){ println("recording end.") dispatch_async(dispatch_get_main_queue()) { self.filter?.removetarget(self.moviewriter!) self.videocamera.audioencodingtarget = nil self.moviewriter!.finishrecording() self.puttorchoff() self.delegate?.recordingend() println("completed") } }
any suggestion? have find way make work without black frames?
did try ?
inside gpuimagemoviewriter.m add code:
static bool allowwriteaudio = no; - (void)startrecording; { ... allowwriteaudio = no; } - (void)processaudiobuffer:(cmsamplebufferref)audiobuffer; { if (!allowwriteaudio) { return; } ... } - (void)newframereadyattime:(cmtime)frametime atindex:(nsinteger)textureindex; { ... if (![assetwriterpixelbufferinput appendpixelbuffer:pixel_buffer withpresentationtime:frametime]) nslog(@"problem appending pixel buffer @ time: %@", cfbridgingrelease(cmtimecopydescription(kcfallocatordefault, frametime))); allowwriteaudio = yes; //< add ... }
Comments
Post a Comment