Browse code

lavf/segment: guess list type from list filename suffix

Stefano Sabatini authored on 2012/08/16 07:16:28
Showing 3 changed files
... ...
@@ -466,8 +466,9 @@ time.
466 466
 
467 467
 The segment muxer works best with a single constant frame rate video.
468 468
 
469
-Optionally it can generate a flat list of the created segments, one segment
470
-per line, by setting the option @var{segment_list}.
469
+Optionally it can generate a list of the created segments, by setting
470
+the option @var{segment_list}. The list type is specified by the
471
+@var{segment_list_type} option.
471 472
 
472 473
 The segment muxer supports the following options:
473 474
 
... ...
@@ -503,12 +504,15 @@ muxer according to the provided pattern, and should not contain the
503 503
 @var{segment_start_time} and @var{segment_end_time} specify
504 504
 the segment start and end time expressed in seconds.
505 505
 
506
+A list file with the suffix @code{".ext"} will auto-select this format.
506 507
 @item m3u8
507 508
 Generate an extended M3U8 file, version 4, compliant with
508 509
 @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt}.
510
+
511
+A list file with the suffix @code{".m3u8"} will auto-select this format.
509 512
 @end table
510 513
 
511
-Default value is "flat".
514
+If not specified the type is guessed from the list file name suffix.
512 515
 @item segment_time @var{time}
513 516
 Set segment duration to @var{time}. Default value is "2".
514 517
 @item segment_time_delta @var{delta}
... ...
@@ -37,6 +37,7 @@
37 37
 #include "libavutil/mathematics.h"
38 38
 
39 39
 typedef enum {
40
+    LIST_TYPE_UNDEFINED = -1,
40 41
     LIST_TYPE_FLAT = 0,
41 42
     LIST_TYPE_EXT,
42 43
     LIST_TYPE_M3U8,
... ...
@@ -282,9 +283,15 @@ static int seg_write_header(AVFormatContext *s)
282 282
     if (!oc)
283 283
         return AVERROR(ENOMEM);
284 284
 
285
-    if (seg->list)
285
+    if (seg->list) {
286
+        if (seg->list_type == LIST_TYPE_UNDEFINED) {
287
+            if      (av_match_ext(seg->list, "ext" )) seg->list_type = LIST_TYPE_EXT;
288
+            else if (av_match_ext(seg->list, "m3u8")) seg->list_type = LIST_TYPE_M3U8;
289
+            else                                      seg->list_type = LIST_TYPE_FLAT;
290
+        }
286 291
         if ((ret = segment_list_open(s)) < 0)
287 292
             goto fail;
293
+    }
288 294
 
289 295
     for (i = 0; i< s->nb_streams; i++)
290 296
         seg->has_video +=
... ...
@@ -411,7 +418,7 @@ static const AVOption options[] = {
411 411
     { "segment_format",    "set container format used for the segments", OFFSET(format),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
412 412
     { "segment_list",      "set the segment list filename",              OFFSET(list),    AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,       E },
413 413
     { "segment_list_size", "set the maximum number of playlist entries", OFFSET(list_size), AV_OPT_TYPE_INT,  {.dbl = 5},     0, INT_MAX, E },
414
-    { "segment_list_type", "set the segment list type",                  OFFSET(list_type), AV_OPT_TYPE_INT,  {.dbl = LIST_TYPE_FLAT}, 0, LIST_TYPE_NB-1, E, "list_type" },
414
+    { "segment_list_type", "set the segment list type",                  OFFSET(list_type), AV_OPT_TYPE_INT,  {.dbl = LIST_TYPE_UNDEFINED}, -1, LIST_TYPE_NB-1, E, "list_type" },
415 415
     { "flat", "flat format",     0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" },
416 416
     { "ext",  "extended format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXT  }, INT_MIN, INT_MAX, 0, "list_type" },
417 417
     { "m3u8", "M3U8 format",     0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, 0, "list_type" },
... ...
@@ -31,7 +31,7 @@
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33 33
 #define LIBAVFORMAT_VERSION_MINOR 25
34
-#define LIBAVFORMAT_VERSION_MICRO 102
34
+#define LIBAVFORMAT_VERSION_MICRO 103
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \