2015-07-10 47 views
0

我想在我現有的捕獲的視頻中添加濾鏡效果,我試圖用GPUImageMovie(<GPUImage/GPUImage.h>)來做到這一點,但碰到[movieWriter startRecording];,所以如果有任何其他適當的方式來做到這一點,請你給我建議。如何在現有視頻中添加過濾器?

在此先感謝。

回答

0

只要通過您現有的videoURL,它將被過濾,不要忘記添加GPUImage框架。

- (void)testFilterOptions:(NSURL*)videoUrl{ 

    movieFile = [[GPUImageMovie alloc] initWithURL:videoUrl]; 
    movieFile.runBenchmark = YES; 
    movieFile.playAtActualSpeed = NO; 
    //filter = [[GPUImagePixellateFilter alloc] init]; 
    filter = [[GPUImageSepiaFilter alloc] init]; 

    [movieFile addTarget:filter]; 

    // Only rotate the video for display, leave orientation the same for recording 
// GPUImageView *filterView = (GPUImageView *)self.previewView; 
// [filter addTarget:filterView]; 

    // In addition to displaying to the screen, write out a processed version of the movie to disk 
    NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mov"]; 
    unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie 
    NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; 

    movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 480.0)]; 
    [filter addTarget:movieWriter]; 

    // Configure this for video from the movie file, where we want to preserve all video frames and audio samples 
    movieWriter.shouldPassthroughAudio = NO; 
    movieFile.audioEncodingTarget = nil; 
    [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; 

    [movieWriter startRecording]; 
    [movieFile startProcessing]; 

    [movieWriter setCompletionBlock:^{ 
     [filter removeTarget:movieWriter]; 
     [movieWriter finishRecording]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 
     //Recording complete do whatever you want 
     }); 
    }]; 
} 
相關問題