[vlc-devel] [PATCH 1/1] daala: add support for 422 and 444

Tristan Matthews le.businessman at gmail.com
Fri Sep 26 01:04:45 CEST 2014


Somewhat borrowed from schroedinger.

---
 modules/codec/daala.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/modules/codec/daala.c b/modules/codec/daala.c
index 9d66d7a..068a9a6 100644
--- a/modules/codec/daala.c
+++ b/modules/codec/daala.c
@@ -95,6 +95,13 @@ static void daala_CopyPicture( picture_t *, od_img * );
 static int  OpenEncoder( vlc_object_t *p_this );
 static void CloseEncoder( vlc_object_t *p_this );
 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
+
+static const char *const enc_chromafmt_list[] = {
+    "420", "422", "444"
+};
+static const char *const enc_chromafmt_list_text[] = {
+    N_("4:2:0"), N_("4:2:2"), N_("4:4:4")
+};
 #endif
 
 /*****************************************************************************
@@ -133,12 +140,20 @@ vlc_module_begin ()
                  ENC_QUALITY_TEXT, ENC_QUALITY_LONGTEXT, false )
     add_integer_with_range( ENC_CFG_PREFIX "keyint", 256, 1, 1000,
                  ENC_KEYINT_TEXT, ENC_KEYINT_LONGTEXT, false )
-#endif
+
+#   define ENC_CHROMAFMT_TEXT N_("Chroma format")
+#   define ENC_CHROMAFMT_LONGTEXT N_("Picking chroma format will force a " \
+                                     "conversion of the video into that format")
+
+    add_string( ENC_CFG_PREFIX "chroma-fmt", "420", ENC_CHROMAFMT_TEXT,
+                ENC_CHROMAFMT_LONGTEXT, false )
+    change_string_list( enc_chromafmt_list, enc_chromafmt_list_text )
 vlc_module_end ()
 
 static const char *const ppsz_enc_options[] = {
-    "quality", "keyint", NULL
+    "quality", "keyint", "chroma-fmt", NULL
 };
+#endif
 
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
@@ -551,6 +566,23 @@ struct encoder_sys_t
     daala_enc_ctx   *dcx;                   /* daala context */
 };
 
+static void SetEncChromaFormat( encoder_t *p_enc, uint32_t i_codec )
+{
+    p_enc->fmt_in.i_codec = i_codec;
+
+    switch( i_codec ) {
+    case VLC_CODEC_I420:
+        p_enc->fmt_in.video.i_bits_per_pixel = 12;
+        break;
+    case VLC_CODEC_I422:
+        p_enc->fmt_in.video.i_bits_per_pixel = 16;
+        break;
+    case VLC_CODEC_I444:
+        p_enc->fmt_in.video.i_bits_per_pixel = 24;
+        break;
+    }
+}
+
 static int OpenEncoder( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t *)p_this;
@@ -576,6 +608,31 @@ static int OpenEncoder( vlc_object_t *p_this )
 
     config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
 
+    char *psz_tmp = var_GetString( p_enc, ENC_CFG_PREFIX "chroma-fmt" );
+    uint32_t i_codec;
+    if( !psz_tmp ) {
+        free(p_sys);
+        return VLC_ENOMEM;
+    } else {
+        if( !strcmp( psz_tmp, "420" ) ) {
+            i_codec = VLC_CODEC_I420;
+        }
+        else if( !strcmp( psz_tmp, "422" ) ) {
+            i_codec = VLC_CODEC_I422;
+        }
+        else if( !strcmp( psz_tmp, "444" ) ) {
+            i_codec = VLC_CODEC_I444;
+        }
+        else {
+            msg_Err( p_enc, "Invalid chroma format: %s", psz_tmp );
+            free( psz_tmp );
+            free( p_sys );
+            return VLC_EGENERIC;
+        }
+        free( psz_tmp );
+        SetEncChromaFormat( p_enc, i_codec );
+    }
+
     daala_info_init( &p_sys->di );
 
     p_sys->di.pic_width = p_enc->fmt_in.video.i_visible_width;
@@ -585,8 +642,9 @@ static int OpenEncoder( vlc_object_t *p_this )
     p_sys->di.nplanes = 3;
     for (int i = 0; i < p_sys->di.nplanes; i++)
     {
-        p_sys->di.plane_info[i].ydec =
-        p_sys->di.plane_info[i].xdec = i > 0;
+        p_sys->di.plane_info[i].xdec = i > 0 && i_codec != VLC_CODEC_I444;
+        p_sys->di.plane_info[i].ydec = i_codec == VLC_CODEC_I420 ?
+            p_sys->di.plane_info[i].xdec : 0;
     }
     p_sys->di.frame_duration = 1;
 
-- 
1.9.3




More information about the vlc-devel mailing list