From patchwork Thu Sep 14 15:10:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 43728 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b2f:b0:149:dfde:5c0a with SMTP id fp47csp482589pzb; Thu, 14 Sep 2023 08:11:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPw3Dx9CKTl4dfJkl/Wv6LzTCapednmwqt5I/7xNec3L/2kDwuN07E20L+9BKBftfL04G6 X-Received: by 2002:a17:906:300a:b0:9a2:19ea:88fc with SMTP id 10-20020a170906300a00b009a219ea88fcmr4415016ejz.71.1694704269960; Thu, 14 Sep 2023 08:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694704269; cv=none; d=google.com; s=arc-20160816; b=b9njxn5+HAUOO3vlEH7prv3Bm6MXCj473MsCM+Tc/FS8ZZ5eVow4ADqkqVLgk5O7Nz somAczMzG9xC4+MMVs2RYnZafmZWkm/0VhVKFSuwEBm4P1ExFgQ5mBjfT9xN81pK9U3z tMgcKYEVw9OH705h2yQzTuXhMRaN3rchWQTL6TuEWbsbuCl003kTgclyFI0+RdUFJrm8 DTwPtjmbRQEN8Ikbc3Dn9QAboTSoqdK4Ui00isKi+6pWW9iCOoAXmuJsyolcsr2SUISj fTtUu5/g1/JqvUbZU56NhLQspSDlYMaYF48Q0i5pQZjhEaGOXTkgkOeW09hcKrhxXY7p gSjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=bh6oVOv+Qx/kpP403jucdASa6z6XLgO3/El0uwsGR5A=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=MfjbNpSP+h7Js9/nZPT5HjQ0dZyrQdSIq9MxYdOPOKW2p7b1StpOux+DOpR9ZTz8y4 RTfT8x9wEmHsogBsPid+0yscqp/4aFNBXvR/slLiI++GHxHcEI8GQLridEdwn5an5Hgb pJMkCsBJmLGW3JRqEPWEMCMGqLPMRHqLVjrc0f/IJ0A8mGha7unm1wJKyvsy7izm2HF+ U4L4LK3bDYzQRZ0QT+trZVJXLPhlwPUv6c/dD0n9OUn6VnJVRC9kstAlIl4F2ZkBh7wB 8MN+llCZJp127aj3+r86Dof3kXZkg6bC7f9eDMttR2fiy0dVJ7XFv9HoWyAmoHLk6Ghi SaQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y14-20020a170906470e00b00991dfb5dfb7si1327422ejq.573.2023.09.14.08.10.57; Thu, 14 Sep 2023 08:11:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA27E68C7D9; Thu, 14 Sep 2023 18:10:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40AEE68C56B for ; Thu, 14 Sep 2023 18:10:46 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E785A240200 for ; Thu, 14 Sep 2023 17:10:45 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Ur2dEdszwrdx for ; Thu, 14 Sep 2023 17:10:45 +0200 (CEST) Received: from mail1.khirnov.net (mail1.khirnov.net [IPv6:2a00:c500:561:206::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail1.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 824D42401E7 for ; Thu, 14 Sep 2023 17:10:45 +0200 (CEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 0D822257E for ; Thu, 14 Sep 2023 17:10:38 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id N7K3K5iFzwlN for ; Thu, 14 Sep 2023 17:10:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 2616D257C for ; Thu, 14 Sep 2023 17:10:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9BD6C3A0376 for ; Thu, 14 Sep 2023 17:10:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Sep 2023 17:10:18 +0200 Message-Id: <20230914151020.10415-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_enc: refactor setting encoding field_order X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tj3ZzTdQzVcd 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(-) 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: