https://www.youtube.com/watch?v=yCOrqUA0ws4
我实现了使用AVMtableComposition播放两个视频,但我不知道如何模糊一个特定的背景轨道.我在代码中执行了以下 *** 作:
self.composition = [AVMutableComposition composition];AVAsset *firstAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ScreenFlow_Blend" ofType:@"mp4"]]];[self addAsset:firstAsset toComposition:self.composition withTrackID:1];[self addAsset:firstAsset toComposition:self.composition withTrackID:2];// [self addAsset:ThirdAsset toComposition:self.composition withTrackID:3];AVAssetTrack *backVIDeoTrack = [firstAsset tracksWithMediaType:AVMediaTypeVIDeo][0];;self.vIDeoComposition = [AVMutableVIDeoComposition vIDeoComposition];self.vIDeoComposition.renderSize = CGSizeMake(1280,720);self.vIDeoComposition.frameDuration = CMTimeMake(1,30);AVMutableVIDeoCompositionInstruction *instruction = [AVMutableVIDeoCompositionInstruction vIDeoCompositionInstruction];instruction.timeRange = [backVIDeoTrack timeRange];CGfloat scale = 1280/backVIDeoTrack.naturalSize.wIDth;CGAffinetransform t = CGAffinetransformMakeScale(scale,scale);t = CGAffinetransformTranslate(t,-backVIDeoTrack.naturalSize.height/2 + self.vIDeoComposition.renderSize.height/2);AVMutableVIDeoCompositionLayerInstruction *frontLayerInstruction = [AVMutableVIDeoCompositionLayerInstruction vIDeoCompositionLayerInstruction];frontLayerInstruction.trackID = 1;[frontLayerInstruction settransform:t atTime:kCMTimeZero];CGfloat scaleSmall = 720/backVIDeoTrack.naturalSize.height;CGAffinetransform translate = CGAffinetransformMakeTranslation(self.vIDeoComposition.renderSize.wIDth/2 - ((backVIDeoTrack.naturalSize.wIDth/2)*scaleSmall),0);CGAffinetransform scaletransform = CGAffinetransformMakeScale(scaleSmall,scaleSmall);CGAffinetransform finaltransform = CGAffinetransformConcat(scaletransform,translate);CGAffinetransform t1 = CGAffinetransformMakeScale(scaleSmall,scaleSmall);t1 = CGAffinetransformTranslate(t1,1280,0);AVMutableVIDeoCompositionLayerInstruction *backLayerInstruction = [AVMutableVIDeoCompositionLayerInstruction vIDeoCompositionLayerInstruction];backLayerInstruction.trackID = 2;[backLayerInstruction settransform:finaltransform atTime:kCMTimeZero];// AVMutableVIDeoCompositionLayerInstruction *maskLayerInstruction = [AVMutableVIDeoCompositionLayerInstruction vIDeoCompositionLayerInstruction];// maskLayerInstruction.trackID = 3;// [maskLayerInstruction settransform:t atTime:kCMTimeZero];instruction.layerInstructions = @[backLayerInstruction,frontLayerInstruction];self.vIDeoComposition.instructions = @[ instruction ];AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:self.composition];playerItem.vIDeoComposition = self.vIDeoComposition;self.player = [AVPlayer playerWithPlayerItem:playerItem];AVPlayerLayer *newPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:[self player]];[newPlayerLayer setFrame:[[[self playerVIEw] layer] bounds]];// [newPlayerLayer setHIDden:YES];[[[self playerVIEw] layer] addSublayer:newPlayerLayer];[self setPlayerLayer:newPlayerLayer];
使用上面的代码我可以实现这一点:
https://drive.google.com/open?id=0B2jCvCt5fosyOVNOcGZ1MU1laEU
我了解customVIDeoCompositor类来过滤组合框架.我尝试了,但如果我使用customVIDeoCompositor然后我失去了在组合层的转换.另外,从customVIDeoCompositor我不知道如何过滤特定的跟踪ID.
如果有人有任何文件的链接或建议,那么真的很欣赏在此.
解决方法 在添加屏幕中心的第二个视频层之前,添加此代码UIVisualEffect *blurEffect;blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtralight];//Change the effect which you want.UIVisualEffectVIEw *visualEffectVIEw;visualEffectVIEw = [[UIVisualEffectVIEw alloc] initWithEffect:blurEffect];visualEffectVIEw.frame = self.vIEw.bounds;[self.vIEw addSubvIEw:visualEffectVIEw];
在斯威夫特
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light) //Change the style which suites you let blurEffectVIEw = UIVisualEffectVIEw(effect: blurEffect) blurEffectVIEw.frame = vIEw.bounds blurEffectVIEw.autoresizingMask = [.FlexibleWIDth,.FlexibleHeight] // for supporting device rotation vIEw.addSubvIEw(blurEffectVIEw)总结
以上是内存溢出为你收集整理的ios – 视频中的AVfoundation模糊背景全部内容,希望文章能够帮你解决ios – 视频中的AVfoundation模糊背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)