[FFmpeg-cvslog] lavf/segment: add segment_format_options option

Stefano Sabatini git at videolan.org
Sun Sep 7 13:19:16 CEST 2014


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sat Sep  6 15:43:11 2014 +0200| [4f5493fe2380ad4aba67759baa7d7d4437f2e776] | committer: Stefano Sabatini

lavf/segment: add segment_format_options option

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f5493fe2380ad4aba67759baa7d7d4437f2e776
---

 doc/muxers.texi       |   11 +++++++++++
 libavformat/segment.c |   25 +++++++++++++++++++++++--
 libavformat/version.h |    2 +-
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index d7833a6..69ce47f 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -804,6 +804,11 @@ reference stream. The default value is @code{auto}.
 Override the inner container format, by default it is guessed by the filename
 extension.
 
+ at item segment_format_options @var{options_list}
+Set output format options using a :-separated list of key=value
+parameters. Values containing the @code{:} special character must be
+escaped.
+
 @item segment_list @var{name}
 Generate also a listfile named @var{name}. If not specified no
 listfile is generated.
@@ -959,6 +964,12 @@ ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list out.list out%03d.nu
 @end example
 
 @item
+Segment input and set output format options for the output segments:
+ at example
+ffmpeg -i in.mkv -f segment -segment_time 10 -segment_format_options movflags=+faststart out%03d.mp4
+ at end example
+
+ at item
 As the example above, but segment the input file according to the split
 points specified by the @var{segment_times} option:
 @example
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 3ee7d7d..00e5881 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -72,7 +72,9 @@ typedef struct {
     int segment_count;     ///< number of segment files already written
     AVOutputFormat *oformat;
     AVFormatContext *avf;
-    char *format;          ///< format to use for output segment files
+    char *format;              ///< format to use for output segment files
+    char *format_options_str;  ///< format options to use for output segment files
+    AVDictionary *format_options;
     char *list;            ///< filename for the segment list file
     int   list_flags;      ///< flags affecting list generation
     int   list_size;       ///< number of entries for the segment list file
@@ -563,6 +565,7 @@ static int seg_write_header(AVFormatContext *s)
 {
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = NULL;
+    AVDictionary *options = NULL;
     int ret;
 
     seg->segment_count = 0;
@@ -594,6 +597,15 @@ static int seg_write_header(AVFormatContext *s)
         }
     }
 
+    if (seg->format_options_str) {
+        ret = av_dict_parse_string(&seg->format_options, seg->format_options_str, "=", ":", 0);
+        if (ret < 0) {
+            av_log(s, AV_LOG_ERROR, "Could not parse format options list '%s'\n",
+                   seg->format_options_str);
+            goto fail;
+        }
+    }
+
     if (seg->list) {
         if (seg->list_type == LIST_TYPE_UNDEFINED) {
             if      (av_match_ext(seg->list, "csv" )) seg->list_type = LIST_TYPE_CSV;
@@ -645,7 +657,14 @@ static int seg_write_header(AVFormatContext *s)
             goto fail;
     }
 
-    if ((ret = avformat_write_header(oc, NULL)) < 0) {
+    av_dict_copy(&options, seg->format_options, 0);
+    ret = avformat_write_header(oc, &options);
+    if (av_dict_count(options)) {
+        av_log(s, AV_LOG_ERROR,
+               "Some of the provided format options in '%s' are not recognized\n", seg->format_options_str);
+    }
+    av_dict_free(&options);
+    if (ret < 0) {
         avio_close(oc->pb);
         goto fail;
     }
@@ -799,6 +818,7 @@ fail:
     if (seg->list)
         avio_close(seg->list_pb);
 
+    av_dict_free(&seg->format_options);
     av_opt_free(seg);
     av_freep(&seg->times);
     av_freep(&seg->frames);
@@ -820,6 +840,7 @@ fail:
 static const AVOption options[] = {
     { "reference_stream",  "set reference stream", OFFSET(reference_stream_specifier), AV_OPT_TYPE_STRING, {.str = "auto"}, CHAR_MIN, CHAR_MAX, E },
     { "segment_format",    "set container format used for the segments", OFFSET(format),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
+    { "segment_format_options", "set list of options for the container format used for the segments", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
     { "segment_list",      "set the segment list filename",              OFFSET(list),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
 
     { "segment_list_flags","set flags affecting segment list generation", OFFSET(list_flags), AV_OPT_TYPE_FLAGS, {.i64 = SEGMENT_LIST_FLAG_CACHE }, 0, UINT_MAX, E, "list_flags"},
diff --git a/libavformat/version.h b/libavformat/version.h
index 44810a2..da1c5b9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 56
 #define LIBAVFORMAT_VERSION_MINOR  4
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list