2017-03-23 133 views
1

我現在使用Videotoolbox來處理h.264編碼。如何調整Videotoolbox的屬性?

而且我發現了一個示例代碼,它工作正常:

#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

kvtcompressionpropertykey_dataratelimits文件說:

每個硬性限制由字節的數據大小,以秒爲 持續時間描述...

因此,你需要設置這個屬性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); 
+0

Apple發佈了關於[kVTCompressionPropertyKey_Data RateLimits](https://developer.apple.com/library/content/qa/qa1958/_index.html#//apple_ref/doc/uid/DTS40017665)屬性。 –