【问题标题】:io<s AVAssetTrack video-orientationio<s AVAssetTrack 视频方向
【发布时间】:2014-02-23 22:53:53
【问题描述】:

我正在使用自定义 CaptureSessionManager 录制一些视频,并根据设备方向旋转预览层(否则,预览层在横向左/右上是颠倒的)。到目前为止,这有效。但是……

当我尝试播放视频时,我使用以下代码来确定视频的方向:

AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    CGSize size = [videoTrack naturalSize];
    CGAffineTransform txf = [videoTrack preferredTransform];

    if (size.width == txf.tx && size.height == txf.ty)
        return UIInterfaceOrientationLandscapeRight;
    else if (txf.tx == 0 && txf.ty == 0)
        return UIInterfaceOrientationLandscapeLeft;
    else if (txf.tx == 0 && txf.ty == size.width)
        return UIInterfaceOrientationPortraitUpsideDown;
    else
        return UIInterfaceOrientationPortrait;

但结果总是一样的,不管是左是右。

我使用此代码获取输出:

AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    CGSize size = [videoTrack naturalSize];
    CGAffineTransform txf = [videoTrack preferredTransform];

    NSLog(@"Transformation a %f - b %f - c %f - d %f", txf.a, txf.b, txf.c, txf.d);
    NSLog(@"Transformation tx %f - ty %f", txf.tx, txf.ty);
    NSLog(@"Size width: %f - height: %f", size.width, size.height);

导致:

Transformation a -1.000000 - b 0.000000 - c 0.000000 - d -1.000000
Transformation tx 1920.000000 - ty 1080.000000
Size width: 1920.000000 - height: 1080.000000

用于左右方向录制。

有什么想法吗?

【问题讨论】:

  • 很好的代码 sn-p 来确定视频方向,谢谢!

标签: ios video orientation avasset


【解决方案1】:

好吧,愚蠢,愚蠢的错误……

我忘了在输出文件上设置方向:

self.recordingOrientation -&gt; AVCaptureVideoOrientation 在设备旋转或启动录制时存储。

AVCaptureConnection *CaptureConnection = [MovieFileOutput connectionWithMediaType:AVMediaTypeVideo];

if ([CaptureConnection isVideoOrientationSupported])
{
    [CaptureConnection setVideoOrientation:self.recordingOrientation];
}

【讨论】:

  • 这里,self. recordingOrientation 是什么?我有同样的问题
  • 这是视频的方向 AVCaptureVideoOrientationLandscapeRight | AVCaptureVideoOrientationLandscapeLeft | AVCaptureVideoOrientationPortraitUpsideDown | AVCaptureVideoOrientationPortrait
猜你喜欢
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多