2016-09-04 2 views
11

내 응용 프로그램에서 1280 x 720 크기의 컴포지션 렌더링을 수정했습니다. 그렇다면 세로 비디오를 가져 오면 배경이 흐리게 보이고 중앙에 비디오의 종횡비 프레임을 표시해야합니다. 이 같은 동일은 :비디오에서 AVfoundation 블러 배경

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, 0, -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를 필터링하는 방법을 모르겠습니다.

다른 사람이 문서 링크 나 제안 사항이있는 경우이 문제에 대해 정말 고맙게 생각합니다.

+0

당신이하면 addAsset'의 구현을 보여줄 수있는이 코드를 추가'및 'setPlayerLayer :'? –

+0

동영상의 'backVideoTrack.naturalSize'는 무엇입니까? –

+0

backVideoTrack, naturalSize는 1920 x 1080 –

답변

-1

2 가지 AVPlayer S를 사용하는 것을 달성하기위한 방법 및 a blur overlay view : backgroundLayer ->bluer overlay view ->frontLayer. 플레이어가 동시에 시작하고 중지 할 수 있도록해야합니다.

또 다른 옵션은 1 AVPlayertime observer입니다. 모든 프레임에서 frontLayer의 현재 이미지를 추출하고 흐리게 표시 한 후 backgroundLayer에 표시하십시오. 흐림 기능은 위에 제공된 것과 동일한 링크에서 찾을 수 있습니다. toComposition :

+0

질문을 이해하십시오. 그는'AVMutablecomposition'을 사용하여 런타임을 원합니다. –

+0

그의 질문을 잘 이해하셨습니까? 그는 도움이 될 수있는 제안을 요청했습니다. 그리고 그는'AVMutablecomposition' 만 사용하기를 원한다는 언급은하지 않았습니다. – sahara108

0

화면의 중앙에있는 두 번째 비디오 레이어를 추가하기 전에

스위프트에서
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) 
+0

비디오 트랙을 가지고 놀고 싶습니다. 여러 개의 비디오 트랙이있을 것입니다. 동적 흐림은 런타임에 여러 트랙에 대해 변경 될 것이며 최종적으로 비디오로 내보내려는 것과 동일한 것입니다. 따라서 사용자의 솔루션은 실시간 비디오 편집을위한 UI 처리 만 흐리게 처리합니다. –

+0

원하는 경우 흐림 효과를 확인하고 변경해야합니다. 동적 흐림 효과는 시각적 효과에 적합한 고유 한 알고리즘으로 만들어집니다. youtube에 올린 동영상 링크에 간단한 흐림 효과가 있습니다. 동적 흐림을 원한다면 알고리즘을 추가하십시오. – gurmandeep