Browse code

lavf/segment: add support to ffconcat segment list

Stefano Sabatini authored on 2013/02/22 03:33:26
Showing 4 changed files
... ...
@@ -29,6 +29,7 @@ the caller can decide which variant streams to actually receive.
29 29
 The total bitrate of the variant that the stream belongs to is
30 30
 available in a metadata key named "variant_bitrate".
31 31
 
32
+@anchor{concat}
32 33
 @section concat
33 34
 
34 35
 Virtual concatenation script demuxer.
... ...
@@ -579,6 +579,13 @@ auto-select this format.
579 579
 
580 580
 @code{ext} is deprecated in favor or @code{csv}.
581 581
 
582
+@item ffconcat
583
+Generate an ffconcat file for the created segments. The resulting file
584
+can be read using the FFmpeg @ref{concat} demuxer.
585
+
586
+A list file with the suffix @code{".ffcat"} or @code{".ffconcat"} will
587
+auto-select this format.
588
+
582 589
 @item m3u8
583 590
 Generate an extended M3U8 file, version 3, compliant with
584 591
 @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming}.
... ...
@@ -53,6 +53,7 @@ typedef enum {
53 53
     LIST_TYPE_CSV,
54 54
     LIST_TYPE_M3U8,
55 55
     LIST_TYPE_EXT, ///< deprecated
56
+    LIST_TYPE_FFCONCAT,
56 57
     LIST_TYPE_NB,
57 58
 } ListType;
58 59
 
... ...
@@ -225,6 +226,8 @@ static int segment_list_open(AVFormatContext *s)
225 225
         for (entry = seg->segment_list_entries; entry; entry = entry->next)
226 226
             max_duration = FFMAX(max_duration, entry->end_time - entry->start_time);
227 227
         avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%"PRId64"\n", (int64_t)ceil(max_duration));
228
+    } else if (seg->list_type == LIST_TYPE_FFCONCAT) {
229
+        avio_printf(seg->list_pb, "ffconcat version 1.0\n");
228 230
     }
229 231
 
230 232
     return ret;
... ...
@@ -232,7 +235,8 @@ static int segment_list_open(AVFormatContext *s)
232 232
 
233 233
 static void segment_list_print_entry(AVIOContext      *list_ioctx,
234 234
                                      ListType          list_type,
235
-                                     const SegmentListEntry *list_entry)
235
+                                     const SegmentListEntry *list_entry,
236
+                                     void *log_ctx)
236 237
 {
237 238
     switch (list_type) {
238 239
     case LIST_TYPE_FLAT:
... ...
@@ -247,6 +251,18 @@ static void segment_list_print_entry(AVIOContext      *list_ioctx,
247 247
         avio_printf(list_ioctx, "#EXTINF:%f,\n%s\n",
248 248
                     list_entry->end_time - list_entry->start_time, list_entry->filename);
249 249
         break;
250
+    case LIST_TYPE_FFCONCAT:
251
+    {
252
+        char *buf;
253
+        if (av_escape(&buf, list_entry->filename, NULL, AV_ESCAPE_MODE_AUTO, AV_ESCAPE_FLAG_WHITESPACE) < 0) {
254
+            av_log(log_ctx, AV_LOG_WARNING,
255
+                   "Error writing list entry '%s' in list file\n", list_entry->filename);
256
+            return;
257
+        }
258
+        avio_printf(list_ioctx, "file %s\n", buf);
259
+        av_free(buf);
260
+        break;
261
+    }
250 262
     default:
251 263
         av_assert0(!"Invalid list type");
252 264
     }
... ...
@@ -293,11 +309,11 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last)
293 293
             if ((ret = segment_list_open(s)) < 0)
294 294
                 goto end;
295 295
             for (entry = seg->segment_list_entries; entry; entry = entry->next)
296
-                segment_list_print_entry(seg->list_pb, seg->list_type, entry);
296
+                segment_list_print_entry(seg->list_pb, seg->list_type, entry, s);
297 297
             if (seg->list_type == LIST_TYPE_M3U8 && is_last)
298 298
                 avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n");
299 299
         } else {
300
-            segment_list_print_entry(seg->list_pb, seg->list_type, &seg->cur_entry);
300
+            segment_list_print_entry(seg->list_pb, seg->list_type, &seg->cur_entry, s);
301 301
         }
302 302
         avio_flush(seg->list_pb);
303 303
     }
... ...
@@ -551,6 +567,7 @@ static int seg_write_header(AVFormatContext *s)
551 551
             if      (av_match_ext(seg->list, "csv" )) seg->list_type = LIST_TYPE_CSV;
552 552
             else if (av_match_ext(seg->list, "ext" )) seg->list_type = LIST_TYPE_EXT;
553 553
             else if (av_match_ext(seg->list, "m3u8")) seg->list_type = LIST_TYPE_M3U8;
554
+            else if (av_match_ext(seg->list, "ffcat,ffconcat")) seg->list_type = LIST_TYPE_FFCONCAT;
554 555
             else                                      seg->list_type = LIST_TYPE_FLAT;
555 556
         }
556 557
         if ((ret = segment_list_open(s)) < 0)
... ...
@@ -761,6 +778,7 @@ static const AVOption options[] = {
761 761
     { "flat", "flat format",     0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, E, "list_type" },
762 762
     { "csv",  "csv format",      0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_CSV  }, INT_MIN, INT_MAX, E, "list_type" },
763 763
     { "ext",  "extended format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_EXT  }, INT_MIN, INT_MAX, E, "list_type" },
764
+    { "ffconcat", "ffconcat format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_FFCONCAT }, INT_MIN, INT_MAX, E, "list_type" },
764 765
     { "m3u8", "M3U8 format",     0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, E, "list_type" },
765 766
     { "hls", "Apple HTTP Live Streaming compatible", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, E, "list_type" },
766 767
 
... ...
@@ -31,7 +31,7 @@
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33 33
 #define LIBAVFORMAT_VERSION_MINOR 63
34
-#define LIBAVFORMAT_VERSION_MICRO 103
34
+#define LIBAVFORMAT_VERSION_MICRO 104
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \