问题
I was trying to use video filters of GPUImage
framework. I followed Filtering and re-encoding a movie tutorial. It giving me error Unknown type name GPUImageRotationFilter
. So i tried to apply a simple filter to my video file
Here is my code
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];
}];
This one also giving me BAD_ACCESS.
Stack trace
- What Iam doing wrong?
- Can any explain me how to apply GPUImage filter to an existing video file?.
回答1:
First of all update your GPUImageFramework
with the latest one. You can get the new one from here.
Double check the size of the moviewWriter. It should be CGSizeMake(640.0, 480.0)
instead of CGSizeMake(480.0, 640.0)
.
Or you can create an video asset and then provide the size of video asset in the size parameter.
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)];
Its working for me.
来源:https://stackoverflow.com/questions/16332390/gpuimage-apply-filer-to-existing-video-file