Objective c GPUImageMovie中的视频开头有一个红色边框
谢谢你看到这个问题 我从GPUImageMovieComposition和GPUImageWriter创建了一部电影,有时(5%~10%)电影开始时会有红色边框 请告诉我为什么会发生这种现象 我使用AVFileTypeMPEG4作为示例文件类型,但AVFileTypeQuickTimeMovie也一样Objective c GPUImageMovie中的视频开头有一个红色边框,objective-c,video,avfoundation,gpuimage,gpuimagestillcamera,Objective C,Video,Avfoundation,Gpuimage,Gpuimagestillcamera,谢谢你看到这个问题 我从GPUImageMovieComposition和GPUImageWriter创建了一部电影,有时(5%~10%)电影开始时会有红色边框 请告诉我为什么会发生这种现象 我使用AVFileTypeMPEG4作为示例文件类型,但AVFileTypeQuickTimeMovie也一样 _movieFile = [[GPUImageMovieComposition alloc] initWithComposition:composition andVideoComposition
_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];
解决方案
我终于找到了解决问题的方法。。。但不是完美的方式
我修改了-(void)processMovieFrame:(CVPixelBufferRef)具有采样时间的movieFrame:(CMTime)currentSampleTime
在
GPUImageMovie.m
一点点
当设置了currentSampleTime
时,所有红色框都具有currentSampleTime.value==0
因此,当currentSampleTime.value==0时,我避免设置currentSampleTime
下面是我实际使用的一些代码
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];
}
}
for(目标中的id currentTarget)
{
NSInteger indexOfObject=[targets indexOfObject:currentTarget];
NSInteger targetTextReindex=[[targetTextReindices objectAtIndex:indexOfObject]integerValue];
如果(currentSampleTime.value!=0){
[currentTarget NewFrameReadyTime:currentSampleTime atIndex:TargetTextReIndex];
}
}
到目前为止,我找到的唯一解决方案是恢复提交e98cc813b。
我通过使用git对分并在同一个视频上执行批处理测试来解决这个问题。
这个提交已经具备了我的项目所需的所有功能,并且只需要很少的更改就可以使它更加稳定。您可以在此处查看更改:
此外,经过大量测试,我可以说处理本身变得更加稳定,特别是在取消方面。
我想知道在引入所有更改后,视频处理是如何变得不那么可靠和稳定的。在我的例子中,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;
}
此修复程序适用于2014年5月27日至7月1日期间最新版本的GPUImage。谢谢您的评论。已还原的提交创建于2013年9月3日。。。对我来说太老了。我需要更新的提交信息。。。你有别的办法解决吗?