Home > front end >  How to tell if a video is HDR or not in Swift?
How to tell if a video is HDR or not in Swift?

Time:12-13

I need to detect if a video is HDR or not and on that basis I want to make a decision. I am using AVKit. Is there any way to tell the difference. Thanks.

CodePudding user response:

Simple and precise:

var isHdrVideo = false
    let pVideoTrack = AVAsset(url: URL(fileURLWithPath: assetURL!))
    if #available(iOS 14.0, *) {
        let tracks = pVideoTrack.tracks(withMediaCharacteristic: .containsHDRVideo)
        for track in tracks{
            isHdrVideo = track.hasMediaCharacteristic(.containsHDRVideo)
            if(isHdrVideo){
                break
            }
        }
    }
  • Related