avformat/hlsenc: support multi level path in m3u8 with filename
authorSteven Liu <lingjiujianke@gmail.com>
Mon, 26 Sep 2016 07:51:02 +0000 (15:51 +0800)
committerSteven Liu <lingjiujianke@gmail.com>
Mon, 3 Oct 2016 22:41:53 +0000 (06:41 +0800)
before patch:

localhost:osx liuqi$ tree 20160926/
20160926/
└── file-20160909
    └── 26
        └── 16
            └── 15
                ├── 46
                │   ├── 13.ts
                │   ├── 25.ts
                │   ├── 36.ts
                │   ├── 45.ts
                │   └── 54.ts
                └── 47
                    ├── 04.ts
                    ├── 14.ts
                    ├── 24.ts
                    └── 35.ts

6 directories, 9 files
localhost:osx liuqi$ cat out.m3u8
 #EXTM3U
 #EXT-X-VERSION:3
 #EXT-X-TARGETDURATION:12
 #EXT-X-MEDIA-SEQUENCE:0
 #EXTINF:11.360000,
 13.ts
 #EXTINF:10.800000,
 25.ts
 #EXTINF:9.120000,
 36.ts
 #EXTINF:8.760000,
 45.ts
 #EXTINF:10.200000,
 54.ts
 #EXTINF:10.720000,
 04.ts
 #EXTINF:9.600000,
 14.ts
 #EXTINF:10.600000,
 24.ts
 #EXTINF:8.760000,
 35.ts
 #EXT-X-ENDLIST

after patch:

localhost:osx liuqi$ tree 20160926/
20160926/
└── file-20160909
    └── 26
        └── 16
            └── 15
                ├── 46
                │   ├── 13.ts
                │   ├── 25.ts
                │   ├── 36.ts
                │   ├── 45.ts
                │   └── 54.ts
                └── 47
                    ├── 04.ts
                    ├── 14.ts
                    ├── 24.ts
                    └── 35.ts

6 directories, 9 files
localhost:osx liuqi$ cat out.m3u8
 #EXTM3U
 #EXT-X-VERSION:3
 #EXT-X-TARGETDURATION:12
 #EXT-X-MEDIA-SEQUENCE:0
 #EXTINF:11.360000,
 20160926/file-20160909/26/16/15/46/13.ts
 #EXTINF:10.800000,
 20160926/file-20160909/26/16/15/46/25.ts
 #EXTINF:9.120000,
 20160926/file-20160909/26/16/15/46/36.ts
 #EXTINF:8.760000,
 20160926/file-20160909/26/16/15/46/45.ts
 #EXTINF:10.200000,
 20160926/file-20160909/26/16/15/46/54.ts
 #EXTINF:10.720000,
 20160926/file-20160909/26/16/15/47/04.ts
 #EXTINF:9.600000,
 20160926/file-20160909/26/16/15/47/14.ts
 #EXTINF:10.600000,
 20160926/file-20160909/26/16/15/47/24.ts
 #EXTINF:8.760000,
 20160926/file-20160909/26/16/15/47/35.ts
 #EXT-X-ENDLIST

Signed-off-by: Steven Liu <lingjiujianke@gmail.com>
libavformat/hlsenc.c

index c161937..e0bb44b 100644 (file)
@@ -364,8 +364,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double
                               int64_t pos, int64_t size)
 {
     HLSSegment *en = av_malloc(sizeof(*en));
-    char *tmp, *p;
-    const char *pl_dir, *filename;
+    const char  *filename;
     int ret;
 
     if (!en)
@@ -374,19 +373,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double
     filename = av_basename(hls->avf->filename);
 
     if (hls->use_localtime_mkdir) {
-        /* Possibly prefix with mkdir'ed subdir, if playlist share same
-         * base path. */
-        tmp = av_strdup(s->filename);
-        if (!tmp) {
-            av_free(en);
-            return AVERROR(ENOMEM);
-        }
-
-        pl_dir = av_dirname(tmp);
-        p = hls->avf->filename;
-        if (strstr(p, pl_dir) == p)
-            filename = hls->avf->filename + strlen(pl_dir) + 1;
-        av_free(tmp);
+        filename = hls->avf->filename;
     }
     av_strlcpy(en->filename, filename, sizeof(en->filename));