YUV/RGB數據存儲本地

static int flag =0;

FILE*fp;

static void dumpYuvPixelBuffer(CVPixelBufferRefpixelBuffer) {

? ? if(flag<10) {

? ? ? ? NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

? ? ? ? NSString*documentsDirectory = [pathsobjectAtIndex:0];

? ? ? ? NSString*filePath = [documentsDirectorystringByAppendingPathComponent:@"/hdrinput.yuv"];

? ? ? ? if(flag==0) {

? ? ? ? ? ? fp=fopen([filePathUTF8String],"wb+");

? ? ? ? }

? ? ? ? CVPixelBufferLockBaseAddress(pixelBuffer, 0);

? ? ? ? size_tcount =CVPixelBufferGetPlaneCount(pixelBuffer);

//? ? ? ? NSMutableData *data = [NSMutableData data];

? ? ? ? for(inti =0; i < count; i++) {

? ? ? ? ? ? size_twidth =CVPixelBufferGetWidthOfPlane(pixelBuffer, i);

? ? ? ? ? ? size_theight =CVPixelBufferGetHeightOfPlane(pixelBuffer, i);

? ? ? ? ? ? size_tbytesPerRow =CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, i);

? ? ? ? ? ? void* buf =CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, i);

? ? ? ? ? ? //? ? ? ? ? ? NSData *Data = [NSData dataWithBytes:buf length:bytesPerRow * height];

? ? ? ? ? ? fwrite(buf,1, bytesPerRow * height,fp);

? ? ? ? ? ? fflush(fp);

? ? ? ? ? ? //? ? ? ? ? ? [data appendData:Data];

? ? ? ? }

//? ? ? ? [data writeToFile:filePath atomically:YES];

? ? ? ? CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

? ? ? ? flag+=1;

? ? }

? }

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容