From dcbf72836c90d077067248a0ddc4e4c7556e2461 Mon Sep 17 00:00:00 2001
From: Tim Nicholson <Tim.Nicholson@bbc.co.uk>
Date: Fri, 2 Nov 2012 13:09:48 +0000
Subject: [PATCH] ffmpeg: add setting of field_order flag

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
---
 ffmpeg.c                             | 12 ++++++++++++
 tests/ref/fate/vsynth1-prores        |  4 ++--
 tests/ref/fate/vsynth1-prores_kostya |  4 ++--
 tests/ref/fate/vsynth1-qtrle         |  4 ++--
 tests/ref/fate/vsynth1-qtrlegray     |  4 ++--
 tests/ref/fate/vsynth1-svq1          |  4 ++--
 tests/ref/fate/vsynth2-prores        |  4 ++--
 tests/ref/fate/vsynth2-prores_kostya |  4 ++--
 tests/ref/fate/vsynth2-qtrle         |  4 ++--
 tests/ref/fate/vsynth2-qtrlegray     |  4 ++--
 tests/ref/fate/vsynth2-svq1          |  4 ++--
 11 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 71a9bea77e5..2c3dfa21ae3 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -846,6 +846,10 @@ static void do_video_out(AVFormatContext *s,
            method. */
         enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;
         enc->coded_frame->top_field_first  = in_picture->top_field_first;
+        if (enc->coded_frame->interlaced_frame)
+            enc->field_order = enc->coded_frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
+        else
+            enc->field_order = AV_FIELD_PROGRESSIVE;
         pkt.data   = (uint8_t *)in_picture;
         pkt.size   =  sizeof(AVPicture);
         pkt.pts    = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base);
@@ -868,6 +872,14 @@ static void do_video_out(AVFormatContext *s,
                 big_picture.top_field_first = !!ost->top_field_first;
         }
 
+        if (big_picture.interlaced_frame) {
+            if (enc->codec->id == AV_CODEC_ID_MJPEG)
+                enc->field_order = big_picture.top_field_first ? AV_FIELD_TT:AV_FIELD_BB;
+            else
+                enc->field_order = big_picture.top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
+        } else
+            enc->field_order = AV_FIELD_PROGRESSIVE;
+
         big_picture.quality = ost->st->codec->global_quality;
         if (!enc->me_threshold)
             big_picture.pict_type = 0;
diff --git a/tests/ref/fate/vsynth1-prores b/tests/ref/fate/vsynth1-prores
index d13bd309ac3..16517ee26ef 100644
--- a/tests/ref/fate/vsynth1-prores
+++ b/tests/ref/fate/vsynth1-prores
@@ -1,4 +1,4 @@
-17a598a8cc6b899c79e3c69b9679e08d *tests/data/fate/vsynth1-prores.mov
-5022811 tests/data/fate/vsynth1-prores.mov
+6f7ce83099b35e5af0cf484f2e9f1f4f *tests/data/fate/vsynth1-prores.mov
+5022821 tests/data/fate/vsynth1-prores.mov
 a2e2d1d45341a94ff994d1d92629f778 *tests/data/fate/vsynth1-prores.out.rawvideo
 stddev:    2.47 PSNR: 40.27 MAXDIFF:   31 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth1-prores_kostya b/tests/ref/fate/vsynth1-prores_kostya
index aa28aa23b28..ab6ecffa965 100644
--- a/tests/ref/fate/vsynth1-prores_kostya
+++ b/tests/ref/fate/vsynth1-prores_kostya
@@ -1,4 +1,4 @@
-504b53c891d5bd917d5cf5190c312a20 *tests/data/fate/vsynth1-prores_kostya.mov
-3858901 tests/data/fate/vsynth1-prores_kostya.mov
+36411e06db3f86ddedd6171a56784d6b *tests/data/fate/vsynth1-prores_kostya.mov
+3858911 tests/data/fate/vsynth1-prores_kostya.mov
 0a4153637d0cc0a88a8bcbf04cfaf8c6 *tests/data/fate/vsynth1-prores_kostya.out.rawvideo
 stddev:    3.17 PSNR: 38.09 MAXDIFF:   39 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth1-qtrle b/tests/ref/fate/vsynth1-qtrle
index 081707d0e0f..9bd79cc60b2 100644
--- a/tests/ref/fate/vsynth1-qtrle
+++ b/tests/ref/fate/vsynth1-qtrle
@@ -1,4 +1,4 @@
-f66efb8a1fd455ef31de540df9a81909 *tests/data/fate/vsynth1-qtrle.mov
-15263148 tests/data/fate/vsynth1-qtrle.mov
+4eaa59011403ce3e53f8abb5cf6d26e5 *tests/data/fate/vsynth1-qtrle.mov
+15263158 tests/data/fate/vsynth1-qtrle.mov
 93695a27c24a61105076ca7b1f010bbd *tests/data/fate/vsynth1-qtrle.out.rawvideo
 stddev:    3.42 PSNR: 37.44 MAXDIFF:   48 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth1-qtrlegray b/tests/ref/fate/vsynth1-qtrlegray
index 99ec831c2a7..425c11f2e64 100644
--- a/tests/ref/fate/vsynth1-qtrlegray
+++ b/tests/ref/fate/vsynth1-qtrlegray
@@ -1,4 +1,4 @@
-a9f365910ce1eb0ccbc05b68ca7cfafb *tests/data/fate/vsynth1-qtrlegray.mov
-5113284 tests/data/fate/vsynth1-qtrlegray.mov
+d010ff7be190f4cd053d79ee7f601ce2 *tests/data/fate/vsynth1-qtrlegray.mov
+5113294 tests/data/fate/vsynth1-qtrlegray.mov
 29def4aed035ed65d3a89f7d382fccbe *tests/data/fate/vsynth1-qtrlegray.out.rawvideo
 stddev:   25.95 PSNR: 19.85 MAXDIFF:  122 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth1-svq1 b/tests/ref/fate/vsynth1-svq1
index 7468b36e4d2..6be76e184c3 100644
--- a/tests/ref/fate/vsynth1-svq1
+++ b/tests/ref/fate/vsynth1-svq1
@@ -1,4 +1,4 @@
-f2930c19bd18eb03c1f984a72cdb67c8 *tests/data/fate/vsynth1-svq1.mov
-1334223 tests/data/fate/vsynth1-svq1.mov
+ea441979fa5bf694d1f6cee958d56560 *tests/data/fate/vsynth1-svq1.mov
+1334233 tests/data/fate/vsynth1-svq1.mov
 9cc35c54b2c77d36bd7e308b393c1f81 *tests/data/fate/vsynth1-svq1.out.rawvideo
 stddev:    9.58 PSNR: 28.50 MAXDIFF:  210 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth2-prores b/tests/ref/fate/vsynth2-prores
index 089fc6c1f08..b5c80e25c66 100644
--- a/tests/ref/fate/vsynth2-prores
+++ b/tests/ref/fate/vsynth2-prores
@@ -1,4 +1,4 @@
-2fb771b09172b82d045772b60084c923 *tests/data/fate/vsynth2-prores.mov
-2844066 tests/data/fate/vsynth2-prores.mov
+a6351254cccdbc7147600951a798172a *tests/data/fate/vsynth2-prores.mov
+2844076 tests/data/fate/vsynth2-prores.mov
 b5844025c0f4c7c37db702c3213db232 *tests/data/fate/vsynth2-prores.out.rawvideo
 stddev:    1.31 PSNR: 45.77 MAXDIFF:   11 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth2-prores_kostya b/tests/ref/fate/vsynth2-prores_kostya
index 3566f1da3c1..16b6078ec05 100644
--- a/tests/ref/fate/vsynth2-prores_kostya
+++ b/tests/ref/fate/vsynth2-prores_kostya
@@ -1,4 +1,4 @@
-fcfd0e077ed36d46719d34248c0d6281 *tests/data/fate/vsynth2-prores_kostya.mov
-3884586 tests/data/fate/vsynth2-prores_kostya.mov
+7de64c634620de738c98aa22e9df927d *tests/data/fate/vsynth2-prores_kostya.mov
+3884596 tests/data/fate/vsynth2-prores_kostya.mov
 ca2f6c1162635dedfa468c90f1fdc0ef *tests/data/fate/vsynth2-prores_kostya.out.rawvideo
 stddev:    0.92 PSNR: 48.77 MAXDIFF:   10 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth2-qtrle b/tests/ref/fate/vsynth2-qtrle
index b29b7ccf2f1..5f536087ce3 100644
--- a/tests/ref/fate/vsynth2-qtrle
+++ b/tests/ref/fate/vsynth2-qtrle
@@ -1,4 +1,4 @@
-7ff87d3858b742ef2d72a7dd12dea019 *tests/data/fate/vsynth2-qtrle.mov
-14798335 tests/data/fate/vsynth2-qtrle.mov
+f2aea57de225cccadb936bba4086a836 *tests/data/fate/vsynth2-qtrle.mov
+14798345 tests/data/fate/vsynth2-qtrle.mov
 98d0e2854731472c5bf13d8638502d0a *tests/data/fate/vsynth2-qtrle.out.rawvideo
 stddev:    1.26 PSNR: 46.10 MAXDIFF:   13 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth2-qtrlegray b/tests/ref/fate/vsynth2-qtrlegray
index 6fa35d1fe6b..45683919ba2 100644
--- a/tests/ref/fate/vsynth2-qtrlegray
+++ b/tests/ref/fate/vsynth2-qtrlegray
@@ -1,4 +1,4 @@
-4d4eac9e7258dde5fbafe931c4bdca59 *tests/data/fate/vsynth2-qtrlegray.mov
-5111273 tests/data/fate/vsynth2-qtrlegray.mov
+fa10a87e9cf648d635340b90e41d2d38 *tests/data/fate/vsynth2-qtrlegray.mov
+5111283 tests/data/fate/vsynth2-qtrlegray.mov
 f63b5ebdfdba750e547c25131b0a3fd1 *tests/data/fate/vsynth2-qtrlegray.out.rawvideo
 stddev:   19.42 PSNR: 22.36 MAXDIFF:   72 bytes:  7603200/  7603200
diff --git a/tests/ref/fate/vsynth2-svq1 b/tests/ref/fate/vsynth2-svq1
index ec9cf88be61..bdde55e7a30 100644
--- a/tests/ref/fate/vsynth2-svq1
+++ b/tests/ref/fate/vsynth2-svq1
@@ -1,4 +1,4 @@
-c0a8f7e727a521ff3c1f6f9bd163e63d *tests/data/fate/vsynth2-svq1.mov
-766691 tests/data/fate/vsynth2-svq1.mov
+11da7948184b3fee455f66cc5f6f8ca5 *tests/data/fate/vsynth2-svq1.mov
+766701 tests/data/fate/vsynth2-svq1.mov
 aa03471dac3f49455a33a2b19fda1098 *tests/data/fate/vsynth2-svq1.out.rawvideo
 stddev:    3.23 PSNR: 37.93 MAXDIFF:   61 bytes:  7603200/  7603200
-- 
GitLab