0

我正在使用GPUImage库使用各种过滤器编辑视频。但是当我应用过滤器时,视频会在手机库中存储两次。任何朋友都可以请解决这个视频被创建两次的问题。我使用的代码是

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

控件在完成处理程序中进行两次,而不是一次!!!

4

0 回答 0