首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从AVURLAsset返回错误方向的naturalSize

从AVURLAsset返回错误方向的naturalSize
EN

Stack Overflow用户
提问于 2012-07-01 21:16:32
回答 2查看 4.3K关注 0票数 5

我正在使用这里找到的代码附加使用UIImagePickerController拍摄的视频图像。

视频是纵向的,播放正常,但一旦我使用AVURLASSet,它转向横向而不是纵向,我找不到为什么?

谁能给我指个方向?

我的代码:

代码语言:javascript
复制
-(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的正确大小

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-05 18:47:58

找到详细教程,介绍如何使用AVfoundation introduction here编辑和操作视频

如果它们是横向的,我们可以使用我们提供的naturalSize属性,但是如果它们是纵向的,我们必须翻转naturalSize,这样宽度就是,反之亦然

票数 2
EN

Stack Overflow用户

发布于 2013-05-23 03:42:40

我在这里留下了正确的代码,以防其他人需要,尽管您选择了自己的答案作为正确的答案。

代码语言:javascript
复制
//readout the size of video
AVAssetTrack *vT = nil;
if ([[asset tracksWithMediaType:AVMediaTypeVideo] count] != 0)
{
    vT = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
}
if (vT != nil)
{
    orgWidth = vT.naturalSize.width;
    orgHeight = vT.naturalSize.height;
}

//check the orientation
CGAffineTransform txf = [vT preferredTransform];
if ((width == txf.tx && height == txf.ty)|(txf.tx == 0 && txf.ty == 0))
{
    //Landscape
}
else
{ 
    //Portrait
} 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11282283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档