[vlc-devel] [PATCH 2/2] avformat mux: support private options

Rafaël Carré funman at videolan.org
Fri Mar 2 18:54:29 CET 2012


syntax: --mux=avformat{mux=mp4,options={movflags=123,foo=bar}}
---
 modules/demux/avformat/avformat.c |    3 +++
 modules/demux/avformat/mux.c      |   21 +++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/modules/demux/avformat/avformat.c b/modules/demux/avformat/avformat.c
index 24905f3..41808bd 100644
--- a/modules/demux/avformat/avformat.c
+++ b/modules/demux/avformat/avformat.c
@@ -51,6 +51,9 @@ vlc_module_begin ()
     set_capability( "sout mux", 2 )
     add_string( "ffmpeg-mux", NULL, MUX_TEXT,
                 MUX_LONGTEXT, true )
+    #define OPTIONS_TEXT NULL
+    #define OPTIONS_LONGTEXT NULL
+    add_string( "ffmpeg-options", NULL, OPTIONS_TEXT, OPTIONS_LONGTEXT, true )
     set_callbacks( OpenMux, CloseMux )
 #endif
 #ifndef MERGE_FFMPEG
diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
index cf8b715..4b21ee0 100644
--- a/modules/demux/avformat/mux.c
+++ b/modules/demux/avformat/mux.c
@@ -46,7 +46,7 @@
 //#define AVFORMAT_DEBUG 1
 
 static const char *const ppsz_mux_options[] = {
-    "mux", NULL
+    "mux", "options", NULL
 };
 
 /*****************************************************************************
@@ -366,6 +366,22 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input )
     return VLC_SUCCESS;
 }
 
+static AVDictionary *get_options(sout_mux_t *p_mux)
+{
+    char *psz_options = var_GetNonEmptyString( p_mux, "ffmpeg-options" );
+    AVDictionary *options = NULL;
+    config_chain_t *cfg;
+    config_ChainParseKeys(&cfg, psz_options);
+    while (cfg) {
+        config_chain_t *next = cfg->p_next;
+        av_dict_set(&options, cfg->psz_name, cfg->psz_value,
+            AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
+        free(cfg);
+        cfg = next;
+    }
+    free(psz_options);
+    return options;
+}
 /*****************************************************************************
  * Mux: multiplex available data in input fifos
  *****************************************************************************/
@@ -381,7 +397,8 @@ 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 */ );
+        AVDictionary *options = get_options(p_mux);
+        error = avformat_write_header( p_sys->oc, options ? &options : NULL);
 #else
         error = av_write_header( p_sys->oc );
 #endif
-- 
1.7.9



More information about the vlc-devel mailing list