[vlc-devel] [PATCH 3/3] avformat (mux/demux): implement private options

Rafaël Carré funman at videolan.org
Sun Apr 15 23:46:53 CEST 2012


---
 modules/codec/avcodec/avcommon.h  |    2 +-
 modules/demux/avformat/avformat.c |    3 +++
 modules/demux/avformat/demux.c    |   12 +++++++++++-
 modules/demux/avformat/mux.c      |    9 +++++++--
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index 18b812c..00cf0e3 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -67,7 +67,7 @@ static inline void vlc_init_avcodec(void)
 static inline AVDictionary *vlc_av_get_options(const char *psz_opts)
 {
     AVDictionary *options = NULL;
-    config_chain_t *cfg;
+    config_chain_t *cfg = NULL;
     config_ChainParseOptions(&cfg, psz_opts);
     while (cfg) {
         config_chain_t *next = cfg->p_next;
diff --git a/modules/demux/avformat/avformat.c b/modules/demux/avformat/avformat.c
index 6d3e172..de3e9b2 100644
--- a/modules/demux/avformat/avformat.c
+++ b/modules/demux/avformat/avformat.c
@@ -31,6 +31,7 @@
 #include <vlc_plugin.h>
 
 #include "avformat.h"
+#include "../../codec/avcodec/avcommon.h"
 
 vlc_module_begin ()
 #endif /* MERGE_FFMPEG */
@@ -43,6 +44,7 @@ vlc_module_begin ()
     set_callbacks( OpenDemux, CloseDemux )
     add_string( "avformat-format", NULL, FORMAT_TEXT, FORMAT_LONGTEXT, true )
     add_obsolete_string("ffmpeg-format") /* removed since 2.1.0 */
+    add_string( "avformat-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
 
 #ifdef ENABLE_SOUT
     /* mux submodule */
@@ -52,6 +54,7 @@ vlc_module_begin ()
     set_capability( "sout mux", 2 )
     add_string( "sout-avformat-mux", NULL, MUX_TEXT, MUX_LONGTEXT, true )
     add_obsolete_string("ffmpeg-mux") /* removed since 2.1.0 */
+    add_string( "sout-avformat-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
     set_callbacks( OpenMux, CloseMux )
 #endif
 #ifndef MERGE_FFMPEG
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 4596583..cdfaee4 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -252,7 +252,17 @@ int OpenDemux( vlc_object_t *p_this )
 
     vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
 #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0)
-    error = avformat_find_stream_info( p_sys->ic, NULL /* options */ );
+    char *psz_opts = var_InheritString( p_demux, "avformat-options" );
+    AVDictionary *options[p_sys->ic->nb_streams];
+    if (psz_opts && *psz_opts) {
+        options[0] = vlc_av_get_options(psz_opts);
+        for (unsigned i = 1; i < p_sys->ic->nb_streams; i++) {
+            options[i] = NULL;
+            av_dict_copy(&options[i], options[0], 0);
+        }
+    }
+    free(psz_opts);
+    error = avformat_find_stream_info( p_sys->ic, options );
 #else
     error = av_find_stream_info( p_sys->ic );
 #endif
diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
index 625b652..eb1670c 100644
--- a/modules/demux/avformat/mux.c
+++ b/modules/demux/avformat/mux.c
@@ -47,7 +47,7 @@
 //#define AVFORMAT_DEBUG 1
 
 static const char *const ppsz_mux_options[] = {
-    "mux", NULL
+    "mux", "options", NULL
 };
 
 /*****************************************************************************
@@ -381,7 +381,12 @@ static int Mux( sout_mux_t *p_mux )
         msg_Dbg( p_mux, "writing header" );
 
 #if (LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0))
-        error = avformat_write_header( p_sys->oc, NULL /* options */ );
+        char *psz_opts = var_GetNonEmptyString( p_mux, "sout-avformat-options" );
+        AVDictionary *options = NULL;
+        if (psz_opts && *psz_opts)
+            options = vlc_av_get_options(psz_opts);
+        free(psz_opts);
+        error = avformat_write_header( p_sys->oc, options ? &options : NULL);
 #else
         error = av_write_header( p_sys->oc );
 #endif
-- 
1.7.9.5



More information about the vlc-devel mailing list