GStreamer的x264enc插件支持RGB色彩空间

1、找到gstreamer中x264当前支持的色彩空间类型的代码

static gboolean

gst_x264_enc_add_x264_chroma_format (GstStructure * s,

    gboolean allow_420_8, gboolean allow_420_10, gboolean allow_422,

    gboolean allow_444)

{

  GValue fmts = G_VALUE_INIT;

  GValue fmt = G_VALUE_INIT;

  gboolean ret = FALSE;

  g_value_init (&fmts, GST_TYPE_LIST);

  g_value_init (&fmt, G_TYPE_STRING);



  if (vtable_8bit) {

    gint chroma_format = *vtable_8bit->x264_chroma_format;



    if ((chroma_format == 0 || chroma_format == X264_CSP_I444) && allow_444) {

      g_value_set_string (&fmt, "Y444");

      gst_value_list_append_value (&fmts, &fmt);

    }



    if ((chroma_format == 0 || chroma_format == X264_CSP_I422) && allow_422) {

      g_value_set_string (&fmt, "Y42B");

      gst_value_list_append_value (&fmts, &fmt);

    }



    if ((chroma_format == 0 || chroma_format == X264_CSP_I420) && allow_420_8) {

      g_value_set_string (&fmt, "I420");

      gst_value_list_append_value (&fmts, &fmt);

      g_value_set_string (&fmt, "YV12");

      gst_value_list_append_value (&fmts, &fmt);

      g_value_set_string (&fmt, "NV12");

      gst_value_list_append_value (&fmts, &fmt);

    }

  }



  if (vtable_10bit) {

    gint chroma_format = *vtable_10bit->x264_chroma_format;

    if ((chroma_format == 0 || chroma_format == X264_CSP_I444) && allow_444) {

      if (G_BYTE_ORDER == G_LITTLE_ENDIAN)

        g_value_set_string (&fmt, "Y444_10LE");

      else

        g_value_set_string (&fmt, "Y444_10BE");





      gst_value_list_append_value (&fmts, &fmt);

    }



    if ((chroma_format == 0 || chroma_format == X264_CSP_I422) && allow_422) {

      if (G_BYTE_ORDER == G_LITTLE_ENDIAN)

        g_value_set_string (&fmt, "I422_10LE");

      else

        g_value_set_string (&fmt, "I422_10BE");





      gst_value_list_append_value (&fmts, &fmt);

    }



    if ((chroma_format == 0 || chroma_format == X264_CSP_I420) && allow_420_10) {

      if (G_BYTE_ORDER == G_LITTLE_ENDIAN)

        g_value_set_string (&fmt, "I420_10LE");

      else

        g_value_set_string (&fmt, "I420_10BE");



      gst_value_list_append_value (&fmts, &fmt);

    }

  }



  if (gst_value_list_get_size (&fmts) != 0) {

    gst_structure_take_value (s, "format", &fmts);

    ret = TRUE;

  } else {

    g_value_unset (&fmts);

  }



  g_value_unset (&fmt);

  return ret;

}

2、增加如下代码

if ((chroma_format == 0 || chroma_format ==X264_CSP_RGB) && allow_RGB_32) {

      g_value_set_string (&fmt, "RGB32");

      gst_value_list_append_value (&fmts, &fmt);

    }

3、还需要确定你的x264库是不是支持

/* Colorspace type */

#define X264_CSP_MASK           0x00ff  /* */

#define X264_CSP_NONE           0x0000  /* Invalid mode     */

#define X264_CSP_I400           0x0001  /* monochrome 4:0:0 */

#define X264_CSP_I420           0x0002  /* yuv 4:2:0 planar */

#define X264_CSP_YV12           0x0003  /* yvu 4:2:0 planar */

#define X264_CSP_NV12           0x0004  /* yuv 4:2:0, with one y plane and one packed u+v */

#define X264_CSP_NV21           0x0005  /* yuv 4:2:0, with one y plane and one packed v+u */

#define X264_CSP_I422           0x0006  /* yuv 4:2:2 planar */

#define X264_CSP_YV16           0x0007  /* yvu 4:2:2 planar */

#define X264_CSP_NV16           0x0008  /* yuv 4:2:2, with one y plane and one packed u+v */

#define X264_CSP_YUYV           0x0009  /* yuyv 4:2:2 packed */

#define X264_CSP_UYVY           0x000a  /* uyvy 4:2:2 packed */

#define X264_CSP_V210           0x000b  /* 10-bit yuv 4:2:2 packed in 32 */

#define X264_CSP_I444           0x000c  /* yuv 4:4:4 planar */

#define X264_CSP_YV24           0x000d  /* yvu 4:4:4 planar */

#define X264_CSP_BGR            0x000e  /* packed bgr 24bits */

#define X264_CSP_BGRA           0x000f  /* packed bgr 32bits */

#define X264_CSP_RGB            0x0010  /* packed rgb 24bits */

#define X264_CSP_MAX            0x0011  /* 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 */

你可能感兴趣的:(GStreamer,GStreamer)