我正在使用 AVMutableComposition 合并视频并且视频被合并。但是视频在合并后被存储在横向(这是 AVAsset 的默认模式)中。所以我希望视频只能在纵向模式下修复......有没有将视频方向设置为纵向模式的方法。提前感谢
这是我用于合并视频的代码
NSArray *arrVideoUrl=[objApp.dictSelectedVideos allKeys];
NSMutableArray *arrVideoAsset=[[NSMutableArray alloc]init];
for (int i=0; i<objApp.dictSelectedVideos.count; i++) {
AVURLAsset *video=[[AVURLAsset alloc]initWithURL:[arrVideoUrl objectAtIndex:i] options:nil];
[arrVideoAsset addObject:video];
}
AVURLAsset *music_track=[[AVURLAsset alloc]initWithURL:songUrl options:nil];
//to mix up the media items
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
//Setting Audio track
AVMutableCompositionTrack *AudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
//setting the track to add the videos
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVURLAsset *tempVideo1=[arrVideoAsset objectAtIndex:0];
AVURLAsset *tempVideo2=[arrVideoAsset objectAtIndex:1];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, tempVideo1.duration)ofTrack:[[tempVideo1 tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
if (arrVideoUrl.count==1)
{
[AudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeAdd(kCMTimeZero, tempVideo2.duration))ofTrack:[[music_track tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
}
else{
for (int j=1; j<=arrVideoAsset.count-1; j++)
{
AVURLAsset *tempVideoNext=[arrVideoAsset objectAtIndex:j];
AVURLAsset *tempVideoPrev=[arrVideoAsset objectAtIndex:j-1];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, tempVideoNext.duration)ofTrack:[[tempVideoNext tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:tempVideoPrev.duration error:nil];
}
[AudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeAdd(tempVideo1.duration, tempVideo2.duration))ofTrack:[[music_track tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
}