首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GPUImage滤波视频

GPUImage滤波视频
EN

Stack Overflow用户
提问于 2014-04-09 20:53:18
回答 1查看 2.7K关注 0票数 13

这是对上一次但仅与question有轻微关联的后续行动。

我正在使用GPUImage库将过滤器应用于相机应用程序中的静止照片和视频。几乎所有的事情都很顺利。还有一个我未能解决的问题是:

  1. 我捕捉到一个GPUImageMovie
  2. 我把它写到文件系统
  3. 我从文件系统中读取并应用了一个新的过滤器。
  4. 我将其写入文件系统中的另一个URL

保存到新URL的是一个具有正确持续时间但没有移动的视频。当我点击播放,这只是一个静止的图像,我认为第一帧的视频。每当我将任何过滤器应用于从文件系统中检索的视频时,都会发生这种情况。应用过滤器实时录制视频效果很好。我的密码在下面。

有人能告诉我,我如何修改它以保存整个原始视频与过滤器应用?

代码语言:javascript
复制
- (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];
            });
        }];
    }];
}
EN

回答 1

Stack Overflow用户

发布于 2014-09-18 16:33:20

我正在为未来的访问者发布这个问题的“答案”。我的代码现在起作用了,但事实是,我不知道是什么原因造成了这种变化。我不想让上面的代码成为任何人的“鲱鱼”。这个问题可能发生在我的代码库的其他地方。但是,我想提到问题中发布的方法与我的工作代码中的方法之间的区别。

  1. 我简化了控制器的结构,因此它一次只处理一个媒体项。不再是videoURLsByIndexPath,我只有self.mediaItem。显然,这使得组织更易于管理。我还怀疑,在电影作者的完成块中为字典添加一个movieURL条目可能与我所看到的意外结果有关。
  2. movieWriter现在是一个强大的财产,而不是一个象牙。这与AFAIK无关,因为ivars默认为强引用。尽管如此,这里发布的内容和我的工作代码之间还是有区别的。
  3. 几乎可以肯定是不相关的,但是我在self.editedMovie.audioEncodingTarget = self.movieWriter周围放了一个if - check来检查[self.mediaItem tracksWithType:AVMediaTypeAudio]的计数是否大于0。
  4. 由于不再需要维护视频URL字典,我只需调用self.mediaItem = [AVURLAsset assetWithURL:movieURL];。我是在电影编剧的完成区外这么做的。

我觉得这不是最有价值的答案,但我希望我在这里提到的各点证明是有用的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22973697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档