[FFmpeg-devel] [PATCH 09/12] lavf/concat: add support for chapters

Nicolas George george at nsup.org
Tue Aug 31 21:07:36 EEST 2021


Signed-off-by: Nicolas George <george at nsup.org>
---
 doc/demuxers.texi       |  4 ++++
 libavformat/concatdec.c | 12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 6bb0574e94..0c347e3f47 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -184,6 +184,10 @@ Can be present multiple times.
 @item @code{stream_codec @var{value}}
 Codec for the stream.
 
+ at item @code{cahpter @var{id} @var{start} @var{end}}
+Add a chapter. @var{id} is an unique identifier, possibly small and
+consecutive.
+
 @end table
 
 @subsection Options
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index a0d68d51cc..0dd39a149e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -408,7 +408,7 @@ static int concat_read_close(AVFormatContext *avf)
     return 0;
 }
 
-#define MAX_ARGS 2
+#define MAX_ARGS 3
 #define NEEDS_UNSAFE   (1 << 1)
 #define NEEDS_FILE     (1 << 1)
 #define NEEDS_STREAM   (1 << 2)
@@ -432,6 +432,7 @@ typedef enum ParseDirective {
    DIR_EXSID,
    DIR_STMETA,
    DIR_STCODEC,
+   DIR_CHAPTER,
 } ParseDirective;
 
 static const ParseSyntax syntax[] = {
@@ -447,6 +448,7 @@ static const ParseSyntax syntax[] = {
     [DIR_EXSID    ] = { "exact_stream_id",      "i",    NEEDS_STREAM },
     [DIR_STMETA   ] = { "stream_meta",          "ks",   NEEDS_STREAM },
     [DIR_STCODEC  ] = { "stream_codec",         "k",    NEEDS_STREAM },
+    [DIR_CHAPTER  ] = { "chapter",              "idd",  0 },
 };
 
 static int concat_parse_script(AVFormatContext *avf)
@@ -457,6 +459,7 @@ static int concat_parse_script(AVFormatContext *avf)
     uint8_t *cursor, *keyword;
     ConcatFile *file = NULL;
     AVStream *stream = NULL;
+    AVChapter *chapter = NULL;
     unsigned line = 0, arg;
     const ParseSyntax *dir;
     char *arg_kw[MAX_ARGS];
@@ -609,6 +612,13 @@ static int concat_parse_script(AVFormatContext *avf)
             break;
         }
 
+        case DIR_CHAPTER:
+            chapter = avpriv_new_chapter(avf, arg_int[0], AV_TIME_BASE_Q,
+                                         arg_int[1], arg_int[2], NULL);
+            if (!chapter)
+                return AVERROR(ENOMEM);
+            break;
+
         default:
             FAIL(AVERROR_BUG);
         }
-- 
2.33.0



More information about the ffmpeg-devel mailing list