Using GPUImage library for editing video

969 Views Asked by At

I am using GPUImage Library to edit videos using various filters.But when I apply filter the videos are stored twice in the phone library.Any buddy can please sort out this issue of video being created twice. The code i used is

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

The control goes twice in the completion handler instead of going once !!!

0

There are 0 best solutions below