[FFmpeg-devel] add hls muxer support extra entries outside m3u8 playlist

740936897 740936897 at qq.com
Sun May 18 04:38:33 CEST 2014


HI, all:
currently, HLS muxer does't support to remove segment file, only hls_wrap is set.
if hls_wrap is set, the segment number will cycle, eg, from 0~10.
if  hls_wrap is not set, the segment number will increase continuously, but result to many many segment files.
I fix this problem, add a HLS muxer option : hls_extra_size.
if segment file size > (hls_extra_size + hls_list_size), segment file  will be removed.


follow is the content of patch.  forgive my poor english  ^_^
--------------------------------------------------------------------------------------------------------------------


From 774743cfd112ed164858359e06292035ae0932cf Mon Sep 17 00:00:00 2001
From: wenjie.zhao <wenjie.zhao at chinacache.com>
Date: Sat, 17 May 2014 08:57:34 +0800
Subject: [PATCH] add hls muxer support extra entries outside m3u8 playlist
 this extra entries will be deleted later.


---
 libavformat/hlsenc.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)


diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1b5ef0e..041a288 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -21,6 +21,7 @@
 
 #include <float.h>
 #include <stdint.h>
+#include <unistd.h>
 
 #include "libavutil/mathematics.h"
 #include "libavutil/parseutils.h"
@@ -33,6 +34,7 @@
 
 typedef struct ListEntry {
     char  name[1024];
+    char  filename[1024];       // segment file path
     int   duration;
     struct ListEntry *next;
 } ListEntry;
@@ -54,6 +56,13 @@ typedef struct HLSContext {
     int nb_entries;
     ListEntry *list;
     ListEntry *end_list;
+
+    // extra entries size
+    int extra_size;
+    ListEntry *extra_list;
+    ListEntry *extra_end_list;
+    int nb_extra_entries;
+
     char *basename;
     AVIOContext *pb;
 } HLSContext;
@@ -91,6 +100,7 @@ static int append_entry(HLSContext *hls, uint64_t duration)
         return AVERROR(ENOMEM);
 
     av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name));
+    av_strlcpy(en->filename, hls->avf->filename, sizeof(en->filename));
 
     en->duration = duration;
     en->next     = NULL;
@@ -105,7 +115,23 @@ static int append_entry(HLSContext *hls, uint64_t duration)
     if (hls->size && hls->nb_entries >= hls->size) {
         en = hls->list;
         hls->list = en->next;
-        av_free(en);
+        if (!hls->extra_list)
+            hls->extra_list = en;
+        else
+            hls->extra_end_list->next = en;
+
+        hls->extra_end_list = en;
+        hls->nb_extra_entries ++;
+
+        if (hls->extra_size && hls->nb_extra_entries > hls->extra_size) {
+            en = hls->extra_list;
+            hls->extra_list = en->next;
+            
+            // remove useless file
+            unlink(en->filename);
+            av_free(en);
+        }
+
     } else
         hls->nb_entries++;
 
@@ -116,7 +142,7 @@ static int append_entry(HLSContext *hls, uint64_t duration)
 
 static void free_entries(HLSContext *hls)
 {
-    ListEntry *p = hls->list, *en;
+    ListEntry *p = hls->extra_list, *en;
 
     while(p) {
         en = p;
@@ -324,6 +350,7 @@ static const AVOption options[] = {
     {"start_number",  "set first number in the sequence",        OFFSET(sequence),AV_OPT_TYPE_INT64,  {.i64 = 0},     0, INT64_MAX, E},
     {"hls_time",      "set segment length in seconds",           OFFSET(time),    AV_OPT_TYPE_FLOAT,  {.dbl = 2},     0, FLT_MAX, E},
     {"hls_list_size", "set maximum number of playlist entries",  OFFSET(size),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
+    {"hls_extra_size",     "set extra size of playlist entries",  OFFSET(extra_size),    AV_OPT_TYPE_INT,    {.i64 = 5},     0, INT_MAX, E},
     {"hls_wrap",      "set number after which the index wraps",  OFFSET(wrap),    AV_OPT_TYPE_INT,    {.i64 = 0},     0, INT_MAX, E},
     { NULL },
 };
-- 
1.7.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-add-hls-muxer-support-extra-entries-outside-m3u8-pla.patch
Type: application/octet-stream
Size: 3253 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140518/9522975a/attachment.obj>


More information about the ffmpeg-devel mailing list