怎样查看macOS支持的硬件编解码器信息

已知macOS支持H.264和H.265编解码器,但是像VP9在某个设备上是否支持未知。很奇怪macOS上找不到一个现成的工具,能够查看支持哪些视频编解码格式。于是我翻了一通Apple videotoolbox文档,用swift做了一个小工具。

1. 查看解码支持情况


import VideoToolbox

func listVideoDecoders() {
    let codecTypes: [CMVideoCodecType: String] = [
        kCMVideoCodecType_H264: "H.264",
        kCMVideoCodecType_HEVC: "H.265",
        kCMVideoCodecType_HEVCWithAlpha: "H.265 alpha",
        kCMVideoCodecType_DolbyVisionHEVC: "H.265 dolby vision",
        kCMVideoCodecType_AV1: "AV1",
        kCMVideoCodecType_VP9: "VP9",
    ]

    for (codecType, codecName) in codecTypes {
        VTRegisterSupplementalVideoDecoderIfAvailable(codecType)
        let isSupported = VTIsHardwareDecodeSupported(codecType)
        if isSupported {
            print("Hardware decoder available for codec: \(codecName)")
        } else {
            print("Hardware decoder not available for codec: \(codecName)")
        }
    }
}

listVideoDecoders()

只涉及两个API:

  • VTIsHardwareDecodeSupported 查看是否支持某个格式的硬件解码
  • VTRegisterSupplementalVideoDecoderIfAvailable 注册补充的解码器。在我的设备上,调用VTRegisterSupplementalVideoDecoderIfAvailable 之后才支持VP9

另外,上面可以看到,Apple把H.265 alpha和H.265 dolby vision当成独立的解码器类型列出来了。

编译和运行:


$ swiftc vt_list.swift -o vt_list
$ ./vt_list

Hardware decoder available for codec: H.265 dolby vision
Hardware decoder available for codec: H.265 alpha
Hardware decoder not available for codec: AV1
Hardware decoder available for codec: VP9
Hardware decoder available for codec: H.264
Hardware decoder available for codec: H.265

2. 查看编码器


func fourCCToString(_ fourCC: CMVideoCodecType) -> String {
    let bytes: [CChar] = [
        CChar((fourCC >> 24) & 0xFF),
        CChar((fourCC >> 16) & 0xFF),
        CChar((fourCC >> 8) & 0xFF),
        CChar(fourCC & 0xFF),
        0
    ]
    return String(cString: bytes)
}

func listVideoEncoders() {
    var encoderList: CFArray?
    let encoderListOptions: [NSString: Any] = [
        kVTVideoEncoderList_CodecType: true as NSNumber,
        kVTVideoEncoderList_EncoderID: true as NSNumber,
        kVTVideoEncoderList_DisplayName: true as NSNumber,
        kVTVideoEncoderList_CodecName: true as NSNumber,
    ]
    
    let status = VTCopyVideoEncoderList(encoderListOptions as CFDictionary, &encoderList)
    
    if status == noErr, let encoders = encoderList as? [[NSString: Any]] {
        for encoder in encoders {
            if let codecType = encoder[kVTVideoEncoderList_CodecType] as? CMVideoCodecType,
               let codecName = encoder[kVTVideoEncoderList_CodecName] as? String,
               let displayName = encoder[kVTVideoEncoderList_DisplayName] as? String,
               let encoderID = encoder[kVTVideoEncoderList_EncoderID] as? String {
                let fourCCString = fourCCToString(codecType)
                print("Codec Type: \(codecType) (\(fourCCString)), Codec Name: \(codecName), Display Name: \(displayName), Encoder ID: \(encoderID)")
            }
        }
    } else {
        print("Failed to retrieve encoder list.")
    }
}

listVideoEncoders()
  • 用VTCopyVideoEncoderList() 获取编码器列表
  • CMVideoCodecType是个整型,打印它的数值没有什么可读性,它的数值背后实际上是按照fourcc定义的,所以我们通过fourCCToString打印出来

以下运行结果仅供参考:


Codec Type: 24 (), Codec Name: 24-bit RGB, Display Name: 24-bit RGB, Encoder ID: com.apple.videotoolbox.videoencoder.24rgb
Codec Type: 32 (), Codec Name: 32-bit ARGB, Display Name: 32-bit ARGB, Encoder ID: com.apple.videotoolbox.videoencoder.32argb
Codec Type: 1634755438 (apcn), Codec Name: Apple ProRes 422, Display Name: Apple ProRes 422, Encoder ID: com.apple.videotoolbox.videoencoder.prores-422
Codec Type: 1634755432 (apch), Codec Name: Apple ProRes 422 HQ, Display Name: Apple ProRes 422 HQ, Encoder ID: com.apple.videotoolbox.videoencoder.prores-422hq
Codec Type: 1634755443 (apcs), Codec Name: Apple ProRes 422 LT, Display Name: Apple ProRes 422 LT, Encoder ID: com.apple.videotoolbox.videoencoder.prores-422lt
Codec Type: 1634755439 (apco), Codec Name: Apple ProRes 422 Proxy, Display Name: Apple ProRes 422 Proxy, Encoder ID: com.apple.videotoolbox.videoencoder.prores-422proxy
Codec Type: 1634743400 (ap4h), Codec Name: Apple ProRes 4444, Display Name: Apple ProRes 4444, Encoder ID: com.apple.videotoolbox.videoencoder.prores-4444
Codec Type: 1634743416 (ap4x), Codec Name: Apple ProRes 4444 XQ, Display Name: Apple ProRes 4444 XQ, Encoder ID: com.apple.videotoolbox.videoencoder.prores-4444xq
Codec Type: 1634755438 (apcn), Codec Name: AppleProResHW 422, Display Name: AppleProResHW 422, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.422
Codec Type: 1634755432 (apch), Codec Name: AppleProResHW 422 HQ, Display Name: AppleProResHW 422 HQ, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.422hq
Codec Type: 1634755443 (apcs), Codec Name: AppleProResHW 422 LT, Display Name: AppleProResHW 422 LT, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.422lt
Codec Type: 1634755439 (apco), Codec Name: AppleProResHW 422 Proxy, Display Name: AppleProResHW 422 Proxy, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.422proxy
Codec Type: 1634743400 (ap4h), Codec Name: AppleProResHW 4444, Display Name: AppleProResHW 4444, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.4444
Codec Type: 1634743416 (ap4x), Codec Name: AppleProResHW 4444 XQ, Display Name: AppleProResHW 4444 XQ, Encoder ID: com.apple.videotoolbox.videoencoder.appleproreshw.4444xq
Codec Type: 1684369512 (deph), Codec Name: Depth, Display Name: Apple Depth (HEVC)-Apple HEVC (HW), Encoder ID: com.apple.videotoolbox.videoencoder.depth-hevc:com.apple.videotoolbox.videoencoder.ave.hevc
Codec Type: 1684369512 (deph), Codec Name: Depth, Display Name: Apple Depth (HEVC)-Apple HEVC (SW), Encoder ID: com.apple.videotoolbox.videoencoder.depth-hevc:com.apple.videotoolbox.videoencoder.hevc.vcp
Codec Type: 1684632424 (dish), Codec Name: Disparity, Display Name: Apple Disparity (HEVC)-Apple HEVC (HW), Encoder ID: com.apple.videotoolbox.videoencoder.disparity-hevc:com.apple.videotoolbox.videoencoder.ave.hevc
Codec Type: 1684632424 (dish), Codec Name: Disparity, Display Name: Apple Disparity (HEVC)-Apple HEVC (SW), Encoder ID: com.apple.videotoolbox.videoencoder.disparity-hevc:com.apple.videotoolbox.videoencoder.hevc.vcp
Codec Type: 1748121139 (h263), Codec Name: H.263, Display Name: H.263, Encoder ID: com.apple.videotoolbox.videoencoder.h263
Codec Type: 1635148593 (avc1), Codec Name: H.264, Display Name: Apple H.264 (HW), Encoder ID: com.apple.videotoolbox.videoencoder.ave.avc
Codec Type: 1635148593 (avc1), Codec Name: H.264, Display Name: Apple H.264 (SW), Encoder ID: com.apple.videotoolbox.videoencoder.h264
Codec Type: 1752589105 (hvc1), Codec Name: HEVC, Display Name: Apple HEVC (HW), Encoder ID: com.apple.videotoolbox.videoencoder.ave.hevc
Codec Type: 1752589105 (hvc1), Codec Name: HEVC, Display Name: Apple HEVC (SW), Encoder ID: com.apple.videotoolbox.videoencoder.hevc.vcp
Codec Type: 1785750887 (jpeg), Codec Name: JPEG, Display Name: Apple JPEG, Encoder ID: com.apple.videotoolbox.videoencoder.jpeg
Codec Type: 1785750887 (jpeg), Codec Name: JPEG, Display Name: JPEG (HW), Encoder ID: com.apple.videotoolbox.videoencoder.jpeg.ajpeg
Codec Type: 1836415073 (muxa), Codec Name: Muxed Alpha, Display Name: Apple Muxed Alpha-Apple HEVC (HW), Encoder ID: com.apple.videotoolbox.videoencoder.hevc-with-alpha:com.apple.videotoolbox.videoencoder.ave.hevc
Codec Type: 1836415073 (muxa), Codec Name: Muxed Alpha, Display Name: Apple Muxed Alpha-Apple HEVC (SW), Encoder ID: com.apple.videotoolbox.videoencoder.hevc-with-alpha:com.appl

可以看到,部分编码器既有硬件编码的实现,也有软件编码的实现。H.265编码器分了多个类型:

  • Apple HEVC 普通H.265
  • Apple Muxed Alpha-Apple HEVC 支持透明视频
  • Apple Depth (HEVC)-Apple HEVC
  • Apple Disparity (HEVC)-Apple HEVC

后面两个不清楚它们的应用场景。

作者:quink
来源:Fun With FFmpeg
原文:https://mp.weixin.qq.com/s/2Y3TAkXMiNq8E1HdzT3fLQ

版权声明:本文内容转自互联网,本文观点仅代表作者本人。本站仅提供信息存储空间服务,所有权归原作者所有。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至1393616908@qq.com 举报,一经查实,本站将立刻删除。

(0)

相关推荐

发表回复

登录后才能评论