GPUImage : Apply filer to existing video file

不问归期 提交于 2020-01-13 18:56:32

问题


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

  1. What Iam doing wrong?
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!