我现在正在使用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;
使用它们的正确方法是什么?
希望有人能告诉我。谢谢你的时间!
答案 0 :(得分:0)
来自kvtcompressionpropertykey_dataratelimits的文件说:
每个硬限制由数据大小(以字节为单位)和a来描述 持续时间以秒为单位......
因此,您需要使用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);