这是对上一次但仅与question有轻微关联的后续行动。
我正在使用GPUImage库将过滤器应用于相机应用程序中的静止照片和视频。几乎所有的事情都很顺利。还有一个我未能解决的问题是:
保存到新URL的是一个具有正确持续时间但没有移动的视频。当我点击播放,这只是一个静止的图像,我认为第一帧的视频。每当我将任何过滤器应用于从文件系统中检索的视频时,都会发生这种情况。应用过滤器实时录制视频效果很好。我的密码在下面。
有人能告诉我,我如何修改它以保存整个原始视频与过滤器应用?
- (void)applyProcessingToVideoAtIndexPath:(NSIndexPath *)indexPath withFilter:(GPUImageFilter *)selectedFilter
{
NSArray *urls = [self.videoURLsByIndexPaths objectForKey:self.indexPathForDisplayedImage];
NSURL *url = [urls lastObject];
self.editedMovie = [[GPUImageMovie alloc] initWithURL:url];
assert(!!self.editedMovie);
[self.editedMovie addTarget:selectedFilter]; // apply the user-selected filter to the file
NSURL *movieURL = [self generatedMovieURL];
// A different movie writer than the one I was using for live video capture.
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 640.0)];
[selectedFilter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
self.editedMovie.audioEncodingTarget = movieWriter;
[self.editedMovie enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[self.editedMovie startProcessing];
__weak GPUImageMovieWriter *weakWriter = movieWriter;
__weak CreateContentViewController *weakSelf = self;
[movieWriter setCompletionBlock:^{
[selectedFilter removeTarget:weakWriter];
[weakWriter finishRecordingWithCompletionHandler:^{
NSArray *urls = [weakSelf.videoURLsByIndexPaths objectForKey:weakSelf.indexPathForDisplayedImage];
urls = [urls arrayByAddingObject:movieURL];
NSMutableDictionary *mutableVideoURLs = [weakSelf.videoURLsByIndexPaths mutableCopy];
[mutableVideoURLs setObject:urls forKey:weakSelf.indexPathForDisplayedImage];
weakSelf.videoURLsByIndexPaths = mutableVideoURLs;
dispatch_sync(dispatch_get_main_queue(), ^{
[self.filmRoll reloadData];
[weakSelf showPlayerLayerForURL:movieURL onTopOfImageView:weakSelf.displayedImageView];
});
}];
}];
}发布于 2014-09-18 16:33:20
我正在为未来的访问者发布这个问题的“答案”。我的代码现在起作用了,但事实是,我不知道是什么原因造成了这种变化。我不想让上面的代码成为任何人的“鲱鱼”。这个问题可能发生在我的代码库的其他地方。但是,我想提到问题中发布的方法与我的工作代码中的方法之间的区别。
self.editedMovie.audioEncodingTarget = self.movieWriter周围放了一个if - check来检查[self.mediaItem tracksWithType:AVMediaTypeAudio]的计数是否大于0。self.mediaItem = [AVURLAsset assetWithURL:movieURL];。我是在电影编剧的完成区外这么做的。我觉得这不是最有价值的答案,但我希望我在这里提到的各点证明是有用的。
https://stackoverflow.com/questions/22973697
复制相似问题