gpt4 book ai didi

ios - AVAssetTrack 的 preferredTransform 有时似乎是错误的。如何解决这个问题?

转载 作者:行者123 更新时间:2023-12-03 21:10:28 84 4
gpt4 key购买 nike

我正在使用 AVAssetExportSession在 iOS 应用程序中导出视频。为了以正确的方向呈现视频,我正在使用 AVAssetTrackpreferredTransform .对于一些源视频,这个属性似乎有一个错误的值,结果视频出现偏移或全黑。我怎样才能解决这个问题?

最佳答案

preferredTransformCGAffineTransform .属性a , b , c , d是反射和旋转矩阵的串联,以及属性 txty描述一个翻译。在所有我观察到的不正确的情况下 preferredTransform ,反射/旋转部分似乎是正确的,只有平移部分包含错误的值。一个可靠的解决方法似乎是检查 a , b , c , d (共8个case,每个对应UIImageOrientation中的一个case)并更新txty因此:

extension AVAssetTrack {
var fixedPreferredTransform: CGAffineTransform {
var t = preferredTransform
switch(t.a, t.b, t.c, t.d) {
case (1, 0, 0, 1):
t.tx = 0
t.ty = 0
case (1, 0, 0, -1):
t.tx = 0
t.ty = naturalSize.height
case (-1, 0, 0, 1):
t.tx = naturalSize.width
t.ty = 0
case (-1, 0, 0, -1):
t.tx = naturalSize.width
t.ty = naturalSize.height
case (0, -1, 1, 0):
t.tx = 0
t.ty = naturalSize.width
case (0, 1, -1, 0):
t.tx = naturalSize.height
t.ty = 0
case (0, 1, 1, 0):
t.tx = 0
t.ty = 0
case (0, -1, -1, 0):
t.tx = naturalSize.height
t.ty = naturalSize.width
default:
break
}
return t
}
}

关于ios - AVAssetTrack 的 preferredTransform 有时似乎是错误的。如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64161544/

84 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com