Sergey Kuryanov
Sergey Kuryanov

Reputation: 6114

Blend two videos with chroma key using GPUImage

I try to blend two videos using GPUImage. One of them (show.mov) contain green background.
Here is show.mov and galaxy.mov.
I downloaded the latest version of GPUImage and changed SimpleVideoFileFilter example:

- (void)viewDidLoad
{
    [super viewDidLoad];

    _movie = [[GPUImageMovie alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"galaxy" ofType:@"mov"]]];
    _greenMovie = [[GPUImageMovie alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"snow" ofType:@"mov"]]];

    _movie.playAtActualSpeed = YES;
    _greenMovie.playAtActualSpeed = YES;

    _filter = [[GPUImageChromaKeyBlendFilter alloc] init];

    [_greenMovie addTarget:_filter];
    [_movie addTarget:_filter];

    GPUImageView *filterView = (GPUImageView *)self.view;
    [_filter addTarget:filterView];

    [_greenMovie startProcessing];
    [_movie startProcessing];
}

When I run the project (no matter on device or simulator) I get just blank white view and after 14 seconds (length of show.mov) I see only last frame of blended videos. Using writer from example create file on disk, but this file can't be opened.
I am using iPhone 5 with 7.0.3 and XCode 5.0.2
Did I miss something?

Upvotes: 3

Views: 1426

Answers (1)

Sergey Kuryanov
Sergey Kuryanov

Reputation: 6114

Thanks to @BradLarson, he pointed to an github issue where I found commit that caused this problem.

In GPUImageMovie.m I comment two lines in startProcessing method:

[inputAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{
    //runSynchronouslyOnVideoProcessingQueue(^{
        NSError *error = nil;
        AVKeyValueStatus tracksStatus = [inputAsset statusOfValueForKey:@"tracks" error:&error];
        if (!tracksStatus == AVKeyValueStatusLoaded)
        {
            return;
        }
        blockSelf.asset = inputAsset;
        [blockSelf processAsset];
        blockSelf = nil;
    //});
}];

Upvotes: 1

Related Questions