diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-08-15 11:06:34 +0200 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-08-18 11:21:47 +0200 |
commit | e5ae2f912626e72821d6e152dabf7c89fe1f5119 (patch) | |
tree | a0ce886c597bef675628098585ea39ecd16f07b6 /libavformat/segment.c | |
parent | 4a12d1e8e794059b58718f402c46aed9e2bed458 (diff) | |
download | ffmpeg-e5ae2f912626e72821d6e152dabf7c89fe1f5119.tar.gz |
lavf/segment: add M3U8 list support
Address trac ticket #1642.
Diffstat (limited to 'libavformat/segment.c')
-rw-r--r-- | libavformat/segment.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libavformat/segment.c b/libavformat/segment.c index 78b304ae17..2b1ad0ece8 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -20,6 +20,8 @@ /** * @file generic segmenter + * M3U8 specification can be find here: + * @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt} */ #include <float.h> @@ -37,6 +39,7 @@ typedef enum { LIST_TYPE_FLAT = 0, LIST_TYPE_EXT, + LIST_TYPE_M3U8, LIST_TYPE_NB, } ListType; @@ -120,12 +123,25 @@ static int segment_list_open(AVFormatContext *s) if (ret < 0) return ret; seg->list_max_segment_time = 0; + + if (seg->list_type == LIST_TYPE_M3U8) { + avio_printf(seg->list_pb, "#EXTM3U\n"); + avio_printf(seg->list_pb, "#EXT-X-VERSION:4\n"); + } + return ret; } static void segment_list_close(AVFormatContext *s) { SegmentContext *seg = s->priv_data; + + if (seg->list_type == LIST_TYPE_M3U8) { + avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%d\n", + (int)(seg->list_max_segment_time + 0.5)); + avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n"); + } + avio_close(seg->list_pb); } @@ -153,6 +169,9 @@ static int segment_end(AVFormatContext *s) avio_printf(seg->list_pb, "%s\n", oc->filename); } else if (seg->list_type == LIST_TYPE_EXT) { avio_printf(seg->list_pb, "%s,%f,%f\n", oc->filename, seg->start_time, seg->end_time); + } else if (seg->list_type == LIST_TYPE_M3U8) { + avio_printf(seg->list_pb, "#EXTINF:%f,\n%s\n", + seg->end_time - seg->start_time, oc->filename); } seg->list_max_segment_time = FFMAX(seg->end_time - seg->start_time, seg->list_max_segment_time); avio_flush(seg->list_pb); @@ -395,6 +414,7 @@ static const AVOption options[] = { { "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" }, { "flat", "flat format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" }, { "ext", "extended format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXT }, INT_MIN, INT_MAX, 0, "list_type" }, + { "m3u8", "M3U8 format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, 0, "list_type" }, { "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, { "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta_str), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, E }, { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, |