iphone – naturalSize从AVURLAsset返回错误的方向

前端之家收集整理的这篇文章主要介绍了iphone – naturalSize从AVURLAsset返回错误的方向前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用[here] [1]中找到的代码将图像附加到使用UI ImagePickerController拍摄的视频上.

视频是纵向的,并且播放得很好但是一旦我使用AVURLASSet它转向横向而不是肖像,我找不到原因?

任何人都能指出我正确的方向吗?

我的代码

-(IBAction)addWaterMark:(id)sender {
 AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:tempPath] options:nil];
AVMutableComposition* mixComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo  preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) 
                               ofTrack:clipVideoTrack
                                atTime:kCMTimeZero error:nil];

[compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; 

CGSize videoSize = [videoAsset naturalSize]; 
NSLog(@"%f %f",videoSize.width,videoSize.height);
}

在这一点上,我得到480,360而不是正确的temppath大小

解决方法

找到了详细的教程,描述了如何使用AVfoundation简介 here编辑和操作视频

If they are landscape,we can use the naturalSize property we are supplied with,but if they are portrait,we must flip the the naturalSize so that the width is now the height and vice-versa

猜你在找的Xcode相关文章