gpt4 book ai didi

macos - 如何调试 Mac OS 不使用硬件 H264 编码器的原因

转载 作者:行者123 更新时间:2023-12-01 07:35:53 24 4
gpt4 key购买 nike

我正在尝试使用 H264 编码一些仅视频流,并且我愿意使用硬件编码器来比较硬件和 CPU 编码之间的质量和资源消耗。问题是我无法强制操作系统使用硬件编码器。

这是我用来创建 VTCompressionSession 的代码:

var status: OSStatus

let encoderSpecifications: CFDictionary? = [
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder as String: true,
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder as String: true,
kVTVideoEncoderSpecification_EncoderID as String: "com.apple.videotoolbox.videoencoder.24rgb" // Tried without this paramenter so the system can decide what encoder ID should be using but doesn't work anyway.
]

let pixelBufferOptions: CFDictionary? = [
kCVPixelBufferWidthKey as String: Int(width),
kCVPixelBufferHeightKey as String: Int(height),
kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_24RGB) // Tried commenting this in case that there was a pixelformat constraint but didn't change anything
];

status = VTCompressionSessionCreate(kCFAllocatorDefault, width, height, CMVideoCodecType(kCMVideoCodecType_H264), encoderSpecifications, pixelBufferOptions, nil, { (outputCallbackRefCon: UnsafeMutablePointer<Void>, sourceFrameRefCon: UnsafeMutablePointer<Void>, status: OSStatus, infoFlags: VTEncodeInfoFlags, sampleBuffer: CMSampleBuffer?) -> Void in
...
}, unsafeBitCast(self, UnsafeMutablePointer<Void>.self), &compressionSession)

我打开了控制台,这是我尝试创建 session 时收到的唯一相关消息:
10/28/15 22:06:27.711 Dupla-Mac[87762]: <<<< VTVideoEncoderSelection >>>> VTSelectAndCreateVideoEncoderInstanceInternal: no video encoder found for 'avc1'

这是我在使用 EncoderID 时得到的状态代码:
2015-10-28 22:17:13.480 Dupla-Mac[87895:5578917] Couldn't create compression session :( -12908

这是我不使用 EncoderID 时得到的:
2015-10-28 22:18:16.695 Dupla-Mac[87996:5581914] Couldn't create compression session :( -12915

两者都与资源缺乏可用性有关,但找不到任何区别。我已经检查过可能使用硬件编码器的最著名的功能已关闭,但我不知道如何确定地检查这一点。 AirPlay 关闭,QuickTime 关闭,没有任何应用程序访问相机,等等。

TL;DR:有没有办法强制或知道操作系统使用什么策略来启用硬件编码器,并最终知道为什么它在任何时候都不可用?

提前致谢!

最佳答案

我想你已经解决了这个问题,但对于其他人 - macOS 上唯一可用的硬件加速编码器(10.8-10.12 适用于所有 mac 2012+)/iOS(8-10)是 com.apple.videotoolbox.videoencoder.h264.gva这是完整列表:https://gist.github.com/vade/06ace2e33561a79cc240

关于macos - 如何调试 Mac OS 不使用硬件 H264 编码器的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33404418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com