使用GPUImageVideoCamera和GPUImageMovieWriter ,视频前面一帧有白屏(或者黑屏帧)
主要原因是音频采集会更快。
#import "GPUImageContext.h"
#import "GLProgram.h"
#import "GPUImageFilter.h"
+static BOOL allowWriteAudio = NO;
/////////////////////////////////////////////////////////
- (void)startRecording;
{
+ allowWriteAudio = NO;
alreadyFinishedRecording = NO;
startTime = kCMTimeInvalid;
}
//////////////////////////////////////////////////////////
- (void)finishRecordingWithCompletionHandler:(void (^)(void))handler;
- (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer;
{
+ if (!allowWriteAudio) {
+ return;
+ }
if (!isRecording)
{
return;
////////////////////////////////////////////////////////////////////////////////////
- (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer;
{
if (![assetWriterAudioInput appendSampleBuffer:audioBuffer])
NSLog(@"Problem appending audio buffer at time: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime)));
+ allowWriteAudio = YES;
上述改法可能也有bug,参考另外的改法
参考代码2[self.videoCamera addAudioInputsAndOutputs];
调用GPUImageVideoCamera这句话就可以避免一开始黑屏