X264 support for Input NV12 format

Source: Internet
Author: User
Tags format definition

X264 support for Input NV12 format

The General encoder (for example JM) input format is YUV420 (YV12), the H. S standard also introduces YUV420 input. The input of the X264 encoder is also generally in the YUV420 format, but x264 is NV12 in the way the internal frames are stored. Because the general encoder handles u,v two channels the same way, for example they have the same QP, macro block division, reference frame ID, motion vector. As a result, the data reads of the U,V two channel are consistent so that NV12 UV two-channel interleaved storage is more efficient than YV12 UV two channels stored separately on data access. Based on this consideration, the x264 internal frames (including input-encoded frames, reference frames) are stored in a NV12 manner. Input for YUV422 in NV16 format
the function int x264_frame_copy_picture (x264_t *h, x264_frame_t *dst, x264_picture_t *src) will SRC->IMG.I_CSP Convert to NV12 and other corresponding storage formats.
Input/Output
NV12, I420, YV12 = NV12
NV16, I422, YV16, V210 = NV16
I444, Yv24,bgr,bgra,rgb = I444

So x264 can directly input the NV12 video data format (some mobile camera output is NV12), and more efficient than the input YUV420.
The specific code is:

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 {//other temporarily considered to be YUV420 format
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;
}

Attach the x264 CSP format definition:
#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 the bits per pixel component */

X264 support for Input NV12 format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.