gpt4 book ai didi

ios - Swift - 如何获得视频维度?

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:20 26 4
gpt4 key购买 nike

我正在开发一个视频编辑应用程序,其中每个视频都以不裁剪视频任何部分的方式进行平方。为此,在纵向视频的情况下,它包含左右黑色部分和横向视频,它在视频的顶部和底部包含黑色部分。黑色部分是视频的一部分,它们不适用于 AVPlayerViewController。这是示例,enter image description here

我需要用一些 CALayers 覆盖这些黑色部分。

What will be the frame(CGRect) of the CALayer?

我正在使用包含黑色部分的 naturalSize 属性获取视频尺寸。

Is there any way to get the video dimension without the black portions?(I mean the dimension of actual video content) or is there any way to get the CGRect of black area of the video?

最佳答案

func initAspectRatioOfVideo(with fileURL: URL) -> Double {
let resolution = resolutionForLocalVideo(url: fileURL)
guard let width = resolution?.width, let height = resolution?.height else {
return 0
}
return Double(height / width)
}

private func resolutionForLocalVideo(url: URL) -> CGSize? {
guard let track = AVURLAsset(url: url).tracks(withMediaType: AVMediaType.video).first else { return nil }
let size = track.naturalSize.applying(track.preferredTransform)
return CGSize(width: abs(size.width), height: abs(size.height))
}

关于ios - Swift - 如何获得视频维度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44879386/

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