问题描述:

I'm trying to add an image to every frame of a video using the GPUImage library, but can't get it to work. For some reason, the processed video only includes the original video, without the image overlay. What am I doing wrong?

GPUImagePicture *overlay = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"overlayimage"] smoothlyScaleOutput:YES];

[overlay processImage];

GPUImageMovie *movie = [[GPUImageMovie alloc] initWithURL:[THE URL TO THE VIDEO ASSET]];

movie.delegate = self;

movie.runBenchmark = YES;

movie.playAtActualSpeed = YES;

self.movieView = [[GPUImageView alloc] initWithFrame:self.bounds];

self.movieView.fillMode = kGPUImageFillModePreserveAspectRatio;

[self addSubview:self.movieView];

GPUImageAlphaBlendFilter *filter = [[GPUImageAlphaBlendFilter alloc] init];

[movie addTarget:filter atTextureLocation:0];

[overlay addTarget:filter atTextureLocation:1];

[filter prepareForImageCapture];

[filter addTarget:self.movieView];

[movie startProcessing];

网友答案:

Here's the solution, if anyone runs into the same problem: You have to retain the GPUImagePicture, GPUImageMovie and GPUImageView objects, for example by storing them in properties. Otherwise they will be released under ARC at the end of the method or the runloop.

网友答案:

Two things you can try:

  1. Don't call processImage on overlay until AFTER you've targeted the alpha blend filter. I'd try it right before, or right after you call startProcessing on movie.

  2. Don't worry about specifying the textureLocation's when your targeting the AlphaBlendFilter. you can just call addTarget and let the blend sort it out.

Those are off the top of my head, I'll actually test them out after work tonight.

相关阅读:
Top