Commit cf5dd2e0b9 for ffmpeg

commit cf5dd2e0b90980ec4e2365659bf3c75d87cda0f0
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date:   Mon Nov 23 15:19:17 2026 -0800

    avformat/mxfenc: signal interlaced ProRes

    Write separate fields and BFF DisplayF2Offset -1 per RDD 44 Table 6.
    Keep the generic VideoLineMap and write PsF as a full frame, which
    Apple's MXF reader needs.

    Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index c2d14bb776..52feae7271 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -108,7 +108,8 @@ typedef struct MXFStreamContext {
     UID clip_container_ul;   ///< clip wrapping essence container ul, used by OPAtom
     int order;               ///< interleaving order if dts are equal
     int interlaced;          ///< whether picture is interlaced
-    int field_dominance;     ///< tff=1, bff=2
+    int field_dominance;     ///< first field in temporal order, 1 or 2
+    int display_f2_offset;   ///< DisplayF2Offset, 0 or -1
     int signal_standard;
     int temporal_reordering;
     AVRational aspect_ratio; ///< display aspect ratio
@@ -1383,7 +1384,7 @@ static int64_t mxf_write_generic_picture_desc(AVFormatContext *s, AVStream *st)
     if (sc->interlaced) {
         //Display F2 Offset
         mxf_write_local_tag(s, 4, 0x3217);
-        avio_wb32(pb, -((st->codecpar->height - display_height)&1));
+        avio_wb32(pb, sc->display_f2_offset);
     }

     if (sc->picture_descriptor_key == &mxf_rgba_descriptor_key) {
@@ -2433,6 +2434,8 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk

     /* frame header color fields, SMPTE RDD 36 */
     if (pkt->size >= 25 && AV_RL32(pkt->data + 4) == AV_RL32("icpf")) {
+        int interlace_mode = (pkt->data[8 + 12] >> 2) & 3;
+
         if (pkt->data[22]) // 0 is unknown
             sc->color_primaries = pkt->data[22];
         /* code 1 covers BT.601, BT.709 and BT.2020, keep a more precise stream value */
@@ -2444,6 +2447,17 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk
             sc->color_trc = pkt->data[23];
         if (pkt->data[24]) // 0 is unknown, not RGB
             sc->color_space = pkt->data[24];
+
+        // interlace_mode: 1 top field first, 2 bottom field first,
+        // RDD 44 Table 6 also signals bottom field first with DisplayF2Offset -1.
+        // Fields of a stream marked progressive (PsF) stay a full frame.
+        if (st->codecpar->field_order != AV_FIELD_PROGRESSIVE &&
+            (interlace_mode == 1 || interlace_mode == 2)) {
+            sc->interlaced        = 1;
+            // Field 1 is first in both modes; the offset puts it below field 2 for BFF.
+            sc->field_dominance   = 1;
+            sc->display_f2_offset = -(interlace_mode == 2);
+        }
     }

     sc->frame_size = pkt->size;
diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak
index 9775ad25fa..d8e822b94a 100644
--- a/tests/fate/mxf.mak
+++ b/tests/fate/mxf.mak
@@ -88,9 +88,17 @@ fate-mxf-opatom-user-comments: CMD = md5 -y -i $(TARGET_SAMPLES)/mxf/Sony-00001.
 FATE_MXF-$(call REMUX, MXF_OPATOM MXF, DVVIDEO_DECODER) += fate-mxf-remux-opatom-dv25
 fate-mxf-remux-opatom-dv25: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Avid-00005.mxf mxf_opatom "-map 0:v -c copy" "-c copy"

+# Interlaced ProRes BFF on a 625 line raster: DisplayF2Offset -1, read from the descriptor.
+MXF_PRORES_DEPS = FFMPEG FFPROBE RAWVIDEO_DEMUXER RAWVIDEO_DECODER SCALE_FILTER FORMAT_FILTER SETFIELD_FILTER
+FATE_MXF_PRORES_FIELDS-$(call TRANSCODE, PRORES, MXF, $(MXF_PRORES_DEPS)) += fate-mxf-prores-bff
+fate-mxf-prores-bff: CMD = transcode "rawvideo -s 352x288 -pix_fmt yuv420p" tests/data/vsynth1.yuv mxf \
+    "-frames:v 2 -vf scale=720:576,format=yuv422p10,setfield=bff -c:v prores -flags +ildct" "-c copy" "-nofind_stream_info -show_entries stream=field_order"
+$(FATE_MXF_PRORES_FIELDS-yes): tests/data/vsynth1.yuv
+
 FATE_SAMPLES_FFMPEG += $(FATE_MXF-yes)
 FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MXF_FFMPEG_FFPROBE-yes)
 FATE_SAMPLES_FFPROBE += $(FATE_MXF_PROBE-yes)
+FATE_FFMPEG_FFPROBE += $(FATE_MXF_PRORES_FIELDS-yes)

 # Cross the 64 KiB IndexEntryArray limit, so that the index table is split.
 FATE_MXF_INDEX-$(call ENCMUX, MPEG2VIDEO, MXF_OPATOM, COLOR_FILTER FILE_PROTOCOL) += fate-mxf-opatom-index-segments
@@ -122,4 +130,4 @@ FATE_FFMPEG_FFPROBE += $(FATE_MXF_INDEX_FFPROBE-yes)

 fate-mxf: $(if $(CONFIG_FFMPEG),$(FATE_MXF-yes) $(FATE_MXF_INDEX-yes))
 fate-mxf: $(if $(CONFIG_FFPROBE),$(FATE_MXF_PROBE-yes))
-fate-mxf: $(if $(call ALLYES, FFMPEG FFPROBE),$(FATE_MXF_FFMPEG_FFPROBE-yes) $(FATE_MXF_INDEX_FFPROBE-yes))
+fate-mxf: $(if $(call ALLYES, FFMPEG FFPROBE),$(FATE_MXF_FFMPEG_FFPROBE-yes) $(FATE_MXF_INDEX_FFPROBE-yes) $(FATE_MXF_PRORES_FIELDS-yes))
diff --git a/tests/ref/fate/mxf-prores-bff b/tests/ref/fate/mxf-prores-bff
new file mode 100644
index 0000000000..e60e303301
--- /dev/null
+++ b/tests/ref/fate/mxf-prores-bff
@@ -0,0 +1,12 @@
+0cf832163004521332af6a1b98cdb86d *tests/data/fate/mxf-prores-bff.mxf
+599609 tests/data/fate/mxf-prores-bff.mxf
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: prores
+#dimensions 0: 720x576
+#sar 0: 0/1
+0,          0,          0,        1,   295569, 0x2fe31ee1
+0,          1,          1,        1,   295498, 0x9a2fdbde
+[STREAM]
+field_order=bb
+[/STREAM]