0

I'm sorry for what is probably a very stupid question, but I've been unable to find a solution for several days now.

I know a little about Python and it turned out to be very easy to implement on it.

So I have the path to the file. I need to know its horizontal resolution.

 Button(action: {
            print(selectedPath)
            let rpFilePicker: NSOpenPanel = NSOpenPanel()
            
            rpFilePicker.allowsMultipleSelection = false
            rpFilePicker.canChooseFiles = true
            rpFilePicker.canChooseDirectories = true
            
            rpFilePicker.runModal()
            selectedPath = rpFilePicker.url!.path
            
            let fm = FileManager.default

            do {
                let items = try fm.contentsOfDirectory(atPath: selectedPath)

                for item in items {
                    let slash = "/" // yes its stupid
                    let onePath = selectedPath + slash + item
                    print(onePath)
    
                }
            } catch {
                
            }

I would like some simple solution, without a ton of code, which frankly scares in Swift after Python...

Thanks!

1 Answers1

0

Get Dimensions Of Video From Local URL

var videoSize: CGSize = getVideoResolution(url: "local video url")!

func getVideoResolution(url: String) -> CGSize? {
    guard let track = AVURLAsset(url: URL(string: url)!).tracks(withMediaType: AVMediaType.video).first else { return nil }
    let size = track.naturalSize.applying(track.preferredTransform)
    return size
}
Euan Traynor
  • 420
  • 2
  • 11