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

Michael Niedermayer michaelni at gmx.at
Wed Jul 9 15:30:18 CEST 2014


On Mon, May 19, 2014 at 10:36:48AM +0800, 740936897 wrote:
> 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);

thats not ok, you dont know if its a local file
it could be anything thats supported by AVIO / URLProtocols


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140709/d35512c8/attachment.asc>


More information about the ffmpeg-devel mailing list