我想在不使用任何第三方框架的情况下将过滤器应用于预先录制的视频我该怎么做。我曾尝试将CIfilter用于CAlayer,但它不是Working.Here是我的代码:
CALayer *effectlayer=[CALayer layer];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
keysAndValues: kCIInputImageKey,effectlayer,
@"inputIntensity", @.5, nil];
[effectlayer setFilters:[NSArray arrayWithObjects:filter, nil]];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer=[CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
[parentLayer addSublayer:overlayLayero];
[parentLayer addSublayer:effectlayer];
答案 0 :(得分:0)
以下是我的答案的代码:
// 1 - set up the overlay
CALayer *overlayLayer = [CALayer layer];
UIImage *overlayImage = nil;
overlayImage = [UIImage imageNamed:@"your Image name"];
[overlayLayer setContents:(id)[overlayImage CGImage]];
overlayLayer.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer setMasksToBounds:YES];
// 2 - set up the parent layer
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
// composiontion is instance of your AVMutableVideoComposition
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];