Thanks for watching this question.
I create a movie from GPUImageMovieComposition and GPUImageWriter, and sometimes (5% ~ 10%) the movie has red frames at the beginning.
Please teach me why this phenomenon occurs.
I use AVFileTypeMPEG4 as a sample file type, but AVFileTypeQuickTimeMovie too.
_movieFile = [[GPUImageMovieComposition alloc] initWithComposition:composition andVideoComposition:videoComposition andAudioMix:nil];
_movieFile.playAtActualSpeed = YES;
_movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:processedMovieURL
size:CGSizeMake(1280.0, 720.0)
fileType:AVFileTypeMPEG4
outputSettings:videoSetting];
_movieWriter.shouldPassthroughAudio = NO;
[_movieWriter setVideoInputReadyCallback:nil];
[_movieWriter setHasAudioTrack:YES audioSettings:audioSetting];
[_movieFile addTarget:_movieWriter];
_movieFile.audioEncodingTarget = _movieWriter;
[_movieFile enableSynchronizedEncodingUsingMovieWriter:_movieWriter];
[_movieWriter startRecording];
[_movieFile startProcessing];
DECISION
Finally, I was able to find a way to solve ... but not an ideal way ...
I modified
- (void)processMovieFrame:(CVPixelBufferRef)movieFrame withSampleTime:(CMTime)currentSampleTime
in a GPUImageMovie.mbit.
When currentSampleTimeinstalled, the entire red frame has currentSampleTime.value == 0
therefore I avoided installation currentSampleTimewhencurrentSampleTime.value == 0
Here are some codes that I actually used.
for (id<GPUImageInput> currentTarget in targets)
{
NSInteger indexOfObject = [targets indexOfObject:currentTarget];
NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue];
if(currentSampleTime.value != 0){
[currentTarget newFrameReadyAtTime:currentSampleTime atIndex:targetTextureIndex];
}
}