2013-11-25 67 views
0

视频我试图指定颜色的边框添加到视频让这样的事情http://d.pr/i/1WXs添加边框使用GPUImage

下面是我在做什么

GPUImageNormalBlendFilter *blendFilter = [GPUImageNormalBlendFilter new]; 

_movie = [[GPUImageMovie alloc] initWithURL:_movieUrl]; 

_sourcePicture = [[GPUImagePicture alloc] initWithImage:[self imageWithColor:RGBACOLOR(255, 0, 0, 0.5f)]]; 
[_sourcePicture processImage]; 

[_sourcePicture addTarget:blendFilter atTextureLocation:0]; 
[_movie addTarget:blendFilter atTextureLocation:1]; 

[blendFilter addTarget:_videoView]; 

[_movie startProcessing]; 

据我了解,转换过滤器无法调整视频大小以添加空格? 我该如何做到这一点?

谢谢。

+0

您是否在转换过滤器上使用过'-setBackgroundColorRed:green:blue:alpha:'并将背景颜色设置为白色(1.0,1.0,1.0,1.0)?一旦你调整了视频的大小,其余的图像应该用白色填充。 –

+0

@BradLarson,是的,我已经尝试过,它的工作原理。但是,转换过滤器会调整视频大小,并且我需要调整画布大小。 – aiwo

回答

0

使用变换链求解&裁剪过滤器。

[transformFilter setBackgroundColorRed:1 green:0 blue:0 alpha:0]; // For example 

// Calculate scale for exact crop size 
// For 16x9 scale = 16 * videoSize.height/(9 * videoSize.width); 
CGFloat scale = [self scaleForCropSize:self.cropSize]; 
transformFilter.affineTransform = CGAffineTransformMakeScale(scale, scale); 

CGSize videoSize = [self.paramsContainer.videoTrack naturalSize]; 
CGRect cropRegion; 
if (videoSize.width > videoSize.height) { 
    cropRegion = CGRectMake((1 - scale)/2, 0, scale, 1); 
} else { 
    cropRegion = CGRectMake(0, (1 - scale)/2, 1, scale); 
} 

cropFilter.cropRegion = cropRegion;