我在用着GPUImage在我的应用程序中并尝试过滤视频。实时视频过滤效果良好。当我尝试从文件系统将视频读入内存并使用发布在日落湖软件教程页面和 SimpleVideoFileFilter 演示中。
EDIT:我意识到我原来的帖子可能没有提出足够具体的问题。我要问的是:如何将视频从磁盘读入内存,应用 GPUImageFilter,然后用过滤后的版本覆盖原始视频?
该应用程序因以下错误而崩溃:
-[AVAssetWriter startWriting] Cannot call method when status is 2
状态2是AVAssetWriterStatusCompleted
。我已经看到其他三个都发生了同样的失败AVAssetWriterStatus
es.
我在下面发布了相关代码。
GPUImageFilter *selectedFilter = [self.allFilters objectAtIndex:indexPath.item];
// get the file url I stored when the video was initially captured
NSURL *url = [self.videoURLsByIndexPath objectForKey:self.indexPathForDisplayedImage];
GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:url];
movieFile.runBenchmark = YES;
movieFile.playAtActualSpeed = NO;
[movieFile addTarget:selectedFilter]; // apply the user-selected filter to the file
unlink([url.absoluteString UTF8String]); // delete the file that was at that file URL so it's writeable
// A different movie writer than the one I was using for live video capture.
GPUImageMovieWriter *editingMovieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:url size:CGSizeMake(640.0, 640.0)];
[selectedFilter addTarget:editingMovieWriter];
editingMovieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = editingMovieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:editingMovieWriter];
[editingMovieWriter startRecording];
[movieFile startProcessing]; // Commenting out this line prevents crash
// weak variables to prevent retain cycle
__weak GPUImageMovieWriter *weakWriter = editingMovieWriter;
__weak id weakSelf = self;
[editingMovieWriter setCompletionBlock:^{
[selectedFilter removeTarget:weakWriter];
[weakWriter finishRecording];
[weakSelf savePhotosToLibrary]; // use ALAssetsLibrary to write to camera roll
}];
也许我的问题在于editingMovieWriter 的范围。或者可能是我正在使用与我尝试写入的相同的 URL 初始化 GPUImageMovie 实例。我已经阅读了 GPUImage github 问题页面上的几篇文章、SO 上的几篇相关文章、自述文件以及上面链接的教程。
任何对此问题的见解将不胜感激。谢谢。
这背后至少可能有一件事。在上面的代码中,您没有坚持对您的movieFile
源对象。
如果这是一个启用 ARC 的项目,则该对象将在您完成设置方法后立即被释放(如果不是,您将泄漏该对象)。这将停止电影播放,释放电影本身,并导致黑帧被发送到过滤器管道(其他潜在的不稳定因素)。
你需要做movieFile
一个强引用的实例变量,以确保它挂在这个设置方法之后,因为所有电影处理都是异步的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)