我正在使用GPUImage Library使用各种过滤器编辑视频。但是当我应用过滤器时,视频会在手机库中存储两次。任何好友都可以将这个问题视为两次创建。 我使用的代码是
movieFile=[[GPUImageMovie alloc]initWithURL:tempUrl];
// movieFile.runBenchmark = YES;
// movieFile.playAtActualSpeed = YES;
[movieFile addTarget:_filter];
NSURL *url = tempUrl;
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetTrack *videoAssetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGAffineTransform videoTransform = videoAssetTrack.preferredTransform;
//Getting path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"MovieVideo-%d.mov",arc4random() % 1000]];
NSURL *movieURL = [NSURL fileURLWithPath:myPathDocs];
_movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURLsize:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];
[_filter addTarget:_movieWriter];
_movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = _movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:_movieWriter];
[_movieWriter startRecordingInOrientation:videoTransform];
[movieFile startProcessing];
__unsafe_unretained typeof(self) weakSelf = self;
[_movieWriter setCompletionBlock:^{
[weakSelf.filter removeTarget:weakSelf.movieWriter];
[self.movieWriter finishRecording];
[weakSelf exportDidFinish:movieURL];
}];
控件在完成处理程序中运行两次而不是一次!!!