[vlc-commits] ffmpeg: add ffmpeg-codec and sout-ffmpeg-codec

Rafaël Carré git at videolan.org
Mon Nov 14 21:24:22 CET 2011


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon Nov 14 15:22:48 2011 -0500| [35d7ee99308588f50ce3ab952e9ed14d6d12e4e6] | committer: Rafaël Carré

ffmpeg: add ffmpeg-codec and sout-ffmpeg-codec

This allows specifying the libavcodec decoder/encoder by name
Useful in case there are more than one codec per fourcc

Example: ffvp8 / libvpx decoders for VP8

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=35d7ee99308588f50ce3ab952e9ed14d6d12e4e6
---

 modules/codec/avcodec/avcodec.c |   19 ++++++++++++++++++-
 modules/codec/avcodec/avcodec.h |    3 +++
 modules/codec/avcodec/encoder.c |   21 ++++++++++++++++++---
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 0d98564..c61eea9 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -127,6 +127,7 @@ vlc_module_begin ()
 
     add_integer( "ffmpeg-debug", 0, DEBUG_TEXT, DEBUG_LONGTEXT,
                  true )
+    add_string( "ffmpeg-codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
 #if defined(HAVE_AVCODEC_VAAPI) || defined(HAVE_AVCODEC_DXVA2)
     add_bool( "ffmpeg-hw", false, HW_TEXT, HW_LONGTEXT, false )
 #endif
@@ -144,6 +145,7 @@ vlc_module_begin ()
     set_capability( "encoder", 100 )
     set_callbacks( OpenEncoder, CloseEncoder )
 
+    add_string( ENC_CFG_PREFIX "codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
     add_string( ENC_CFG_PREFIX "hq", "simple", ENC_HQ_TEXT,
                 ENC_HQ_LONGTEXT, false )
         change_string_list( enc_hq_list, enc_hq_list_text, 0 )
@@ -237,7 +239,22 @@ static int OpenDecoder( vlc_object_t *p_this )
     InitLibavcodec(p_this);
 
     /* *** ask ffmpeg for a decoder *** */
-    p_codec = avcodec_find_decoder( i_codec_id );
+    char *psz_decoder = var_CreateGetString( p_this, "ffmpeg-codec" );
+    if( psz_decoder && *psz_decoder )
+    {
+        p_codec = avcodec_find_decoder_by_name( psz_decoder );
+        if( !p_codec )
+            msg_Err( p_this, "Decoder `%s' not found", psz_decoder );
+        else if( p_codec->id != i_codec_id )
+        {
+            msg_Err( p_this, "Decoder `%s' can't handle %4.4s",
+                    psz_decoder, (char*)&p_dec->fmt_in.i_codec );
+            p_codec = NULL;
+        }
+    }
+    free( psz_decoder );
+    if( !p_codec )
+        p_codec = avcodec_find_decoder( i_codec_id );
     if( !p_codec )
     {
         msg_Dbg( p_dec, "codec not found (%s)", psz_namecodec );
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index e9dbf18..c5399ab 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -115,6 +115,9 @@ int ffmpeg_OpenCodec( decoder_t *p_dec );
 #define DEBUG_TEXT N_( "Debug mask" )
 #define DEBUG_LONGTEXT N_( "Set FFmpeg debug mask" )
 
+#define CODEC_TEXT N_( "Codec name" )
+#define CODEC_LONGTEXT N_( "Internal libavcodec codec name" )
+
 /* TODO: Use a predefined list, with 0,1,2,4,7 */
 #define VISMV_TEXT N_( "Visualize motion vectors" )
 #define VISMV_LONGTEXT N_( \
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 0823369..7ccb78f 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -146,7 +146,7 @@ struct encoder_sys_t
 };
 
 static const char *const ppsz_enc_options[] = {
-    "keyint", "bframes", "vt", "qmin", "qmax", "hq",
+    "keyint", "bframes", "vt", "qmin", "qmax", "codec", "hq",
     "rc-buffer-size", "rc-buffer-aggressivity", "pre-me", "hurry-up",
     "interlace", "interlace-me", "i-quant-factor", "noise-reduction", "mpeg4-matrix",
     "trellis", "qscale", "strict", "lumi-masking", "dark-masking",
@@ -196,7 +196,7 @@ int OpenEncoder( vlc_object_t *p_this )
     encoder_t *p_enc = (encoder_t *)p_this;
     encoder_sys_t *p_sys;
     AVCodecContext *p_context;
-    AVCodec *p_codec;
+    AVCodec *p_codec = NULL;
     int i_codec_id, i_cat;
     const char *psz_namecodec;
     float f_val;
@@ -253,7 +253,22 @@ int OpenEncoder( vlc_object_t *p_this )
     /* Initialization must be done before avcodec_find_encoder() */
     InitLibavcodec( p_this );
 
-    p_codec = avcodec_find_encoder( i_codec_id );
+    char *psz_encoder = var_GetString( p_this, ENC_CFG_PREFIX "codec" );
+    if( psz_encoder && *psz_encoder )
+    {
+        p_codec = avcodec_find_encoder_by_name( psz_encoder );
+        if( !p_codec )
+            msg_Err( p_this, "Encoder `%s' not found", psz_encoder );
+        else if( p_codec->id != i_codec_id )
+        {
+            msg_Err( p_this, "Encoder `%s' can't handle %4.4s",
+                    psz_encoder, (char*)&p_enc->fmt_out.i_codec );
+            p_codec = NULL;
+        }
+    }
+    free( psz_encoder );
+    if( !p_codec )
+        p_codec = avcodec_find_encoder( i_codec_id );
     if( !p_codec )
     {
         msg_Err( p_enc, "cannot find encoder %s\n"



More information about the vlc-commits mailing list