This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit c4947461bacea5e0a98e30e2ebd5fff28fb832cc
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Sun Sep 20 18:34:51 2026 +0200
Commit:     michaelni <[email protected]>
CommitDate: Sat Sep 26 11:36:30 2026 +0000

    avformat/concatdec: add an option creating a chapter per file
    
    With chapter_per_file set, every file becomes a chapter named after its
    title tag or, failing that, its file name, carrying the file's other
    tags, so a player can present a playlist as a browsable list. Finding
    the chapter boundaries means probing every file up front, which also
    makes the total duration known and the output seekable. The generated
    chapters get ids above those of the chapters the script declares, and
    the chapters are kept in chronological order.
    
    Assisted-by: Claude
---
 doc/demuxers.texi                               |  9 +++
 libavformat/concatdec.c                         | 51 ++++++++++++++++-
 tests/{simple1.ffconcat => chapters.ffconcat}   |  4 +-
 tests/fate/concatdec.mak                        |  8 ++-
 tests/ref/fate/concat-demuxer-chapters-lavf-mxf | 76 +++++++++++++++++++++++++
 5 files changed, 142 insertions(+), 6 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 82c36a4594..7610055193 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -242,6 +242,15 @@ expressed in microseconds. The duration metadata is only 
set if it is known
 based on the concat file.
 The default is 0.
 
+@item chapter_per_file
+If set to 1, add a chapter for each file, named after the @code{title}
+metadata of the file or, failing that, its file name, and carrying the rest
+of the file's metadata. The files are opened in order when the script is read
+to learn their durations, stopping after the first file whose duration is
+unknown, which gets the last chapter; when all durations are known, this also
+makes the total duration known and the output seekable.
+The default is 0.
+
 @end table
 
 @subsection Examples
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 77195cd7b2..b2857b35d5 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -73,6 +73,7 @@ typedef struct {
     ConcatMatchMode stream_match_mode;
     unsigned auto_convert;
     int segment_time_metadata;
+    int chapter_per_file;
 } ConcatContext;
 
 static int concat_probe(const AVProbeData *probe)
@@ -669,6 +670,48 @@ fail:
     return ret == AVERROR_EOF ? 0 : ret;
 }
 
+static int compare_chapter_starts(const void *a, const void *b)
+{
+    const AVChapter *ca = *(const AVChapter *const *)a, *cb = *(const 
AVChapter *const *)b;
+
+    return av_compare_ts(ca->start, ca->time_base, cb->start, cb->time_base);
+}
+
+static int add_file_chapters(AVFormatContext *avf)
+{
+    ConcatContext *cat = avf->priv_data;
+    int64_t id = 0;
+
+    for (unsigned i = 0; i < avf->nb_chapters; i++)
+        id = FFMAX(id, av_sat_add64(avf->chapters[i]->id, 1));
+    for (unsigned i = 0; i < cat->nb_files; i++) {
+        ConcatFile *file = &cat->files[i];
+        AVDictionaryEntry *title;
+        AVChapter *chapter;
+        int64_t end = AV_NOPTS_VALUE;
+        int ret = probe_file(avf, i);
+
+        if (ret < 0)
+            return ret;
+        if (file->duration != AV_NOPTS_VALUE)
+            end = av_sat_add64(file->start_time, file->duration);
+        if (end == INT64_MAX || id == INT64_MAX || (end != AV_NOPTS_VALUE && 
end < file->start_time))
+            return AVERROR_INVALIDDATA;
+        file->user_duration = file->duration;
+        title = av_dict_get(cat->avf->metadata, "title", NULL, 0);
+        chapter = avpriv_new_chapter(avf, id++, AV_TIME_BASE_Q, 
file->start_time, end,
+                                     title ? title->value : 
av_basename(file->url));
+        if (!chapter || (ret = av_dict_copy(&chapter->metadata, 
cat->avf->metadata, AV_DICT_DONT_OVERWRITE)) < 0)
+            return chapter ? ret : AVERROR(ENOMEM);
+        if (end == AV_NOPTS_VALUE) {
+            av_log(avf, AV_LOG_WARNING, "Duration of '%s' unknown, no chapters 
for the files after it\n", file->url);
+            break;
+        }
+    }
+    qsort(avf->chapters, avf->nb_chapters, sizeof(*avf->chapters), 
compare_chapter_starts);
+    return 0;
+}
+
 static int concat_read_header(AVFormatContext *avf)
 {
     ConcatContext *cat = avf->priv_data;
@@ -683,6 +726,10 @@ static int concat_read_header(AVFormatContext *avf)
         av_log(avf, AV_LOG_ERROR, "No files to concat\n");
         return AVERROR_INVALIDDATA;
     }
+    cat->stream_match_mode = avf->nb_streams ? MATCH_EXACT_ID :
+                                               MATCH_ONE_TO_ONE;
+    if (cat->chapter_per_file && (ret = add_file_chapters(avf)) < 0)
+        return ret;
 
     for (i = 0; i < cat->nb_files; i++) {
         if (cat->files[i].start_time == AV_NOPTS_VALUE)
@@ -706,8 +753,6 @@ static int concat_read_header(AVFormatContext *avf)
         cat->seekable = 1;
     }
 
-    cat->stream_match_mode = avf->nb_streams ? MATCH_EXACT_ID :
-                                               MATCH_ONE_TO_ONE;
     if ((ret = open_file(avf, 0)) < 0)
         return ret;
 
@@ -951,6 +996,8 @@ static const AVOption options[] = {
       OFFSET(auto_convert), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC },
     { "segment_time_metadata", "output file segment start time and duration as 
packet metadata",
       OFFSET(segment_time_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
+    { "chapter_per_file", "add a chapter for each file, opening them all up 
front to learn their durations",
+      OFFSET(chapter_per_file), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC },
     { NULL }
 };
 
diff --git a/tests/simple1.ffconcat b/tests/chapters.ffconcat
similarity index 61%
copy from tests/simple1.ffconcat
copy to tests/chapters.ffconcat
index 6dcadcbf78..217dd6ac32 100644
--- a/tests/simple1.ffconcat
+++ b/tests/chapters.ffconcat
@@ -1,11 +1,9 @@
 ffconcat version 1.0
 
-file      %SRCFILE%
+chapter   10 0.5 0.75
 
 file      %SRCFILE%
-inpoint   00:00.80
 
 file      %SRCFILE%
 inpoint   00:00.20
 outpoint  00:00.40
-file_packet_meta dummy 1
diff --git a/tests/fate/concatdec.mak b/tests/fate/concatdec.mak
index 9b21f1dd4b..88fea0e84e 100644
--- a/tests/fate/concatdec.mak
+++ b/tests/fate/concatdec.mak
@@ -4,12 +4,14 @@ FATE_CONCAT_DEMUXER_SIMPLE2_LAVF  := ts
 
 FATE_CONCAT_DEMUXER_EXTENDED_LAVF := mxf mxf_d10
 
+FATE_CONCAT_DEMUXER_CHAPTERS_LAVF := mxf
+
 define FATE_CONCAT_DEMUXER_SUITE
 $$(addprefix fate-lavf-,$$(FATE_CONCAT_DEMUXER_$(D)_LAVF)): KEEP_FILES ?= 1
 FATE_CONCAT_DEMUXER_$(D)_LAVF := $$(filter 
$$(FATE_LAVF_CONTAINER:fate-lavf-%=%),$$(FATE_CONCAT_DEMUXER_$(D)_LAVF))
 endef
 
-$(foreach D,SIMPLE1 SIMPLE2 EXTENDED,$(eval $(FATE_CONCAT_DEMUXER_SUITE)))
+$(foreach D,SIMPLE1 SIMPLE2 EXTENDED CHAPTERS,$(eval 
$(FATE_CONCAT_DEMUXER_SUITE)))
 
 $(foreach D,$(FATE_CONCAT_DEMUXER_SIMPLE1_LAVF),$(eval 
fate-concat-demuxer-simple1-lavf-$(D): fate-lavf-$(D)))
 $(foreach D,$(FATE_CONCAT_DEMUXER_SIMPLE1_LAVF),$(eval 
fate-concat-demuxer-simple1-lavf-$(D): CMD = concat 
$(SRC_PATH)/tests/simple1.ffconcat ../lavf/lavf.$(D)))
@@ -23,5 +25,9 @@ $(foreach D,$(FATE_CONCAT_DEMUXER_EXTENDED_LAVF),$(eval 
fate-concat-demuxer-exte
 $(foreach D,$(FATE_CONCAT_DEMUXER_EXTENDED_LAVF),$(eval 
fate-concat-demuxer-extended-lavf-$(D): CMD = concat 
$(SRC_PATH)/tests/extended.ffconcat ../lavf/lavf.$(D) md5))
 FATE_CONCAT_DEMUXER += 
$(FATE_CONCAT_DEMUXER_EXTENDED_LAVF:%=fate-concat-demuxer-extended-lavf-%)
 
+$(foreach D,$(FATE_CONCAT_DEMUXER_CHAPTERS_LAVF),$(eval 
fate-concat-demuxer-chapters-lavf-$(D): fate-lavf-$(D)))
+$(foreach D,$(FATE_CONCAT_DEMUXER_CHAPTERS_LAVF),$(eval 
fate-concat-demuxer-chapters-lavf-$(D): CMD = concat 
$(SRC_PATH)/tests/chapters.ffconcat ../lavf/lavf.$(D) "" "-show_chapters 
-chapter_per_file 1"))
+FATE_CONCAT_DEMUXER += 
$(FATE_CONCAT_DEMUXER_CHAPTERS_LAVF:%=fate-concat-demuxer-chapters-lavf-%)
+
 FATE_CONCAT_DEMUXER := $(if $(call ALLYES, CONCAT_DEMUXER 
EXTRACT_EXTRADATA_BSF), $(FATE_CONCAT_DEMUXER))
 FATE_FFPROBE += $(FATE_CONCAT_DEMUXER)
diff --git a/tests/ref/fate/concat-demuxer-chapters-lavf-mxf 
b/tests/ref/fate/concat-demuxer-chapters-lavf-mxf
new file mode 100644
index 0000000000..51a54a4614
--- /dev/null
+++ b/tests/ref/fate/concat-demuxer-chapters-lavf-mxf
@@ -0,0 +1,76 @@
+video|0|0|0.000000|-1|-0.040000|1|0.040000|24801|7168|K__
+audio|1|0|0.000000|0|0.000000|1920|0.040000|3840|32256|K__
+video|0|3|0.120000|0|0.000000|1|0.040000|16743|36864|___
+audio|1|1920|0.040000|1920|0.040000|1920|0.040000|3840|53760|K__
+video|0|1|0.040000|1|0.040000|1|0.040000|13812|58368|___
+audio|1|3840|0.080000|3840|0.080000|1920|0.040000|3840|72704|K__
+video|0|2|0.080000|2|0.080000|1|0.040000|13607|77312|___
+audio|1|5760|0.120000|5760|0.120000|1920|0.040000|3840|91136|K__
+video|0|6|0.240000|3|0.120000|1|0.040000|16158|95744|___
+audio|1|7680|0.160000|7680|0.160000|1920|0.040000|3840|112128|K__
+video|0|4|0.160000|4|0.160000|1|0.040000|13943|116736|___
+audio|1|9600|0.200000|9600|0.200000|1920|0.040000|3840|131072|K__
+video|0|5|0.200000|5|0.200000|1|0.040000|11223|135680|___
+audio|1|11520|0.240000|11520|0.240000|1920|0.040000|3840|146944|K__
+video|0|9|0.360000|6|0.240000|1|0.040000|20298|151552|___
+audio|1|13440|0.280000|13440|0.280000|1920|0.040000|3840|172032|K__
+video|0|7|0.280000|7|0.280000|1|0.040000|13341|176640|___
+audio|1|15360|0.320000|15360|0.320000|1920|0.040000|3840|190464|K__
+video|0|8|0.320000|8|0.320000|1|0.040000|12362|195072|___
+audio|1|17280|0.360000|17280|0.360000|1920|0.040000|3840|207872|K__
+video|0|12|0.480000|9|0.360000|1|0.040000|24786|212480|K__
+audio|1|19200|0.400000|19200|0.400000|1920|0.040000|3840|237568|K__
+video|0|10|0.400000|10|0.400000|1|0.040000|13377|242176|___
+audio|1|21120|0.440000|21120|0.440000|1920|0.040000|3840|256000|K__
+video|0|11|0.440000|11|0.440000|1|0.040000|15624|260608|___
+audio|1|23040|0.480000|23040|0.480000|1920|0.040000|3840|276480|K__
+video|0|15|0.600000|12|0.480000|1|0.040000|22597|281088|___
+audio|1|24960|0.520000|24960|0.520000|1920|0.040000|3840|304128|K__
+video|0|13|0.520000|13|0.520000|1|0.040000|15028|308736|___
+audio|1|26880|0.560000|26880|0.560000|1920|0.040000|3840|324096|K__
+video|0|14|0.560000|14|0.560000|1|0.040000|14014|328704|___
+audio|1|28800|0.600000|28800|0.600000|1920|0.040000|3840|343040|K__
+video|0|18|0.720000|15|0.600000|1|0.040000|20731|347648|___
+audio|1|30720|0.640000|30720|0.640000|1920|0.040000|3840|368640|K__
+video|0|16|0.640000|16|0.640000|1|0.040000|11946|373248|___
+audio|1|32640|0.680000|32640|0.680000|1920|0.040000|3840|385536|K__
+video|0|17|0.680000|17|0.680000|1|0.040000|14464|390144|___
+audio|1|34560|0.720000|34560|0.720000|1920|0.040000|3840|404992|K__
+video|0|21|0.840000|18|0.720000|1|0.040000|16189|409600|___
+audio|1|36480|0.760000|36480|0.760000|1920|0.040000|3840|425984|K__
+video|0|19|0.760000|19|0.760000|1|0.040000|10524|430592|___
+audio|1|38400|0.800000|38400|0.800000|1920|0.040000|3840|441344|K__
+video|0|20|0.800000|20|0.800000|1|0.040000|10599|445952|___
+audio|1|40320|0.840000|40320|0.840000|1920|0.040000|3840|456704|K__
+video|0|24|0.960000|21|0.840000|1|0.040000|24711|461312|K__
+audio|1|42240|0.880000|42240|0.880000|1920|0.040000|3840|486400|K__
+video|0|22|0.880000|22|0.880000|1|0.040000|10840|491008|___
+audio|1|44160|0.920000|44160|0.920000|1920|0.040000|3840|502272|K__
+video|0|23|0.920000|23|0.920000|1|0.040000|13350|506880|___
+audio|1|46080|0.960000|46080|0.960000|1920|0.040000|3840|520704|K__
+video|0|20|0.800000|19|0.760000|1|0.040000|24801|7168|K__
+audio|1|38400|0.800000|38400|0.800000|1920|0.040000|3840|32256|K__
+video|0|23|0.920000|20|0.800000|1|0.040000|16743|36864|___
+audio|1|40320|0.840000|40320|0.840000|1920|0.040000|3840|53760|K__
+video|0|21|0.840000|21|0.840000|1|0.040000|13812|58368|___
+audio|1|42240|0.880000|42240|0.880000|1920|0.040000|3840|72704|K__
+video|0|22|0.880000|22|0.880000|1|0.040000|13607|77312|___
+audio|1|44160|0.920000|44160|0.920000|1920|0.040000|3840|91136|K__
+video|0|26|1.040000|23|0.920000|1|0.040000|16158|95744|___
+audio|1|46080|0.960000|46080|0.960000|1920|0.040000|3840|112128|K__
+video|0|24|0.960000|24|0.960000|1|0.040000|13943|116736|___
+audio|1|48000|1.000000|48000|1.000000|1920|0.040000|3840|131072|K__
+video|0|25|1.000000|25|1.000000|1|0.040000|11223|135680|___
+audio|1|49920|1.040000|49920|1.040000|1920|0.040000|3840|146944|K__
+video|0|29|1.160000|26|1.040000|1|0.040000|20298|151552|___
+audio|1|51840|1.080000|51840|1.080000|1920|0.040000|3840|172032|K__
+video|0|27|1.080000|27|1.080000|1|0.040000|13341|176640|___
+audio|1|53760|1.120000|53760|1.120000|1920|0.040000|3840|190464|K__
+video|0|28|1.120000|28|1.120000|1|0.040000|12362|195072|___
+audio|1|55680|1.160000|55680|1.160000|1920|0.040000|3840|207872|K__
+video|0|32|1.280000|29|1.160000|1|0.040000|24786|212480|K__
+0|mpeg2video|4|video|[0][0][0][0]|0x0000|352|288|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|N/A|25/1|25/1|1/25|0|0.000000|30|1.200000|N/A|N/A|N/A|N/A|N/A|36|22|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001|CPB
 properties|0|0|0|49152|-1
+1|pcm_s16le|unknown|audio|[0][0][0][0]|0x0000|s16|48000|1|unknown|16|0|N/A|0/0|0/0|1/48000|0|0.000000|N/A|N/A|768000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001300000000000000000000000000000000000001
+11|1/1000000|0|0.000000|1000000|1.000000|lavf.mxf|060e2b34.04010101.0d010201.01010900|adab4424-2f25-4dc7-92ff-000c00000000|adab4424-2f25-4dc7-92ff-000c00000001|FFmpeg|OP1a
 
Muxer|0.0.0.0.0|0.0.0|Lavf|adab4424-2f25-4dc7-92ff-29bd000c0002|0.0.0.0.0|0x060A2B340101010501010D001300000000000000000000000000000000000000|00:00:00:00
+10|1/1000000|500000|0.500000|750000|0.750000
+12|1/1000000|1000000|1.000000|1200000|1.200000|lavf.mxf|060e2b34.04010101.0d010201.01010900|adab4424-2f25-4dc7-92ff-000c00000000|adab4424-2f25-4dc7-92ff-000c00000001|FFmpeg|OP1a
 
Muxer|0.0.0.0.0|0.0.0|Lavf|adab4424-2f25-4dc7-92ff-29bd000c0002|0.0.0.0.0|0x060A2B340101010501010D001300000000000000000000000000000000000000|00:00:00:00

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to