C实现NV12转I420
生活随笔
收集整理的這篇文章主要介紹了
C实现NV12转I420
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
功能
將NV12的視頻序列轉換至I420格式
代碼
#include<iostream> #include<stdint.h>int main(int argc, char* argv[]) {char const* input;char const* output;input = argv[1];//輸入NV12序列路徑int num_frame = atoi(argv[2]);//處理幀數uint64_t w = atoi(argv[3]);//寬uint64_t h = atoi(argv[4]);//高output = argv[5];//輸出I420序列路徑int i = 1;uint8_t* buffer[3];buffer[0] = (uint8_t*)malloc(w * h);buffer[1] = (uint8_t*)malloc((w >> 1) * (h >> 1));buffer[2] = (uint8_t*)malloc((w >> 1) * (h >> 1));FILE* fp;fopen_s(&fp, input, "rb+");FILE* fp1;fopen_s(&fp1, output, "wb+");while (i <= num_frame) {fread(buffer[0], 1, w * h, fp);for (int i = 0; i < (h >> 1); i++) {for (int j = 0; j < (w >> 1); j++) {fread(&buffer[1][i * (w >> 1) + j], 1, 1, fp);fread(&buffer[2][i * (w >> 1) + j], 1, 1, fp);}}fwrite(buffer[0], 1, w * h, fp1);fwrite(buffer[1], 1, (w >> 1) * (h >> 1), fp1);fwrite(buffer[2], 1, (w >> 1) * (h >> 1), fp1);i++;}fclose(fp1);fclose(fp);free(buffer);return 0; }使用方法
1、利用VS生成exe可執行文件。
2、利用bat文件調用exe,在bat文件中按順序輸入相關參數,參數之間用空格分開。
bat文件示例
NV12to420.exe D:\4K_NV12\nightLab_3840x2160_iso3200_8bit_30fps_850f_nv12.yuv 850 3840 2160 D:\4K_I420\nightLab_3840x2160_iso3200_8bit_30fps_850f_I420.yuv總結
以上是生活随笔為你收集整理的C实现NV12转I420的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三星note9刷android11,【极
- 下一篇: webstorm控制台中文乱码解决