3

我试图使用GPUImage框架的视频过滤器。我遵循过滤和重新编码电影教程。它给了我错误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

视图控制器.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

堆栈跟踪

在此处输入图像描述

  1. 我在做什么错?
  2. 谁能解释一下如何将 GPUImage 过滤器应用于现有的视频文件?
4

1 回答 1

0

首先GPUImageFramework用最新的更新你的。你可以从这里得到新的。

仔细检查moviewWriter 的大小。它应该CGSizeMake(640.0, 480.0)代替CGSizeMake(480.0, 640.0).

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

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)];

它为我工作。

于 2014-06-12T06:38:22.300 回答