在苹果开发者网站https://developer.apple.com/news/?id=rwbholxw对hdr描述中可以看到,
Asset inspection AVMediaCharacteristic provides options for
specifying media type characteristics, including whether a
video includes HDR metadata. You can use the Swift media
characteristic containsHDRVideo to identify whether any segment
of a track contains HDR so that your app can render it
correctly. In Objective-C, you can use
AVMediaCharacteristicContainsHDRVideo, defined in
AVMediaFormat.h.
After loading the tracks property using the Swift method
loadValuesAsynchronously(forKeys:completionHandler:), you can
get HDR tracks using tracks(withMediaCharacteristic:). Here’s
how you might get all desired HDR tracks:
获取包含hdr的tracks
swift
let avAsset = AVURLAsset(url: fileURL as URL)
let hdrTracks = avAsset.tracks(withMediaCharacteristic: .containsHDRVideo)
OC
NSArray<AVAssetTrack *> *hdrTracks
= [asset tracksWithMediaCharacteristic:AVMediaCharacteristicContainsHDRVideo];
意思就是可以检查视频是否包含hdr元素,当然这个检查是需要ios14以上的系统的。
查看视频是否为hdr
swift
//fileURL为文件路径
let avAsset = AVURLAsset(url: fileURL as URL)
if let videoTrack = avAsset.tracks(withMediaType: .video).first {
if#available(iOS 14.0, *) {
let hasHDR = videoTrack.hasMediaCharacteristic(.containsHDRVideo)
print("=======================================")
print("有HDR?")
print(hasHDR)
print("=======================================")
} else {// Fallback on earlier versions
}
}
OC
if([track hasMediaCharacteristic:AVMediaCharacteristicContainsHDRVideo]){
// Process HDR track
}