0

GPUImage ライブラリを使用して、さまざまなフィルターを使用して動画を編集しています。しかし、フィルターを適用すると、動画が携帯電話のライブラリに 2 回保存されます。動画が 2 回作成されるというこの問題は、誰でも解決できます。私が使用したコードは

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

コントロールは、完了ハンドラーで 1 回ではなく 2 回実行されます !!!

4

0 に答える 0