AVFoundation视频方向水平修复不完整180deg旋转

时间:2014-03-26 15:25:09

标签: ios avfoundation cgaffinetransform affinetransform

我正在进行视频定位修复,我们正在加入几个视频轨道,每个视频轨道都有不同的方向(风景,风景向下,风景镜像,风景向下镜像)。我遇到的问题是视频轨道没有完成干净的半圆180度。正如本演示所见:

视觉结果如下:在应用变换之前(旋转180度帧):

Before applying the transform

应用变换后(翻转以获得正确的横向但旋转未完成):

After applying the transform

我的简化轮换代码如下所示:

CGAffineTransform getOrientationLandscapeTransform(UIImageOrientation videoTrackOrientation, CGAffineTransform videoTrackPreferredTransform)
{
    printTransformForName(@"IN :::", videoTrackPreferredTransform);

    CGAffineTransform fixT = CGAffineTransformIdentity;

    if (orientation == UIImageOrientationDown) {
        fixT = CGAffineTransformConcat(CGAffineTransformMakeTranslation(-preferredTransform.tx, -preferredTransform.ty), CGAffineTransformMakeRotation(M_PI));
    }

    printTransformForName(@"OUT :::", fixT);
    return fixT;
}

输出如下:

[1777:60b] IN ::: [-1, 0, 0, -1, 1920, 1080]
[1777:60b] OUT ::: [-1, 1.2246467991473532e-16, -1.2246467991473532e-16, -1, 1920.0000000000002, 1079.9999999999998]

任何想法为什么有趣的矩阵参数为b& c和tx& ty?我认为这代表了我的问题。

请注意,为了进行调试,我在UILabel转换上尝试了相同的代码,令我惊讶的是产生了预期的结果:

void printTransformForName(NSString *name, CGAffineTransform prefferedTransform) {
    NSLog(@"%@ %@", name, NSStringFromCGAffineTransform(prefferedTransform));
}

printTransformForName(@"BEFORE", test.transform);
test.transform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(-test.transform.tx, -test.transform.ty), CGAffineTransformMakeRotation(M_PI));
printTransformForName(@"AFTER", test.transform);

输出:

2014-03-26 17:07:38.584 Transformation Fun[65788:60b] BEFORE [1, 0, 0, 1, 0, 0]
2014-03-26 17:07:38.609 Transformation Fun[65788:60b] AFTER [-1, 0, -0, -1, 0, 0]

0 个答案:

没有答案