【问题标题】:Can I get PHAsset / AVAsset is hdr video/dolby vision on iphone12?我可以在 iphone12 上获取 PHAsset / AVAsset 是 hdr 视频/杜比视觉吗?
【发布时间】:2020-10-24 06:14:11
【问题描述】:

我想添加 HDR 图标以指示某些资产是 HDR,但如果这是来自 iphone12 的 HDR 视频记​​录,我无法获得任何信息来检查视频

【问题讨论】:

    标签: ios objective-c avfoundation photo


    【解决方案1】:

    更好的方法是使用 avasset.tracks(withMediaCharacteristic: .containsHDRVideo) 或者 simpleVideo.tracks.forEach{$0.hasMediaCharacteristic(.containsHDRVideo)}

    【讨论】:

      【解决方案2】:
      + (BOOL)isHDRVideo:(AVAsset *)avasset {
          if (!avasset) {
              return NO;
          }
          __block BOOL isHDRVideo = NO;
          [avasset.tracks enumerateObjectsUsingBlock:^(AVAssetTrack * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stopTracks) {
              [obj.formatDescriptions enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stopFormatDescriptions) {
                  CMFormatDescriptionRef desc = (__bridge  CMVideoFormatDescriptionRef)obj;
                  NSDictionary *dic = (__bridge NSDictionary *)CMFormatDescriptionGetExtensions(desc);
                  NSString *imageBufferColorPrimaries = dic[(__bridge  id)kCVImageBufferColorPrimariesKey];
                  if ([imageBufferColorPrimaries isEqualToString:(__bridge  id)kCVImageBufferColorPrimaries_ITU_R_2020]) {
                      *stopFormatDescriptions = YES;
                      *stopTracks = YES;
                      isHDRVideo = YES;
                  }
              }];
          }];
          
          return isHDRVideo;
      }
      

      【讨论】:

        【解决方案3】:

        这篇文章真的帮助了我,所以我觉得我必须分享我发现的内容,以便为未来的读者提供一种基于快速的方法。

        可以扩展AVAssetTrack 以移动定义CMFormatDescription 的所有逻辑:

        
        public extension AVAssetTrack {
          var isHDRVideo: Bool {
            guard
              self.mediaType == .video, // If is not a video track is not HDR
              let cmFormatDescription = self.formatDescriptions.map { $0 as!  CMFormatDescription }.first, // Safely get the description
              let transferFunction = CMFormatDescriptionGetExtension(
                cmFormatDescription,
                extensionKey: kCVImageBufferTransferFunctionKey), // It can be nil, which will make the as! CFString fail
            else { return false }
        
            return [
              kCVImageBufferTransferFunction_ITU_R_2020,
              kCVImageBufferTransferFunction_ITU_R_2100_HLG,
              kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ
            ].contains(transferFunction as! CFString)
          }
        }
        
        

        然后说你有一个AVAssetasset,你可以这样做:

        asset.tracks(withMediaType: .video).map { $0.isHDRVideo }
        

        并以此为基础构建你的逻辑。

        【讨论】:

          猜你喜欢
          • 2015-12-25
          • 2020-02-02
          • 1970-01-01
          • 2017-02-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-05-15
          相关资源
          最近更新 更多