xcode ios查看视频是否为hdr

在苹果开发者网站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
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值