]> git.sesse.net Git - vlc/blobdiff - modules/codec/x264.c
avcodec: Map IMA_QT
[vlc] / modules / codec / x264.c
index 11f290a24102bddae343466aba44897a10b94ec9..1b56c9454b022bc8b10f7e40f26c588dafc4a9e3 100644 (file)
 
 #include <assert.h>
 
+#ifdef MODULE_NAME_IS_x26410b
+#define SOUT_CFG_PREFIX "sout-x26410b-"
+#else
 #define SOUT_CFG_PREFIX "sout-x264-"
+#endif
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
+static void x264_log( void *, int i_level, const char *psz, va_list );
 
 /* Frame-type options */
 
@@ -152,6 +157,15 @@ static void Close( vlc_object_t * );
 #define INTERLACED_TEXT N_("Interlaced mode")
 #define INTERLACED_LONGTEXT N_( "Pure-interlaced mode.")
 
+#define FRAMEPACKING_TEXT N_("Frame packing")
+#define FRAMEPACKING_LONGTEXT N_( "For stereoscopic videos define frame arrangement:\n" \
+    " 0: checkerboard - pixels are alternatively from L and R\n" \
+    " 1: column alternation - L and R are interlaced by column\n" \
+    " 2: row alternation - L and R are interlaced by row\n" \
+    " 3: side by side - L is on the left, R on the right\n" \
+    " 4: top bottom - L is on top, R on bottom\n" \
+    " 5: frame alternation - one view per frame" )
+
 #define INTRAREFRESH_TEXT N_("Use Periodic Intra Refresh")
 #define INTRAREFRESH_LONGTEXT N_("Use Periodic Intra Refresh instead of IDR frames")
 
@@ -390,11 +404,11 @@ static void Close( vlc_object_t * );
     "Currently default can cause sync-issues on unmuxable output, like rtsp-output without ts-mux" )
 
 #define HRD_TEXT N_("HRD-timing information")
-#define HRD_LONGTEXT N_("HRD-timing information")
+#define TUNE_TEXT N_("Default tune setting used" )
+#define PRESET_TEXT N_("Default preset setting used" )
 
-#define TUNE_TEXT N_("Tune the settings for a particular type of source or situation. " \
-     "Overridden by user settings." )
-#define PRESET_TEXT N_("Use preset as default settings. Overridden by user settings." )
+#define X264_OPTIONS_TEXT N_("x264 advanced options.")
+#define X264_OPTIONS_LONGTEXT N_("x264 advanced options, in the form {opt=val,op2=val2} .")
 
 static const char *const enc_me_list[] =
   { "dia", "hex", "umh", "esa", "tesa" };
@@ -417,9 +431,19 @@ static const char *const direct_pred_list[] =
 static const char *const direct_pred_list_text[] =
   { N_("none"), N_("spatial"), N_("temporal"), N_("auto") };
 
+static const int const framepacking_list[] =
+  { -1, 0, 1, 2, 3, 4, 5 };
+static const char *const framepacking_list_text[] =
+  { "", N_("checkerboard"), N_("column alternation"), N_("row alternation"), N_("side by side"), N_("top bottom"), N_("frame alternation") };
+
 vlc_module_begin ()
+#ifdef MODULE_NAME_IS_x26410b
+    set_description( N_("H.264/MPEG4 AVC encoder (x264 10-bit)"))
+    set_capability( "encoder", 0 )
+#else
     set_description( N_("H.264/MPEG4 AVC encoder (x264)"))
     set_capability( "encoder", 200 )
+#endif
     set_callbacks( Open, Close )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_VCODEC )
@@ -498,12 +522,18 @@ vlc_module_begin ()
     add_bool( SOUT_CFG_PREFIX "interlaced", false, INTERLACED_TEXT, INTERLACED_LONGTEXT,
               true )
 
+#if X264_BUILD >= 111
+    add_integer( SOUT_CFG_PREFIX "frame-packing", -1, FRAMEPACKING_TEXT, FRAMEPACKING_LONGTEXT, true )
+        change_integer_list( framepacking_list, framepacking_list_text )
+        change_integer_range( -1, 5)
+#endif
+
     add_integer( SOUT_CFG_PREFIX "slices", 0, SLICE_COUNT, SLICE_COUNT_LONGTEXT, true )
     add_integer( SOUT_CFG_PREFIX "slice-max-size", 0, SLICE_MAX_SIZE, SLICE_MAX_SIZE_LONGTEXT, true )
     add_integer( SOUT_CFG_PREFIX "slice-max-mbs", 0, SLICE_MAX_MBS, SLICE_MAX_MBS_LONGTEXT, true )
 
 #if X264_BUILD >= 89
-    add_string( SOUT_CFG_PREFIX "hrd", "none", HRD_TEXT, HRD_LONGTEXT, true )
+    add_string( SOUT_CFG_PREFIX "hrd", "none", HRD_TEXT, HRD_TEXT, true )
         change_string_list( x264_nal_hrd_names, x264_nal_hrd_names, 0 );
 #endif
 
@@ -694,6 +724,9 @@ vlc_module_begin ()
     add_string( SOUT_CFG_PREFIX "tune", NULL , TUNE_TEXT, TUNE_TEXT, false )
         change_string_list( x264_tune_names, x264_tune_names, 0 );
 
+    add_string( SOUT_CFG_PREFIX "options", NULL, X264_OPTIONS_TEXT,
+                X264_OPTIONS_LONGTEXT, true )
+
 vlc_module_end ()
 
 /*****************************************************************************
@@ -713,7 +746,8 @@ static const char *const ppsz_sout_options[] = {
     "verbose", "vbv-bufsize", "vbv-init", "vbv-maxrate", "weightb", "weightp",
     "aq-mode", "aq-strength", "psy-rd", "psy", "profile", "lookahead", "slices",
     "slice-max-size", "slice-max-mbs", "intra-refresh", "mbtree", "hrd",
-    "tune","preset", "opengop", "bluray-compat", NULL
+    "tune","preset", "opengop", "bluray-compat", "frame-packing", "options",
+    NULL
 };
 
 static block_t *Encode( encoder_t *, picture_t * );
@@ -767,31 +801,53 @@ static int  Open ( vlc_object_t *p_this )
 
     p_enc->fmt_in.i_codec = VLC_CODEC_I420;
     p_sys->i_colorspace = X264_CSP_I420;
+#if X264_BUILD >= 118
     char *psz_profile = var_GetString( p_enc, SOUT_CFG_PREFIX "profile" );
     if( psz_profile )
     {
-#if X264_CSP_HIGH_DEPTH
-        int mask = x264_bit_depth > 8 ? X264_CSP_HIGH_DEPTH : 0;
-#else
-        int mask = 0;
+        const int mask = x264_bit_depth > 8 ? X264_CSP_HIGH_DEPTH : 0;
+
+#ifdef MODULE_NAME_IS_x26410b
+        if( mask == 0)
+        {
+            msg_Err( p_enc, "Only high bith depth encoding supported, bit depth:%d", x264_bit_depth);
+            return VLC_EGENERIC;
+        }
 #endif
+
         if( !strcmp( psz_profile, "high10" ) )
         {
             p_enc->fmt_in.i_codec = mask ? VLC_CODEC_I420_10L : VLC_CODEC_I420;
             p_sys->i_colorspace = X264_CSP_I420 | mask;
         }
-        if( !strcmp( psz_profile, "high422" ) )
+        else if( !strcmp( psz_profile, "high422" ) )
         {
             p_enc->fmt_in.i_codec = mask ? VLC_CODEC_I422_10L : VLC_CODEC_I422;
             p_sys->i_colorspace = X264_CSP_I422 | mask;
         }
-        if( !strcmp( psz_profile, "high444" ) )
+        else if( !strcmp( psz_profile, "high444" ) )
         {
             p_enc->fmt_in.i_codec = mask ? VLC_CODEC_I444_10L : VLC_CODEC_I444;
             p_sys->i_colorspace = X264_CSP_I444 | mask;
         }
+#ifdef MODULE_NAME_IS_x26410b
+        else
+        {
+            msg_Err( p_enc, "Only high-profiles and 10-bit are supported");
+            return VLC_EGENERIC;
+        }
+
+#endif
     }
+#ifdef MODULE_NAME_IS_x26410b
+    else
+    {
+            msg_Err( p_enc, "Only high-profiles and 10-bit are supported");
+            return VLC_EGENERIC;
+    }
+#endif
     free( psz_profile );
+#endif //X264_BUILD
 
     p_enc->pf_encode_video = Encode;
     p_enc->pf_encode_audio = NULL;
@@ -937,6 +993,11 @@ static int  Open ( vlc_object_t *p_this )
     if( fabs( var_GetFloat( p_enc, SOUT_CFG_PREFIX "aq-strength" ) - 1.0) > 0.005 )
        p_sys->param.rc.f_aq_strength = var_GetFloat( p_enc, SOUT_CFG_PREFIX "aq-strength" );
 
+#if X264_BUILD >= 111
+    if( var_GetInteger( p_enc, SOUT_CFG_PREFIX "frame-packing" ) > -1 )
+       p_sys->param.i_frame_packing = var_GetInteger( p_enc, SOUT_CFG_PREFIX "frame-packing" );
+#endif
+
     if( var_GetBool( p_enc, SOUT_CFG_PREFIX "verbose" ) )
         p_sys->param.i_log_level = X264_LOG_DEBUG;
 
@@ -1175,7 +1236,9 @@ static int  Open ( vlc_object_t *p_this )
     {
         p_sys->param.i_fps_num = p_enc->fmt_in.video.i_frame_rate;
         p_sys->param.i_fps_den = p_enc->fmt_in.video.i_frame_rate_base;
-        p_sys->param.b_vfr_input = 0;
+        p_sys->param.i_timebase_num = 1;
+        p_sys->param.i_timebase_den = INT64_C(1000000);
+        p_sys->param.b_vfr_input = 1;
     }
 
     /* Check slice-options */
@@ -1237,6 +1300,8 @@ static int  Open ( vlc_object_t *p_this )
         p_sys->param.rc.b_stat_read = i_val & 2;
     }
 
+    p_sys->param.pf_log = x264_log;
+    p_sys->param.p_log_private = p_enc;
     /* We need to initialize pthreadw32 before we open the encoder,
        but only once for the whole application. Since pthreadw32
        doesn't keep a refcount, do it ourselves. */
@@ -1266,6 +1331,28 @@ static int  Open ( vlc_object_t *p_this )
     /* We don't want repeated headers, we repeat p_extra ourself if needed */
     p_sys->param.b_repeat_headers = 0;
 
+    char *psz_opts = var_InheritString( p_enc, SOUT_CFG_PREFIX "options" );
+    if (psz_opts && *psz_opts) {
+        config_chain_t *cfg = NULL;
+        config_ChainParseOptions(&cfg, psz_opts);
+        while (cfg) {
+            config_chain_t *next = cfg->p_next;
+            char *name  = cfg->psz_name;
+            char *value = cfg->psz_value;
+            int ret = x264_param_parse(&p_sys->param, name, value);
+            if (ret == X264_PARAM_BAD_NAME) {
+                msg_Err(p_enc, "Unknown option \"%s\"", name);
+            } else if (ret == X264_PARAM_BAD_VALUE) {
+                msg_Err(p_enc, "Bad value \"%s\" for option \"%s\"", value, name);
+            }
+            free(name);
+            free(value);
+            free(cfg);
+            cfg = next;
+        }
+    }
+    free(psz_opts);
+
     /* Open the encoder */
     p_sys->h = x264_encoder_open( &p_sys->param );
 
@@ -1317,6 +1404,33 @@ static int  Open ( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+/****************************************************************************
+ * Logging
+ ****************************************************************************/
+static void x264_log( void *data, int i_level, const char *psz, va_list args)
+{
+    encoder_t *p_enc = (encoder_t *)data;
+
+    switch( i_level )
+    {
+        case X264_LOG_ERROR:
+            i_level = VLC_MSG_ERR;
+            break;
+        case X264_LOG_WARNING:
+            i_level = VLC_MSG_WARN;
+            break;
+        case X264_LOG_INFO:
+            i_level = VLC_MSG_INFO;
+            break;
+        case X264_LOG_DEBUG:
+            i_level = VLC_MSG_DBG;
+        default:
+            i_level = VLC_MSG_DBG;
+    }
+
+    msg_GenericVa( p_enc, i_level, MODULE_STRING, psz, args );
+};
+
 /****************************************************************************
  * Encode:
  ****************************************************************************/