Commit 35d7ee99 authored by Rafaël Carré's avatar 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
parent 344bc899
...@@ -127,6 +127,7 @@ vlc_module_begin () ...@@ -127,6 +127,7 @@ vlc_module_begin ()
add_integer( "ffmpeg-debug", 0, DEBUG_TEXT, DEBUG_LONGTEXT, add_integer( "ffmpeg-debug", 0, DEBUG_TEXT, DEBUG_LONGTEXT,
true ) true )
add_string( "ffmpeg-codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true )
#if defined(HAVE_AVCODEC_VAAPI) || defined(HAVE_AVCODEC_DXVA2) #if defined(HAVE_AVCODEC_VAAPI) || defined(HAVE_AVCODEC_DXVA2)
add_bool( "ffmpeg-hw", false, HW_TEXT, HW_LONGTEXT, false ) add_bool( "ffmpeg-hw", false, HW_TEXT, HW_LONGTEXT, false )
#endif #endif
...@@ -144,6 +145,7 @@ vlc_module_begin () ...@@ -144,6 +145,7 @@ vlc_module_begin ()
set_capability( "encoder", 100 ) set_capability( "encoder", 100 )
set_callbacks( OpenEncoder, CloseEncoder ) 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, add_string( ENC_CFG_PREFIX "hq", "simple", ENC_HQ_TEXT,
ENC_HQ_LONGTEXT, false ) ENC_HQ_LONGTEXT, false )
change_string_list( enc_hq_list, enc_hq_list_text, 0 ) change_string_list( enc_hq_list, enc_hq_list_text, 0 )
...@@ -237,6 +239,21 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -237,6 +239,21 @@ static int OpenDecoder( vlc_object_t *p_this )
InitLibavcodec(p_this); InitLibavcodec(p_this);
/* *** ask ffmpeg for a decoder *** */ /* *** ask ffmpeg for a decoder *** */
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 ); p_codec = avcodec_find_decoder( i_codec_id );
if( !p_codec ) if( !p_codec )
{ {
......
...@@ -115,6 +115,9 @@ int ffmpeg_OpenCodec( decoder_t *p_dec ); ...@@ -115,6 +115,9 @@ int ffmpeg_OpenCodec( decoder_t *p_dec );
#define DEBUG_TEXT N_( "Debug mask" ) #define DEBUG_TEXT N_( "Debug mask" )
#define DEBUG_LONGTEXT N_( "Set FFmpeg 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 */ /* TODO: Use a predefined list, with 0,1,2,4,7 */
#define VISMV_TEXT N_( "Visualize motion vectors" ) #define VISMV_TEXT N_( "Visualize motion vectors" )
#define VISMV_LONGTEXT N_( \ #define VISMV_LONGTEXT N_( \
......
...@@ -146,7 +146,7 @@ struct encoder_sys_t ...@@ -146,7 +146,7 @@ struct encoder_sys_t
}; };
static const char *const ppsz_enc_options[] = { 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", "rc-buffer-size", "rc-buffer-aggressivity", "pre-me", "hurry-up",
"interlace", "interlace-me", "i-quant-factor", "noise-reduction", "mpeg4-matrix", "interlace", "interlace-me", "i-quant-factor", "noise-reduction", "mpeg4-matrix",
"trellis", "qscale", "strict", "lumi-masking", "dark-masking", "trellis", "qscale", "strict", "lumi-masking", "dark-masking",
...@@ -196,7 +196,7 @@ int OpenEncoder( vlc_object_t *p_this ) ...@@ -196,7 +196,7 @@ int OpenEncoder( vlc_object_t *p_this )
encoder_t *p_enc = (encoder_t *)p_this; encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys; encoder_sys_t *p_sys;
AVCodecContext *p_context; AVCodecContext *p_context;
AVCodec *p_codec; AVCodec *p_codec = NULL;
int i_codec_id, i_cat; int i_codec_id, i_cat;
const char *psz_namecodec; const char *psz_namecodec;
float f_val; float f_val;
...@@ -253,6 +253,21 @@ int OpenEncoder( vlc_object_t *p_this ) ...@@ -253,6 +253,21 @@ int OpenEncoder( vlc_object_t *p_this )
/* Initialization must be done before avcodec_find_encoder() */ /* Initialization must be done before avcodec_find_encoder() */
InitLibavcodec( p_this ); InitLibavcodec( p_this );
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 ); p_codec = avcodec_find_encoder( i_codec_id );
if( !p_codec ) if( !p_codec )
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment