GPUImage:将过滤器应用于现有视频文件

时间:2013-05-02 07:15:31

标签: ios gpuimage

我试图使用GPUImage框架的视频过滤器。我按照Filtering and re-encoding a movie教程。它给了我错误Unknown type name GPUImageRotationFilter。所以我试图将一个简单的过滤器应用到我的视频文件

这是我的代码
viewController.h

@interface ViewController : UIViewController<GPUImageMovieWriterDelegate,GPUImageInput>
{
GPUImageMovie *_movieFile;
GPUImageOutput<GPUImageInput> *_sketchFilter;
GPUImageMovieWriter *_movieWriter;

}
 @property (nonatomic,retain)    GPUImageMovie *movieFile; 
 @property (nonatomic,retain)    GPUImageOutput<GPUImageInput> *sketchFilter; 
 @property (nonatomic,retain)    GPUImageMovieWriter *movieWriter;
@end

viewController.m

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"sample_iPod" withExtension:@"m4v"];

self.movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
self.sketchFilter = [[GPUImageSketchFilter alloc] init];
[self.movieFile addTarget:self.sketchFilter];


NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
[self.sketchFilter addTarget:self.movieWriter];

[self.movieWriter startRecording];
[self.movieFile startProcessing];

[self.movieWriter setCompletionBlock:^{

    [self.sketchFilter removeTarget:self.movieWriter];
    [self.movieWriter finishRecording];

}];

这个也给了我 BAD_ACCESS

堆栈跟踪

enter image description here

  1. 我做错了什么?
  2. 可以解释一下如何将GPUImage过滤器应用于现有的视频文件吗?

1 个答案:

答案 0 :(得分:0)

首先使用最新的GPUImageFramework更新您的CGSizeMake(640.0, 480.0)。您可以从here获取新内容。

仔细检查moviewWriter的大小。它应该是CGSizeMake(480.0, 640.0)而不是AVURLAsset *asset = [AVURLAsset URLAssetWithURLNSURL fileURLWithPath:pathToMovie] options:nil]; AVAssetTrack *videoAssetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];

或者您可以创建视频资源,然后在尺寸参数中提供视频资产的大小。

{{1}}

它为我工作。