3

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

enter image description here

  1. What Iam doing wrong?
  2. Can any explain me how to apply GPUImage filter to an existing video file?.
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
  • Your code looks fine. Where are you getting the EXC_BAD_ACCESS? How did you define movieFile, sketchFilter and movieWriter? The GPUImageRotationFilter is an old filter which isn't available anymore, you should be using the GPUImageTransformFilter instead. – Tomas Camin May 02 '13 at 10:07
  • @TomasCamin I cant figure out where iam getting bad access. See my updated question – Anil Varghese May 02 '13 at 10:28
  • Does your project use ARC? What iOS version are you targeting? – Tomas Camin May 02 '13 at 10:37
  • Iam not using ARC. Deployment target ios6.0 – Anil Varghese May 02 '13 at 10:49
  • 1
    First, that post of mine you're referring to above was simply the original Readme.md for the GPUImage project, which is well out of date at this point. Follow the Readme instructions from GitHub for the latest way to set this up. Second, use the SimpleVideoFileFilter example as a basis. Your code above should work fine, and does in that sample application on my test device with the latest version of the framework. – Brad Larson May 03 '13 at 17:38

1 Answers1

0

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.

Mayur Shrivas
  • 199
  • 1
  • 13