GPUImageMovie video has a red border at the beginning

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];
       }
   }
+4
2

, GPUImageMovieWriter, , .

, , assetWriter , .

, processAudioBuffer,

if (CMTIME_IS_INVALID(startTime))
{
  runSynchronouslyOnContextQueue(_movieWriterContext, ^{
    if ((audioInputReadyCallback == NULL) && (assetWriter.status != AVAssetWriterStatusWriting))
    {
      [assetWriter startWriting];
    }
    [assetWriter startSessionAtSourceTime:currentSampleTime];
    startTime = currentSampleTime;
  });
}

if (CMTIME_IS_INVALID(startTime))
{
  NSLog(@"0: Had to drop an audio frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime)));
  if (_shouldInvalidateAudioSampleWhenDone)
  {
    CMSampleBufferInvalidate(audioBuffer);
  }
  CFRelease(audioBuffer);
  return;
}

GPUImage 27 01 2014 .

+2

, , , - e98cc813b. , git bisect . , . : https://github.com/crazyjooe/GPUImage.

, , , . , .

+1

Source: https://habr.com/ru/post/1537620/


All Articles