[vlc-commits] avcodec: support private options
Rafaël Carré
git at videolan.org
Thu Jun 6 14:56:13 CEST 2013
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Wed Jun 5 15:14:59 2013 +0200| [c9a57e4d1d1a4b704087a2ed49064d175c514d83] | committer: Rafaël Carré
avcodec: support private options
Usage:
--avcodec-options='{lowres=3,foobar=baz}'
--sout-avcodec-options='{threads=42}'
For now the decoder options are global, they apply to audio/video/subtitles decoder.
encoder options can be set in the sout chain, specific to each ES
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c9a57e4d1d1a4b704087a2ed49064d175c514d83
---
modules/codec/avcodec/avcodec.c | 18 +++++++++++++++++-
modules/codec/avcodec/encoder.c | 32 +++++++++++++++++++++++---------
modules/codec/avcodec/subtitle.c | 15 ++++++++++++++-
3 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index aa807eb..04ade54 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -144,6 +144,7 @@ vlc_module_begin ()
add_obsolete_integer( "ffmpeg-threads" ) /* removed since 2.1.0 */
add_integer( "avcodec-threads", 0, THREADS_TEXT, THREADS_LONGTEXT, true );
#endif
+ add_string( "avcodec-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
#ifdef ENABLE_SOUT
@@ -239,6 +240,8 @@ vlc_module_begin ()
/* Audio AAC encoder profile */
add_string( ENC_CFG_PREFIX "aac-profile", "low",
ENC_PROFILE_TEXT, ENC_PROFILE_LONGTEXT, true )
+
+ add_string( ENC_CFG_PREFIX "options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
#endif /* ENABLE_SOUT */
#ifdef MERGE_FFMPEG
@@ -416,9 +419,22 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
p_sys->p_context->sample_rate;
}
int ret;
+ char *psz_opts = var_InheritString( p_dec, "avcodec-options" );
+ AVDictionary *options = NULL;
+ if (psz_opts && *psz_opts)
+ options = vlc_av_get_options(psz_opts);
+ free(psz_opts);
+
vlc_avcodec_lock();
- ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, NULL /* options */ );
+ ret = avcodec_open2( p_sys->p_context, p_sys->p_codec, options ? &options : NULL );
vlc_avcodec_unlock();
+
+ AVDictionaryEntry *t = NULL;
+ while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ msg_Err( p_dec, "Unknown option \"%s\"", t->key );
+ }
+ av_dict_free(&options);
+
if( ret < 0 )
return VLC_EGENERIC;
msg_Dbg( p_dec, "avcodec codec (%s) started", p_sys->psz_namecodec );
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index c75a78f..9523e32 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -158,7 +158,7 @@ static const char *const ppsz_enc_options[] = {
#if (LIBAVCODEC_VERSION_MAJOR < 55)
"luma-elim-threshold", "chroma-elim-threshold",
#endif
- "aac-profile",
+ "aac-profile", "options",
NULL
};
@@ -738,9 +738,21 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->thread_count = vlc_GetCPUCount();
int ret;
+ char *psz_opts = var_InheritString(p_enc, ENC_CFG_PREFIX "options");
+ AVDictionary *options = NULL;
+ if (psz_opts && *psz_opts)
+ options = vlc_av_get_options(psz_opts);
+ free(psz_opts);
+
vlc_avcodec_lock();
- ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
+ ret = avcodec_open2( p_context, p_codec, options ? &options : NULL );
vlc_avcodec_unlock();
+
+ AVDictionaryEntry *t = NULL;
+ while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ msg_Err(p_enc, "Unknown option \"%s\"", t->key);
+ }
+
if( ret )
{
if( p_enc->fmt_in.i_cat != AUDIO_ES ||
@@ -750,8 +762,8 @@ int OpenEncoder( vlc_object_t *p_this )
msg_Err( p_enc, "cannot open encoder" );
dialog_Fatal( p_enc, _("Streaming / Transcoding failed"),
"%s", _("VLC could not open the encoder.") );
- free( p_sys );
- return VLC_EGENERIC;
+ av_dict_free(&options);
+ goto error;
}
if( p_context->channels > 2 )
@@ -774,8 +786,8 @@ int OpenEncoder( vlc_object_t *p_this )
{
msg_Err( p_enc, "MPEG audio doesn't support frequency=%d",
fmt->audio.i_rate );
- free( p_sys );
- return VLC_EGENERIC;
+ av_dict_free(&options);
+ goto error;
}
for ( i = 1; i < 14; i++ )
@@ -795,7 +807,7 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->codec = NULL;
vlc_avcodec_lock();
- ret = avcodec_open2( p_context, p_codec, NULL /* options */ );
+ ret = avcodec_open2( p_context, p_codec, options ? &options : NULL );
vlc_avcodec_unlock();
if( ret )
{
@@ -803,11 +815,13 @@ int OpenEncoder( vlc_object_t *p_this )
dialog_Fatal( p_enc,
_("Streaming / Transcoding failed"),
"%s", _("VLC could not open the encoder.") );
- free( p_sys );
- return VLC_EGENERIC;
+ av_dict_free(&options);
+ goto error;
}
}
+ av_dict_free(&options);
+
if( i_codec_id == AV_CODEC_ID_FLAC )
{
p_enc->fmt_out.i_extra = 4 + 1 + 3 + p_context->extradata_size;
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index 324fd92..407bb90 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -82,9 +82,22 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
/* */
int ret;
+ char *psz_opts = var_InheritString(dec, "avcodec-options");
+ AVDictionary *options = NULL;
+ if (psz_opts && *psz_opts)
+ options = vlc_av_get_options(psz_opts);
+ free(psz_opts);
+
vlc_avcodec_lock();
- ret = avcodec_open2(context, codec, NULL /* options */);
+ ret = avcodec_open2(context, codec, options ? &options : NULL);
vlc_avcodec_unlock();
+
+ AVDictionaryEntry *t = NULL;
+ while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ msg_Err(dec, "Unknown option \"%s\"", t->key);
+ }
+ av_dict_free(&options);
+
if (ret < 0) {
msg_Err(dec, "cannot open codec (%s)", namecodec);
free(context->extradata);
More information about the vlc-commits
mailing list