PR #26145 opened by Baptiste Coudurier (bcoudurier)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26145
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26145.patch

# Summary of changes

Select DVCPRO HD MOV sample-entry tags from the average frame rate and field 
order. A MOV track timescale need not equal the video frame rate: a 25 fps 
stream with a time base of 1/600 currently selects `dvh6` instead of `dvh5`, 
and a 50 fps 720-line stream selects `dvhp` instead of `dvhq`. The 1080-line 
path also selects interlaced tags for progressive video.

Use `avg_frame_rate`, falling back to the inverse time base when the frame rate 
is unavailable, and select `dvh2`/`dvh3` for progressive 1080-line streams. 
Keep the existing SD tag selection.

Add 11 generated FATE cases covering DV25, DV50 and DV100, including 
PAL/NTSC-family rates and progressive/interlaced HD. Each case encodes with a 
MOV track timescale of 600, stream-copies the result, and checks both 
sample-entry tags. No external test samples are required.

Validation: all 11 `fate-mov-dv-tag-*` tests pass; `git diff --check` passes.



>From 33578f7b5da8b4d52f075f26e25572ea821a84b7 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sun, 15 Nov 2026 14:53:54 -0800
Subject: [PATCH] avformat/movenc: select DVCPRO HD tags from frame rate and
 field order

A MOV track timescale need not equal the video frame rate. Comparing the time 
base denominator with 25 or 50 misidentifies 50 Hz DVCPRO HD streams after 
demuxing a MOV file with a different timescale.

Use the average frame rate, falling back to the inverse time base when it is 
unavailable. Select the progressive 1080-line sample entries when the field 
order is progressive. Add generated encode and remux coverage for DV25, DV50 
and DV100 tags with a track timescale of 600.
---
 libavformat/movenc.c              | 13 ++++++++++---
 tests/fate-run.sh                 | 18 ++++++++++++++++++
 tests/fate/mov.mak                | 20 ++++++++++++++++++++
 tests/ref/fate/mov-dv-tag-1080i50 |  2 ++
 tests/ref/fate/mov-dv-tag-1080i60 |  2 ++
 tests/ref/fate/mov-dv-tag-1080p25 |  2 ++
 tests/ref/fate/mov-dv-tag-1080p30 |  2 ++
 tests/ref/fate/mov-dv-tag-50-ntsc |  2 ++
 tests/ref/fate/mov-dv-tag-50-pal  |  2 ++
 tests/ref/fate/mov-dv-tag-720p50  |  2 ++
 tests/ref/fate/mov-dv-tag-720p60  |  2 ++
 tests/ref/fate/mov-dv-tag-ntsc    |  2 ++
 tests/ref/fate/mov-dv-tag-pal     |  2 ++
 tests/ref/fate/mov-dv-tag-pro-pal |  2 ++
 14 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 tests/ref/fate/mov-dv-tag-1080i50
 create mode 100644 tests/ref/fate/mov-dv-tag-1080i60
 create mode 100644 tests/ref/fate/mov-dv-tag-1080p25
 create mode 100644 tests/ref/fate/mov-dv-tag-1080p30
 create mode 100644 tests/ref/fate/mov-dv-tag-50-ntsc
 create mode 100644 tests/ref/fate/mov-dv-tag-50-pal
 create mode 100644 tests/ref/fate/mov-dv-tag-720p50
 create mode 100644 tests/ref/fate/mov-dv-tag-720p60
 create mode 100644 tests/ref/fate/mov-dv-tag-ntsc
 create mode 100644 tests/ref/fate/mov-dv-tag-pal
 create mode 100644 tests/ref/fate/mov-dv-tag-pro-pal

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 27e1dd77188..2bd14ed4516 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1963,6 +1963,11 @@ static int mov_write_dpxe_tag(AVIOContext *pb, MOVTrack 
*track)
 static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
     int tag;
+    AVRational rate = track->st->avg_frame_rate;
+    int progressive = track->par->field_order == AV_FIELD_PROGRESSIVE;
+
+    if (!rate.num || !rate.den)
+        rate = av_inv_q(track->st->time_base);
 
     if (track->par->width == 720) { /* SD */
         if (track->par->height == 480) { /* NTSC */
@@ -1972,11 +1977,13 @@ static int mov_get_dv_codec_tag(AVFormatContext *s, 
MOVTrack *track)
         else if (track->par->format == AV_PIX_FMT_YUV420P) tag = 
MKTAG('d','v','c','p');
         else                                                tag = 
MKTAG('d','v','p','p');
     } else if (track->par->height == 720) { /* HD 720 line */
-        if  (track->st->time_base.den == 50)                tag = 
MKTAG('d','v','h','q');
+        if  (!av_cmp_q(rate, (AVRational){ 50, 1 }))        tag = 
MKTAG('d','v','h','q');
         else                                                tag = 
MKTAG('d','v','h','p');
     } else if (track->par->height == 1080) { /* HD 1080 line */
-        if  (track->st->time_base.den == 25)                tag = 
MKTAG('d','v','h','5');
-        else                                                tag = 
MKTAG('d','v','h','6');
+        if  (!av_cmp_q(rate, (AVRational){ 25, 1 }))
+            tag = progressive ? MKTAG('d','v','h','2') : 
MKTAG('d','v','h','5');
+        else
+            tag = progressive ? MKTAG('d','v','h','3') : 
MKTAG('d','v','h','6');
     } else {
         av_log(s, AV_LOG_ERROR, "unsupported height for dv codec\n");
         return 0;
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 3c265fce2d4..59c3ca35976 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -337,6 +337,24 @@ transcode(){
         run ffprobe${PROGSUF}${EXECSUF} -bitexact -threads $threads 
$ffprobe_opts $tencfile || return
 }
 
+mov_dv_codec_tag(){
+    size=$1
+    rate=$2
+    pix_fmt=$3
+    field=$4
+    srcfile=${outdir}/${test}-src.mov
+    dstfile=${outdir}/${test}.mov
+    test $keep -ge 1 || cleanfiles="$cleanfiles $srcfile $dstfile"
+    ffmpeg -f lavfi -i 
"testsrc2=size=$size:rate=$rate,format=$pix_fmt,setfield=$field" \
+        -frames:v 2 -c:v dvvideo -threads 1 -video_track_timescale 600 \
+        -f mov -y $(target_path $srcfile) || return
+    ffmpeg -i $(target_path $srcfile) -c:v copy -f mov -y $(target_path 
$dstfile) || return
+    run ffprobe${PROGSUF}${EXECSUF} -v error -show_entries 
stream=codec_tag_string,codec_tag \
+        -of compact=p=0 $(target_path $srcfile) || return
+    run ffprobe${PROGSUF}${EXECSUF} -v error -show_entries 
stream=codec_tag_string,codec_tag \
+        -of compact=p=0 $(target_path $dstfile)
+}
+
 stream_demux(){
     src_fmt=$1
     srcfile=$2
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index bb94f66f67d..d13a82ace9e 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -635,6 +635,26 @@ fate-mov-chpl-utf8: tests/data/chpl-utf8.ffmeta
 FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, COLOR_FILTER MPEG4_ENCODER 
FFMETADATA_DEMUXER TGP_MUXER MOV_DEMUXER FILE_PROTOCOL) += fate-mov-chpl-utf8
 fate-mov-chpl-utf8: CMD = run_with_temp "$(FFMPEG) -nostdin -v error 
-filter_complex color=c=black:s=2x2:r=1 -f ffmetadata -i 
$(TARGET_PATH)/tests/data/chpl-utf8.ffmeta -map_chapters 0 -frames:v 1 -c:v 
mpeg4 -threads 1 -flags +bitexact -fflags +bitexact -f 3gp -y" 
"ffprobe$(PROGSSUF)$(EXESUF) -loglevel error -bitexact -show_chapters" 3gp
 
+# Use a track timescale different from the frame rate, then stream copy.
+define MOV_DV_TAG
+FATE_MOV_FFMPEG_FFPROBE-$$(call ALLYES, DVVIDEO_ENCODER DVVIDEO_DECODER \
+    MOV_MUXER MOV_DEMUXER LAVFI_INDEV TESTSRC2_FILTER FORMAT_FILTER \
+    SETFIELD_FILTER WRAPPED_AVFRAME_DECODER FILE_PROTOCOL) += 
fate-mov-dv-tag-$(1)
+fate-mov-dv-tag-$(1): CMD = mov_dv_codec_tag $(2) $(3) $(4) $(5)
+endef
+
+$(eval $(call MOV_DV_TAG,ntsc,720x480,30000/1001,yuv411p,bff))
+$(eval $(call MOV_DV_TAG,pal,720x576,25,yuv420p,bff))
+$(eval $(call MOV_DV_TAG,pro-pal,720x576,25,yuv411p,bff))
+$(eval $(call MOV_DV_TAG,50-ntsc,720x480,30000/1001,yuv422p,bff))
+$(eval $(call MOV_DV_TAG,50-pal,720x576,25,yuv422p,bff))
+$(eval $(call MOV_DV_TAG,720p50,960x720,50,yuv422p,prog))
+$(eval $(call MOV_DV_TAG,720p60,960x720,60000/1001,yuv422p,prog))
+$(eval $(call MOV_DV_TAG,1080i50,1440x1080,25,yuv422p,tff))
+$(eval $(call MOV_DV_TAG,1080i60,1280x1080,30000/1001,yuv422p,tff))
+$(eval $(call MOV_DV_TAG,1080p25,1440x1080,25,yuv422p,prog))
+$(eval $(call MOV_DV_TAG,1080p30,1280x1080,30000/1001,yuv422p,prog))
+
 FATE_FFMPEG += $(FATE_MOV_FFMPEG-yes)
 FATE_FFMPEG_FFPROBE += $(FATE_MOV_FFMPEG_FFPROBE-yes)
 
diff --git a/tests/ref/fate/mov-dv-tag-1080i50 
b/tests/ref/fate/mov-dv-tag-1080i50
new file mode 100644
index 00000000000..bf1211dcf42
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-1080i50
@@ -0,0 +1,2 @@
+codec_tag_string=dvh5|codec_tag=0x35687664
+codec_tag_string=dvh5|codec_tag=0x35687664
diff --git a/tests/ref/fate/mov-dv-tag-1080i60 
b/tests/ref/fate/mov-dv-tag-1080i60
new file mode 100644
index 00000000000..e8605293e3c
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-1080i60
@@ -0,0 +1,2 @@
+codec_tag_string=dvh6|codec_tag=0x36687664
+codec_tag_string=dvh6|codec_tag=0x36687664
diff --git a/tests/ref/fate/mov-dv-tag-1080p25 
b/tests/ref/fate/mov-dv-tag-1080p25
new file mode 100644
index 00000000000..1939e8aec6e
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-1080p25
@@ -0,0 +1,2 @@
+codec_tag_string=dvh2|codec_tag=0x32687664
+codec_tag_string=dvh2|codec_tag=0x32687664
diff --git a/tests/ref/fate/mov-dv-tag-1080p30 
b/tests/ref/fate/mov-dv-tag-1080p30
new file mode 100644
index 00000000000..9f184ab3403
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-1080p30
@@ -0,0 +1,2 @@
+codec_tag_string=dvh3|codec_tag=0x33687664
+codec_tag_string=dvh3|codec_tag=0x33687664
diff --git a/tests/ref/fate/mov-dv-tag-50-ntsc 
b/tests/ref/fate/mov-dv-tag-50-ntsc
new file mode 100644
index 00000000000..c63bbf83804
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-50-ntsc
@@ -0,0 +1,2 @@
+codec_tag_string=dv5n|codec_tag=0x6e357664
+codec_tag_string=dv5n|codec_tag=0x6e357664
diff --git a/tests/ref/fate/mov-dv-tag-50-pal b/tests/ref/fate/mov-dv-tag-50-pal
new file mode 100644
index 00000000000..2572830a38c
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-50-pal
@@ -0,0 +1,2 @@
+codec_tag_string=dv5p|codec_tag=0x70357664
+codec_tag_string=dv5p|codec_tag=0x70357664
diff --git a/tests/ref/fate/mov-dv-tag-720p50 b/tests/ref/fate/mov-dv-tag-720p50
new file mode 100644
index 00000000000..bd3cfee77e9
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-720p50
@@ -0,0 +1,2 @@
+codec_tag_string=dvhq|codec_tag=0x71687664
+codec_tag_string=dvhq|codec_tag=0x71687664
diff --git a/tests/ref/fate/mov-dv-tag-720p60 b/tests/ref/fate/mov-dv-tag-720p60
new file mode 100644
index 00000000000..ed180270106
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-720p60
@@ -0,0 +1,2 @@
+codec_tag_string=dvhp|codec_tag=0x70687664
+codec_tag_string=dvhp|codec_tag=0x70687664
diff --git a/tests/ref/fate/mov-dv-tag-ntsc b/tests/ref/fate/mov-dv-tag-ntsc
new file mode 100644
index 00000000000..bf34e0127cc
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-ntsc
@@ -0,0 +1,2 @@
+codec_tag_string=dvc |codec_tag=0x20637664
+codec_tag_string=dvc |codec_tag=0x20637664
diff --git a/tests/ref/fate/mov-dv-tag-pal b/tests/ref/fate/mov-dv-tag-pal
new file mode 100644
index 00000000000..9696d30f333
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-pal
@@ -0,0 +1,2 @@
+codec_tag_string=dvcp|codec_tag=0x70637664
+codec_tag_string=dvcp|codec_tag=0x70637664
diff --git a/tests/ref/fate/mov-dv-tag-pro-pal 
b/tests/ref/fate/mov-dv-tag-pro-pal
new file mode 100644
index 00000000000..da9ce45ee0c
--- /dev/null
+++ b/tests/ref/fate/mov-dv-tag-pro-pal
@@ -0,0 +1,2 @@
+codec_tag_string=dvpp|codec_tag=0x70707664
+codec_tag_string=dvpp|codec_tag=0x70707664
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to