Search code examples
iosswiftavfoundationavassetexportsession

How to tell if a video is HDR or not in Swift?


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.


Solution

  • 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
                }
            }
        }