使用GPUImage混合两个视频

时间:2014-01-09 09:46:24

标签: ios gpuimage

使用GitHub的最新GPUImage代码我尝试了以下内容:

#import "ViewController.h"
#import "GPUImage.h"
#import <AssetsLibrary/AssetsLibrary.h>

@interface ViewController ()
{
    GPUImageOutput<GPUImageInput> *filter0;
    GPUImageMovieWriter *movieWriter;
    GPUImageMovie *movie1, *movie2;
}
@end


@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSLog(@"started");

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"video1" withExtension:@"MOV"];
    movie1 = [[GPUImageMovie alloc] initWithURL:url];
    movie1.playAtActualSpeed = YES;

    NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"video2" withExtension:@"MOV"];
    movie2 = [[GPUImageMovie alloc] initWithURL:url2];
    movie2.playAtActualSpeed = YES;

    filter0 = [[GPUImageNormalBlendFilter alloc] init];
    [filter0 forceProcessingAtSize:CGSizeMake(1080, 1920)];

    [movie1 addTarget:filter0];
    [movie2 addTarget:filter0]; // movie2 adding Filter

    GPUImageView *filterView= (GPUImageView *) self.view;
    filterView.fillMode = kGPUImageFillModePreserveAspectRatio;

    [filter0 addTarget:filterView];

    [movie1 startProcessing];
    [movie2 startProcessing]; // movie2 startprocessing
}
@end

基本上,我想混合两个视频并将其显示在屏幕上,但在运行后,没有任何内容显示,只有黑屏显示,第二个视频的第一帧显示几秒钟后。< /强>

**我添加了“标题搜索路径”,并在“其他链接器”中给出了标记 -ObjC

现在,如果我将PixellateFilter添加到任何一个视频(比如movie1,评论 movie2添加过滤器 movie2 startprocessing ),那么结果就会到来。

所以我的问题是为什么两个视频没有发生混合,我做错了什么。

提前致谢

1 个答案:

答案 0 :(得分:0)

NSURL *url = [[NSBundle mainBundle] URLForResource:@"abc" withExtension:@"mp4"];

gpuIM = [[GPUImageMovie alloc] initWithURL:url];

gpuIM.playAtActualSpeed = YES;

NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"def" withExtension:@"mov"];
movie2 = [[GPUImageMovie alloc] initWithURL:url2];

movie2.playAtActualSpeed = YES;

filter0 = [[GPUImageColorDodgeBlendFilter alloc] init];

[gpuIM addTarget:filter0];
[movie2 addTarget:filter0];

[filter0 addTarget:_view0];

[gpuIM startProcessing];
[movie2 startProcessing];

另一种方法是从URL创建一个avasset,在GPUImageMovie中使用它,最重要的是使GPUImageMovie实例成为全局。