如何调整 Videotoolbox 中的属性?

How to adjust properties in Videotoolbox?

我现在正在使用Videotoolbox来处理h.264编码。

我找到了一个示例代码,它运行良好:

    #define VTB_HEIGHT 480
    #define VTB_WIDTH 640

    int bitRate = VTB_WIDTH * VTB_HEIGHT * 3 * 4 * 8;

    CFNumberRef bitRateRef = CFNumberCreate(kCFAllocatorDefault,
                                            kCFNumberSInt32Type,
                                            &bitRate);

    VTSessionSetProperty(encodingSession,
                         kVTCompressionPropertyKey_AverageBitRate,
                         bitRateRef);

    CFRelease(bitRateRef);


    int bitRateLimit = bitRate / 8;

    CFNumberRef bitRateLimitRef = CFNumberCreate(kCFAllocatorDefault,
                                                 kCFNumberSInt32Type,
                                                 &bitRateLimit);

    VTSessionSetProperty(encodingSession,
                         kVTCompressionPropertyKey_DataRateLimits,
                         bitRateLimitRef);

    CFRelease(bitRateLimitRef);

但是这两行,我没看懂:

int bitRate = VTB_WIDTH * VTB_HEIGHT * 3 * 4 * 8;

int bitRateLimit = bitRate / 8;

正确的使用方法是什么?

希望有人能告诉我。

感谢您的宝贵时间!

kvtcompressionpropertykey_dataratelimits的文档说:

Each hard limit is described by a data size in bytes and a duration in seconds...

因此您需要使用 2 个参数设置此 属性(以字节为单位的数据大小,以秒为单位的持续时间)

int bitRate = VTB_WIDTH * VTB_HEIGHT * 3 * 4 * 8; 
int bitRateLimit = bitRate / 8; 

// that's say we set data in byte/second
CFNumberRef byteNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bitRateLimit);
int second = 1;
CFNumberRef secNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &second);

// add parameters into a array
const void* numbers[2] = {byteNum, secNum};
CFArrayRef dataRateLimits = CFArrayCreate(NULL, numbers, 2, &kCFTypeArrayCallBacks);

// then set property with array
status = VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_DataRateLimits, arrayValues);