2013-11-25 91 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;