X264支援輸入NV12格式

來源:互聯網
上載者:User

標籤:x264   nv12   264編碼   yv12   

X264支援輸入NV12格式

一般編碼器(例如JM)輸入格式是YUV420(YV12),H.264標準也介紹的是YUV420的輸入。X264編碼器的輸入也一般是YUV420格式,但是在內部幀的儲存方式上x264採用的是NV12。因為一般編碼器對U,V兩通道的處理方式是相同的,例如他們有相同的QP,宏塊劃分,參考幀ID,運動向量。因此對於U,V兩通道的資料讀取是一致的,這樣NV12 UV兩通道交織儲存比YV12 UV兩通道分別儲存在資料訪問上具有更高的效率。基於這樣的考慮,x264內部幀(包括輸入編碼幀,參考幀)採用了NV12的儲存方式。對於YUV422的輸入採用NV16的格式
函數 int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )裡面會將src->img.i_csp 轉換成NV12等相對應的儲存格式。
輸入                         輸出  
NV12, I420, YV12          => NV12
NV16, I422, YV16, V210    => NV16
I444, YV24,BGR,BGRA,RGB => I444

因此x264可以直接輸入NV12的視頻資料格式(一些移動端網路攝影機的輸出為NV12),並且比輸入YUV420的效率還更高一些。
具體代碼為:

    x264_picture_init( &pH264Enc->pic );
    if(chroma_fmt == X264_CSP_NV12){
        pH264Enc->pic.img.i_stride[0] = pH264Enc->param.i_width;
        pH264Enc->pic.img.i_stride[1] = pH264Enc->param.i_width;
        pH264Enc->pic.img.i_stride[2] = 0;
        pH264Enc->pic.img.i_csp = X264_CSP_NV12;
        pH264Enc->pic.img.i_plane = 2;
    } else {  // 其他暫認為都是YUV420格式
        pH264Enc->pic.img.i_stride[0] = pH264Enc->param.i_width;
        pH264Enc->pic.img.i_stride[1] = pH264Enc->param.i_width>>1;
        pH264Enc->pic.img.i_stride[2] = pH264Enc->param.i_width>>1;
        pH264Enc->pic.img.i_csp = X264_CSP_I420;
        pH264Enc->pic.img.i_plane = 3;
    }

附上x264 CSP格式定義:
#define X264_CSP_MASK           0x00ff  /* */
#define X264_CSP_NONE           0x0000  /* Invalid mode     */
#define X264_CSP_I420           0x0001  /* yuv 4:2:0 planar */
#define X264_CSP_YV12           0x0002  /* yvu 4:2:0 planar */
#define X264_CSP_NV12           0x0003  /* yuv 4:2:0, with one y plane and one packed u+v */
#define X264_CSP_I422           0x0004  /* yuv 4:2:2 planar */
#define X264_CSP_YV16           0x0005  /* yvu 4:2:2 planar */
#define X264_CSP_NV16           0x0006  /* yuv 4:2:2, with one y plane and one packed u+v */
#define X264_CSP_V210           0x0007  /* 10-bit yuv 4:2:2 packed in 32 */
#define X264_CSP_I444           0x0008  /* yuv 4:4:4 planar */
#define X264_CSP_YV24           0x0009  /* yvu 4:4:4 planar */
#define X264_CSP_BGR            0x000a  /* packed bgr 24bits   */
#define X264_CSP_BGRA           0x000b  /* packed bgr 32bits   */
#define X264_CSP_RGB            0x000c  /* packed rgb 24bits   */
#define X264_CSP_MAX            0x000d  /* end of list */
#define X264_CSP_VFLIP          0x1000  /* the csp is vertically flipped */
#define X264_CSP_HIGH_DEPTH     0x2000  /* the csp has a depth of 16 bits per pixel component */

X264支援輸入NV12格式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.