AVMutableVideoCompositionLayerInstruction转换比例旋转

时间:2016-02-09 01:44:59

标签: swift avfoundation orientation avmutablecomposition

我正在使用AVMutableComposition合并/拼接多个录制的视频曲目并将其保存为expected output

..所以我循环遍历子视图,根据每个子视图大小转换每个轨道。

    var index = 0
    for subview:UIView in template.subviews {
        let scaleX = (subview.frame.width / template.frame.width) / (tracks[index].naturalSize.width /  mainComposition.renderSize.width)
        let scaleY = (subview.frame.height / template.frame.height) / (tracks[index].naturalSize.height /  mainComposition.renderSize.height)
        let x = subview.frame.origin.x
        let y = subview.frame.origin.y

        let rotate = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
        let scale = CGAffineTransformMakeScale(scaleX, scaleY)
        let translate = CGAffineTransformMakeTranslation(x, y)
        let transform = CGAffineTransformConcat(scale, translate)

        let transformation = AVMutableVideoCompositionLayerInstruction(assetTrack: tracks[index])
        transformation.setTransform(CGAffineTransformConcat(rotate, transform), atTime: kCMTimeZero)
        instructions.append(transformation)
        index++
    }

问题是视频全部不在保存的视频中。 但是如果没有旋转,我会得到预期的输出,如附加图像,但视频中的视频 - 我读到的情况总是如此,iPhone设备中捕获的视频(how to export video asset via AVAssetExportSession in portrait mode

我一直在玩CGAffineTransform,重新排列翻译,旋转或缩放,这是首先或最后但没有得到好结果。 我也试过创建两个分离旋转和sctaletranslate的layerinstruction,但仍然是相同的。

感谢您的帮助

0 个答案:

没有答案
相关问题