diff mbox series

[FFmpeg-devel,1/3] fftools/ffmpeg_enc: refactor setting encoding field_order

Message ID 20230914151020.10415-1-anton@khirnov.net
State Accepted
Commit 74b643a51e05ee816b810b86974f675eb46ab2cf
Headers show
Series [FFmpeg-devel,1/3] fftools/ffmpeg_enc: refactor setting encoding field_order | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Sept. 14, 2023, 3:10 p.m. UTC
Merge three blocks with slightly inconsistent checks into one, treating
encoder input as interlaced when either:
* at least one of ilme/ildct flags is set
* the first frame in the stream is marked as interlaced
* the user specified the -top option

Stop modifying the frame passed to enc_open().
---
 fftools/ffmpeg_enc.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

Comments

Anton Khirnov Sept. 18, 2023, 3:19 p.m. UTC | #1
Set pushed.
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f28884e50c..e878eb02b4 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -356,29 +356,18 @@  int enc_open(OutputStream *ost, AVFrame *frame)
         enc_ctx->colorspace             = frame->colorspace;
         enc_ctx->chroma_sample_location = frame->chroma_location;
 
-        // Field order: autodetection
-        if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&
-            ost->top_field_first >= 0)
-            if (ost->top_field_first)
-                frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
-            else
-                frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
+        if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) ||
+            (frame->flags & AV_FRAME_FLAG_INTERLACED) || ost->top_field_first >= 0) {
+            int top_field_first = ost->top_field_first >= 0 ?
+                ost->top_field_first : !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
 
-        if (frame->flags & AV_FRAME_FLAG_INTERLACED) {
             if (enc->id == AV_CODEC_ID_MJPEG)
-                enc_ctx->field_order = (frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? AV_FIELD_TT:AV_FIELD_BB;
+                enc_ctx->field_order = top_field_first ? AV_FIELD_TT : AV_FIELD_BB;
             else
-                enc_ctx->field_order = (frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? AV_FIELD_TB:AV_FIELD_BT;
+                enc_ctx->field_order = top_field_first ? AV_FIELD_TB : AV_FIELD_BT;
         } else
             enc_ctx->field_order = AV_FIELD_PROGRESSIVE;
 
-        // Field order: override
-        if (ost->top_field_first == 0) {
-            enc_ctx->field_order = AV_FIELD_BB;
-        } else if (ost->top_field_first == 1) {
-            enc_ctx->field_order = AV_FIELD_TT;
-        }
-
         break;
         }
     case AVMEDIA_TYPE_SUBTITLE: