我正在使用这里找到的代码附加使用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的正确大小
发布于 2012-07-05 18:47:58
找到详细教程,介绍如何使用AVfoundation introduction here编辑和操作视频
如果它们是横向的,我们可以使用我们提供的naturalSize属性,但是如果它们是纵向的,我们必须翻转naturalSize,这样宽度就是,反之亦然
发布于 2013-05-23 03:42:40
我在这里留下了正确的代码,以防其他人需要,尽管您选择了自己的答案作为正确的答案。
//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
} https://stackoverflow.com/questions/11282283
复制相似问题