2016-09-04 26 views
11

Uygulamamda, 1280 x 720 boyutlarında görüntü işleme bileşimi var. Bu nedenle herhangi bir portre videosunu içe aktaracak olursam, ortadaki videonun dolgu ve görüntü çerçevesiyle bulanıklık arka planı göstermem gerekiyor. Böyle Aynı:AVfoundation Videoda arka plan bulanıklığı

https://www.youtube.com/watch?v=yCOrqUA0ws4

Ben AVMtableComposition kullanarak her iki videoları oynatmak için elde, ama belli bir plan takip bulanıklık nasıl bilmiyorum. Benim kodunda aşağıdaki vermedi:

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]; 

ben bunu başarabilirsiniz kodunun üzerinde kullanma:

https://drive.google.com/open?id=0B2jCvCt5fosyOVNOcGZ1MU1laEU

Ben kompozisyon kareleri filtrelemek için customVideoCompositor sınıfa biliyorum. Denedim ama eğer customVideoCompositor kullanırsam, dönüşüm katmanlarımdaki dönüşümümü kaybediyorum. Ayrıca, customVideoCompositor'dan belirli bir parça kimliğini nasıl filtreleyeceğimi bilmiyorum.

Birisi herhangi bir dokümana ya da öneriye sahipse, o zaman bu konuda ilerlemeyi gerçekten takdir ediyor.

+0

Eğer addAsset 'uygulamanızı gösterebilir bu kodu eklemek' ve 'setPlayerLayer:'? –

+0

Videonuzun 'backVideoTrack.naturalSize' nedir? –

+0

backVideoTrack, naturalSize 1920 x 1080 –

cevap

-1

2 farklı AVPlayer s kullandığını elde etmek için bir yol ve bir a blur overlay view: backgroundLayer ->bluer overlay view ->frontLayer. Her iki oyuncunun da aynı anda başladığından ve durduğundan emin olmanız yeterlidir.

Başka bir seçenek 1 AVPlayer ve time observer kullanıyor. Her karede frontLayer geçerli görüntüsünü ayıklayın, bulanıklaştırın ve backgroundLayer'da görüntüleyin. Bulanıklaştırma fonksiyonu, yukarıda sağladığım bağlantıda bulunabilir. toComposition:

+0

Lütfen soruyu anlayın. “AVMutablecomposition” kullanarak çalışma zamanı yapmak istiyor. –

+0

Onun sorusunu da anladın mı? O yardımcı olabilecek herhangi bir öneri istedi. Ve o sadece 'AVMutablecomposition' kullanmak istediğini söylemedi. – sahara108

0

ekranın ortasına olduğu ikinci video katmanını eklemeden önce

Swift ise
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

Video parçalarıyla oynamak istiyorum. Birden fazla 5 video parçası olacak. Dinamik bulanıklık, birden fazla parça için çalışma zamanında değişecek ve sonunda video olarak aktarmak istiyorum. Çözümünüz sadece gerçek zamanlı video düzenleme için değil UI işleme bulanıklığı içindir. –

+0

İstediğiniz zaman bulanıklık efektini kontrol etmeli ve değiştirmelisiniz, Görsel efektinizi geliştiren kendi algoritmalarınızla dinamik bulanıklık yapılacaktır. Youtube'da yayınladığınız video bağlantısının basit bir bulanıklık etkisi olduğunu görün. Dinamik bir bulanıklık istiyorsanız, algoritmalar ekleyin. – gurmandeep