我正在使用AVMutableComposition合并/缝合多个录制的视频轨道并将其保存为预期的输出
..所以我循环遍历子视图,根据每个子视图大小转换每个轨道.
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++
}
Run Code Online (Sandbox Code Playgroud)
问题是视频全部不在保存的视频中.但是如果没有旋转,我会得到预期的输出,如附图中的视频,但视频中的视频 - 我读到的是iPhone设备中捕获的视频总是如此(如何通过AVAssetExportSession以纵向模式导出视频资源)
我一直在玩CGAffineTransform,重新排列翻译,旋转或缩放,这是首先或最后但没有得到好结果.我也试过创建两个分离旋转和sctaletranslate但仍然相同的layerinstruction.
谢谢你的帮助