The*_*heo 4 avfoundation ios avassetexportsession
我正在使用AVAssetExportSession在 iOS 应用程序中导出视频。为了以正确的方向呈现视频,我使用AVAssetTrack的是preferredTransform. 对于一些源视频,这个属性似乎有一个错误的值,结果视频出现偏移或全黑。我怎样才能解决这个问题?
这preferredTransform是一个CGAffineTransform. 的属性a,b,c,d是反射和旋转矩阵的级联,并且属性tx和ty描述了翻译。在我观察到的所有不正确的情况下,preferredTransform反射/旋转部分似乎是正确的,只有平移部分包含错误的值。一个可靠的修复似乎是检查a,b,c,d(8案件总共,每个对应于在壳体UIImageOrientation)和更新tx和ty相应地:
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
387 次 |
| 最近记录: |