如何在现有视频中添加过滤器



我想在我现有的捕获视频中添加滤镜效果,我曾尝试使用GPUImageMovie(<GPUImage/GPUImage.h>)但在[movieWriter startRecording];上崩溃,所以您能否建议我是否有任何其他适当的方法来做到这一点。

只需传递您现有的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
        });
    }];
}

相关内容

  • 没有找到相关文章

最新更新