gpt4 book ai didi

ios - 如何为 VTCompressionSession 设置比特率

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:25 26 4
gpt4 key购买 nike

我正在努力将我们的应用程序从一些专有编解码器转移到 iOS 原生 h264 编码器 (VideoToolbox.framework) 并有问题:

是否存在为压缩数据设置比特率或数据率的方法?

这是我创建编码器 session 的方式:

CFMutableDictionaryRef sessionAttributes = CFDictionaryCreateMutable(
NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);

//** bitrate
int fixedBitrate = bitrate; // 2000 * 1024 -> assume 2 Mbits/s

CFNumberRef bitrateNum = CFNumberCreate(NULL, kCFNumberSInt32Type, &fixedBitrate);
CFDictionarySetValue(sessionAttributes, kVTCompressionPropertyKey_AverageBitRate, bitrateNum);
CFRelease(bitrateNum);

CFDictionarySetValue(sessionAttributes, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_H264_High_AutoLevel);

CFDictionarySetValue(sessionAttributes, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue);

OSStatus error = VTCompressionSessionCreate(kCFAllocatorDefault,
width,
height,
kCMVideoCodecType_H264,
sessionAttributes,
NULL,
kCFAllocatorDefault,
&EncoderCallback,
this, *outputCallbackRefCon,
&m_EncoderSession);

我玩了很多 kVTCompressionPropertyKey_AverageBitRate 的不同值,但这对我没有任何作用,我也尝试了 kVTCompressionPropertyKey_DataRateLimits 不同的值,但也没有任何运气。

欢迎任何想法,建议

最佳答案

简而言之,您需要在创建 session 后使用 VTSessionSetProperty

您作为第五个参数传入的字典实际上用于指定要使用的编码器,而不是编码器设置。这有点令人困惑,但 Apple 文档指出:

To specify a particular video encoder when creating a compression session, pass an encoderSpecification CFDictionary containing this key and the EncoderID as its value. The EncoderID CFString may be obtained from the kVTVideoEncoderList_EncoderID entry in the array returned by VTCopyVideoEncoderList.

在使用 VTSessionSetProperty 函数创建 session 后,您需要设置 kVTCompressionPropertyKey_AverageBitRatekVTCompressionPropertyKey_DataRateLimits 属性。

例如:

 status = VTSessionSetProperty(session, kVTCompressionPropertyKey_AverageBitRate, (__bridge CFTypeRef)@(600 * 1024));
status = VTSessionSetProperty(session, kVTCompressionPropertyKey_DataRateLimits, (__bridge CFArrayRef)@[800 * 1024 / 8, 1]);

请记住,kVTCompressionPropertyKey_AverageBitRate 需要位,kVTCompressionPropertyKey_DataRateLimits 需要字节和秒。

关于ios - 如何为 VTCompressionSession 设置比特率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31458150/

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