[FFmpeg-cvslog] lavf/segment: add M3U8 list support

Stefano Sabatini git at videolan.org
Sat Aug 18 11:30:13 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Wed Aug 15 11:06:34 2012 +0200| [e5ae2f912626e72821d6e152dabf7c89fe1f5119] | committer: Stefano Sabatini

lavf/segment: add M3U8 list support

Address trac ticket #1642.

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

 doc/muxers.texi       |    4 ++++
 libavformat/segment.c |   20 ++++++++++++++++++++
 libavformat/version.h |    2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 2cb8e13..e6e72e4 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -502,6 +502,10 @@ muxer according to the provided pattern, and should not contain the
 
 @var{segment_start_time} and @var{segment_end_time} specify
 the segment start and end time expressed in seconds.
+
+ at item m3u8
+Generate an extended M3U8 file, version 4, compliant with
+ at url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt}.
 @end table
 
 Default value is "flat".
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 78b304a..2b1ad0e 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 },
diff --git a/libavformat/version.h b/libavformat/version.h
index 4275ecd..a67c9c2 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
 #define LIBAVFORMAT_VERSION_MINOR 25
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list