Browse code

lavf/hls: add hls_ts_option

Same as COMMITID 4f5493fe2380ad4aba67759baa7d7d4437f2e776.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>

Steven Liu authored on 2014/09/12 19:04:52
Showing 3 changed files
... ...
@@ -224,6 +224,11 @@ Set the segment length in seconds. Default value is 2.
224 224
 Set the maximum number of playlist entries. If set to 0 the list file
225 225
 will contain all the segments. Default value is 5.
226 226
 
227
+@item hls_ts_options @var{options_list}
228
+Set output format options using a :-separated list of key=value
229
+parameters. Values containing @code{:} special characters must be
230
+escaped.
231
+
227 232
 @item hls_wrap @var{wrap}
228 233
 Set the number after which the segment filename number (the number
229 234
 specified in each segment file) wraps. If set to 0 the number will be
... ...
@@ -73,6 +73,8 @@ typedef struct HLSContext {
73 73
 
74 74
     char *basename;
75 75
     char *baseurl;
76
+    char *format_options_str;
77
+    AVDictionary *format_options;
76 78
 
77 79
     AVIOContext *pb;
78 80
 } HLSContext;
... ...
@@ -226,6 +228,7 @@ static int hls_write_header(AVFormatContext *s)
226 226
     int ret, i;
227 227
     char *p;
228 228
     const char *pattern = "%d.ts";
229
+    AVDictionary *options = NULL;
229 230
     int basename_size = strlen(s->filename) + strlen(pattern) + 1;
230 231
 
231 232
     hls->sequence       = hls->start_sequence;
... ...
@@ -235,6 +238,14 @@ static int hls_write_header(AVFormatContext *s)
235 235
     if (hls->flags & HLS_SINGLE_FILE)
236 236
         pattern = ".ts";
237 237
 
238
+    if (hls->format_options_str) {
239
+        ret = av_dict_parse_string(&hls->format_options, hls->format_options_str, "=", ":", 0);
240
+        if (ret < 0) {
241
+            av_log(s, AV_LOG_ERROR, "Could not parse format options list '%s'\n", hls->format_options_str);
242
+            goto fail;
243
+        }
244
+    }
245
+
238 246
     for (i = 0; i < s->nb_streams; i++)
239 247
         hls->has_video +=
240 248
             s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
... ...
@@ -273,11 +284,17 @@ static int hls_write_header(AVFormatContext *s)
273 273
     if ((ret = hls_start(s)) < 0)
274 274
         goto fail;
275 275
 
276
-    if ((ret = avformat_write_header(hls->avf, NULL)) < 0)
276
+    av_dict_copy(&options, hls->format_options, 0);
277
+    ret = avformat_write_header(hls->avf, &options);
278
+    if (av_dict_count(options)) {
279
+        av_log(s, AV_LOG_ERROR, "Some of provided format options in '%s' are not recognized\n", hls->format_options_str);
280
+        ret = AVERROR(EINVAL);
277 281
         goto fail;
278
-
282
+    }
279 283
 
280 284
 fail:
285
+
286
+    av_dict_free(&options);
281 287
     if (ret) {
282 288
         av_free(hls->basename);
283 289
         if (hls->avf)
... ...
@@ -375,6 +392,7 @@ static const AVOption options[] = {
375 375
     {"start_number",  "set first number in the sequence",        OFFSET(start_sequence),AV_OPT_TYPE_INT64,  {.i64 = 0},     0, INT64_MAX, E},
376 376
     {"hls_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E},
377 377
     {"hls_list_size", "set maximum number of playlist entries",  OFFSET(max_nb_segments),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
378
+    {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,    E},
378 379
     {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
379 380
     {"hls_base_url",  "url to prepend to each playlist entry",   OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E},
380 381
     {"hls_flags",     "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"},
... ...
@@ -31,7 +31,7 @@
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 56
33 33
 #define LIBAVFORMAT_VERSION_MINOR  4
34
-#define LIBAVFORMAT_VERSION_MICRO 101
34
+#define LIBAVFORMAT_VERSION_MICRO 102
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \