AVAssetExportSession을 통해 비디오 자산을 내보낼 때 결과 파일은 랜드 공간 모드입니다. (파일은 itune-> apps-> file sharing-> my app를 통해 가져옵니다). 비디오 애셋을 세로 모드로 내보내려면 어떻게해야합니까?AVAssetExportSession을 통해 비디오 자산을 세로 모드로 내보내는 방법
5
A
답변
20
iPhone 캡처 장치에서 오는 비디오는 캡처 할 때 장치 방향이 무엇이든 항상 가로 방향입니다.
동영상을 회전하려면 '간단한'해법은 내 보낸 세션의 비디오 트랙에 변환을 지정하는 것입니다.
AVMutableCompositionTrack *videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *audioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
컴포지션의 트랙에 매개체 트랙을 추가 :
이 AVComposition 객체의 2 개 가변 트랙 만들기 당신이 모든 트랙을 추가 한 후,
...
BOOL videoResult = [videoTrack insertTimeRange:sourceCMTime
ofTrack:[tracks objectAtIndex:0]
atTime:currentTime
error:&error];
BOOL audioResult = [audioTrack insertTimeRange:sourceCMTime
ofTrack:[tracks objectAtIndex:0]
atTime:currentTime
error:&error];
...
을 적용 당신의 비디오 트랙으로 변환 귀하의 작품 :
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(M_PI_2);
// CGAffineTransform rotateTranslate = CGAffineTransformTranslate(rotationTransform,360,0);
videoTrack.preferredTransform = rotationTransform;
(transf orm은 원점으로 왼쪽 위 모서리를 가졌으므로 회전 후에 회전이 필요했지만 iPhone 4S, iOS 5.1에서 테스트 했으므로 이제 회전이 중심 주위에서 이루어진 것으로 보입니다.)
0
U가 트랙을 변환하는 동안 프레임의 범위를 벗어나거나 검은 색 블록으로 나타나기 때문에 renderSize 컴포지션을 설정하십시오.
self.mutableVideoComposition.renderSize = CGSizeMake(assetVideoTrack.naturalSize.height,assetVideoTrack.naturalSize.width);