NV12截图
截圖原理參考:
從NV12中裁剪子畫面注意事項
這是源碼:
//裁剪的坐標X和Y必須是偶數,否則UV和Y會有偏差, 注意點,linesize對其為1 int NV12CropTo420P(uint8_t *nv12data, int width, int height, int cropx,int cropy, uint8_t *yuv420pdata, int dscw, int dsch) {uint8_t *ptry = yuv420pdata, *ptru, *ptrv;uint8_t *nvptr = nv12data + width * height;ptry = yuv420pdata;ptru = yuv420pdata + dscw * dsch; //uptrv = yuv420pdata + dscw * dsch + (dscw * dsch) / 4; //vfor (int y = cropy; y < dsch + cropy /*pFrame->height*/; y++) {memcpy(ptry, nv12data + y * width + cropx, dscw);ptry += dscw;}for (int nvy = cropy / 2; nvy < dsch / 2 + cropy / 2 /*height / 2*/;nvy++) {//-----w-----//Y Y Y Y//Y Y Y Y//Y Y Y Y//Y Y Y Y//U V U V//U V U Vfor (int nvx = cropx; nvx < dscw + cropx; nvx++) {//如果目標是ffmpeg的avframe則需要注意的是linesizeif (nvx % 2 == 0) {*ptru++ = nvptr[nvy * width + nvx]; //u} else {*ptrv++ = nvptr[nvy * width + nvx]; //v}}}return 0; }//-----w-----
//Y00 Y01 Y02 Y03
//Y10 Y11 Y12 Y13
//Y20 Y21 Y22 Y23
//Y30 Y31 Y32 Y33
//U00 V01 U02 V03
//U10 V11 U12 V13
YUV對應關系為:
Y00 Y01
Y10 Y11
U00 V01
總結
- 上一篇: 使用Python基于BibTeX引用格式
- 下一篇: 浏览器对URL的长度限制