GPUImage GPUImageTwoInputFilter two videos

1k views Asked by At

I have a problem with GPUImage using GPUImageTwoInputFilter (any filter like GPUImageChromaKeyBlendFilter) for two videos. I have no videos in this case.

@interface ViewController ()

@property (nonatomic) GPUImageMovie *video;
@property (nonatomic) GPUImageMovie *chromaVideo;
@property (nonatomic) GPUImageMovieWriter *movieWriter;
@property (nonatomic) GPUImageColorDodgeBlendFilter *filter;

@end

@implementation ViewController

- (void)viewDidLoad
{
    NSURL *videoUrl = [[NSBundle mainBundle] URLForResource:@"video"
                                         withExtension:@"MOV"];

    _video = [[GPUImageMovie alloc] initWithURL:videoUrl];
    _video.playAtActualSpeed = YES;

    NSURL *chromaVideoUrl = [[NSBundle mainBundle] URLForResource:@"chroma"
                                          withExtension:@"mov"];
    _chromaVideo = [[GPUImageMovie alloc] initWithURL:chromaVideoUrl];
    _chromaVideo.playAtActualSpeed = YES;

    _filter = [[GPUImageColorDodgeBlendFilter alloc] init];
    //[_filter setThresholdSensitivity:0.45];

    [_video addTarget:_filter];
    [_chromaVideo addTarget:_filter];

    NSURL *outURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/MovieMix.mov"]];

    NSFileManager *fm = [NSFileManager defaultManager];
    [fm removeItemAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/MovieMix.mov"]
                   error:nil];

    _movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:outURL size:CGSizeMake(1280, 720)];

    __weak ViewController *weakSelf = self;
    [_filter addTarget:_movieWriter];

    [_movieWriter startRecording];
    [_video startProcessing];
    [_chromaVideo startProcessing];

    [_movieWriter setCompletionBlock:^
     {
         [weakSelf.filter removeTarget:weakSelf.movieWriter];
         [weakSelf.movieWriter finishRecording];
         UISaveVideoAtPathToSavedPhotosAlbum([NSHomeDirectory() stringByAppendingPathComponent:@"Documents/MovieMix.mov"],nil,nil,nil);
         NSLog(@"Done");
     }];
}

But when I do operations in completion block with dispatch_after 5 sec, I have a video in my gallery with duration == 0 (I think it has 1 frame).

0

There are 0 answers