gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:40:52 31 4
gpt4 key购买 nike

我使用 [此处][1] 中的代码在使用 UIImagePickerController 拍摄的视频上附加图像。

视频是纵向的,播放正常,但是一旦我使用 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

关于iphone - naturalSize 从 AVURLAsset 返回错误的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11282283/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com