내 응용 프로그램에서 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를 필터링하는 방법을 모르겠습니다.
다른 사람이 문서 링크 나 제안 사항이있는 경우이 문제에 대해 정말 고맙게 생각합니다.
당신이하면 addAsset'의 구현을 보여줄 수있는이 코드를 추가'및 'setPlayerLayer :'? –
동영상의 'backVideoTrack.naturalSize'는 무엇입니까? –
backVideoTrack, naturalSize는 1920 x 1080 –