[PR] avformat/movenc: preserve timecode flags when copying tmcd tracks (PR #24078)

Théo Valette via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178645245958.59.7990614458260499764@29965ddac10e>
PR #24078 opened by Théo Valette (theovalette)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24078
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24078.patch

When a MOV `tmcd` data track is explicitly stream-copied, its four-byte frame counter remains unchanged but the output sample description currently clears the timecode flags. A drop-frame counter such as `01:00:00;00` is consequently read back as non-drop-frame `00:59:56:12`.

The MOV demuxer retains the input `tmcd` sample description in codec extradata. The muxer reconstructs that description from `MOVTrack.timecode_flags`, but only muxer-generated metadata timecode tracks initialized the field. Copied tracks therefore wrote its zero-initialized value.

Initialize the complete 32-bit flags field from validated codec extradata when setting up a copied `tmcd` track. This preserves drop-frame and the other defined timecode flags without changing the media packet. The existing `fate-copy-trac236` stream-copy test contains three drop-frame `tmcd` tracks; its reference checksum is updated to cover the preserved descriptions.

Tests:

- Self-contained issue reproducer: fixed output reports `01:00:00;00`, flag word `00000001`, and the unchanged packet MD5 `c6284ce0070c9f5dc266182e85ffd541`.
- `make fate-copy-trac236` with the official FATE sample path configured
- `make fate-lavf-mov`
- Minimal MOV-only configure, build, stream copy, and probe
- `git diff --check HEAD^ HEAD`
- `tools/patcheck` (only the minor-change changelog hint)

Fixes https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20841


From 100d4fa65b53f17b6b0ef0107007b1f8c34386d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Valette?=
 <[email protected]>
Date: Tue, 11 Aug 2026 14:35:20 +0200
Subject: [PATCH] avformat/movenc: preserve timecode flags when copying tmcd
 tracks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The MOV demuxer retains tmcd timecode flags in codec extradata, but copied
tracks never initialize MOVTrack.timecode_flags. mov_write_tmcd_tag()
therefore writes zero when reconstructing the sample description, causing
unchanged frame counters to be interpreted as non-drop-frame.

Initialize the complete flags field from sample-description extradata for
copied tmcd tracks. fate-copy-trac236 covers three drop-frame tmcd tracks.

Fixes issue #20841.

Reported-by: unsword01 <[email protected]>
Signed-off-by: Théo Valette <[email protected]>
---
 libavformat/movenc.c        | 3 +++
 tests/ref/fate/copy-trac236 | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 2a3226c70f..bd8e2b2127 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -8633,6 +8633,9 @@ static int mov_init(AVFormatContext *s)
             }
         } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
             track->timescale = st->time_base.den;
+            if (track->tag == MKTAG('t','m','c','d') &&
+                st->codecpar->extradata_size >= 8)
+                track->timecode_flags = AV_RB32(st->codecpar->extradata + 4);
         } else {
             track->timescale = mov->movie_timescale;
         }
diff --git a/tests/ref/fate/copy-trac236 b/tests/ref/fate/copy-trac236
index 016492cf23..187d598900 100644
--- a/tests/ref/fate/copy-trac236
+++ b/tests/ref/fate/copy-trac236
@@ -1,4 +1,4 @@
-1683aff9357630012ded47d7e45d2c8a *tests/data/fate/copy-trac236.mov
+1aba24bd0b58133d3c59bccde9daad08 *tests/data/fate/copy-trac236.mov
 630918 tests/data/fate/copy-trac236.mov
 #tb 0: 100/2997
 #media_type 0: video
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.