加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:21:45 所属栏目:百科 来源:网络整理
导读:我使用[here] [1]中找到的代码将图像附加到使用UI ImagePickerController拍摄的视频上. 视频是纵向的,并且播放得很好但是一旦我使用AVURLASSet它转向横向而不是肖像,我找不到原因? 任何人都能指出我正确的方向吗? 我的代码: -(IBAction)addWaterMark:(id)
我使用[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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读