[FFmpeg-devel] [PATCH] libavformat/hlsenc: fix delete_segments when use_localtime_mkdir

Steven Liu lingjiujianke at gmail.com
Thu Dec 29 06:04:06 EET 2016


2016-12-29 7:45 GMT+08:00 Bodecs Bela <bodecsb at vivanet.hu>:

> Dear All,
>
> when delete_segments hls_flag is specified, deleting old segments may fail
> in certain cases when use_localtime_mkdir is in effect and
> hls_segment_filename expression contains subdirs. This patch fixes this
> behaviour.
>
> Command to reproduce the bug:
>
> ffmpeg -loglevel info -y -re -f lavfi -i color=c=red:size=640x480:r=25 -f
> lavfi -i anullsrc=r=44100:cl=stereo -c:v mpeg2video -g 25 -acodec aac
> -cutoff 20000 -ac 2 -ar 44100 -ab 192k -f hls -hls_time 3 -hls_list_size 5
> -hls_flags delete_segments -use_localtime_mkdir 1 -use_localtime 1
> -hls_segment_filename "bb/bb%Y%m%d%H%I%S.ts" stream.m3u8
>
>
> thank you in advance,
>
> Bela Bodecs
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>  libavformat/hlsenc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cf4d4bd..c9d8e3c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -194,7 +194,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
         }
     }

-    if (segment) {
+    if (segment && !hls->use_localtime_mkdir) {
         if (hls->segment_filename) {
             dirname = av_strdup(hls->segment_filename);
         } else {
@@ -211,15 +211,20 @@ static int hls_delete_old_segments(HLSContext *hls) {
     while (segment) {
         av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
                                   segment->filename);
-        path_size = strlen(dirname) + strlen(segment->filename) + 1;
+        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) +
strlen(segment->filename) + 1;
         path = av_malloc(path_size);
         if (!path) {
             ret = AVERROR(ENOMEM);
             goto fail;
         }

-        av_strlcpy(path, dirname, path_size);
-        av_strlcat(path, segment->filename, path_size);
+        if (hls->use_localtime_mkdir)
+            av_strlcpy(path, segment->filename, path_size);
+        else { // segment->filename contains basename only
+            av_strlcpy(path, dirname, path_size);
+            av_strlcat(path, segment->filename, path_size);
+        }
+
         if (unlink(path) < 0) {
             av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s:
%s\n",
                                      path, strerror(errno));



applied!


Thanks


More information about the ffmpeg-devel mailing list