From patchwork Sun Sep 25 16:15:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 38288 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1759768pzh; Sun, 25 Sep 2022 09:15:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6jAufsTyYzsGygT7JLWuX/4P+AAhln+7ohDqmEdP+ijveQMdW6R+UKsUwwvfJsAXwDnnEJ X-Received: by 2002:a17:907:3dab:b0:783:4b01:1ffe with SMTP id he43-20020a1709073dab00b007834b011ffemr2796708ejc.107.1664122527810; Sun, 25 Sep 2022 09:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664122527; cv=none; d=google.com; s=arc-20160816; b=YFLKQAQOOWVu2nFcvWl6gciA6q+LQB5XM5VKqwJ94Mmp1GfykxWwqE667Ywrz/YYA1 QBq26Hx9OWPxe/NJObmO74i4BhOQ1X14hTUw2b4ckD7ThfmPzo09fIyRcUpSgTYgO2p6 pKzL7dJz4PLXE0aLwB3QJpB/VG5mYdCZfdBWPLROvqUkJvC28KD4ZOzx47G9jz1Zh550 aO+/xEo1YlPMvsr3/6lESLv7gdW4+bEBhv1SA56KrxNYp5v04WKwzaj1WbXIGOL3P7o5 T8v9KsHs4uNyosU8maEcQjpIZZVpv2+IIczbCZr3nZxdquRNLl/eI1Q7ihpmUfqEJd8X iXGg== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=XsQwBqGZKxdq2xTtlKo+ZHUE6grXMniSuEFTJQ32M+U=; b=j4wv5tKdEcHCzqAd97T4hhrsf4IK8gMFhC7oH8nONUEXHCJUs2L4Gx/oMm55FLmUE4 yt3c/jaqriumHtlFsdcb02dEib8gfRmdwkHd3ONh+7/AqCbit5rxWHTTiv8DSitZI61x YiLBOTW7RFM/DWPqeQbeH9ktacYc11D7w1bdHUDP8R5IOcn7cKv+R8EneLB7B6TeA4XC Sq7nHOzDJnem62423DQtNqfFDJ+iuolCY+x5SdrXNB0rnCWCYgGPiPyex5a88hxVKwoc J7LyRAA/+5KAMAyN9EW7bRRXFTTu+jWklXc7XLgbxPh5feXsJ8Z0cYBTE8DEspd032Wx dJIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=PSj8s48P; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y11-20020a056402270b00b0044f0dc2cbd6si15572165edd.378.2022.09.25.09.15.27; Sun, 25 Sep 2022 09:15:27 -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; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=PSj8s48P; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01FF268B70E; Sun, 25 Sep 2022 19:15:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout01.mail.de (shout01.mail.de [62.201.172.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BDF6F68B635 for ; Sun, 25 Sep 2022 19:15:08 +0300 (EEST) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout01.mail.de (Postfix) with ESMTP id 6765AA052F for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) Received: from smtp01.mail.de (smtp01.bt.mail.de [10.0.121.211]) by postfix01.mail.de (Postfix) with ESMTP id 4F6D280151 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1664122508; bh=MU8DxTFgNFbFRSwc2XJJheJGKSVtZ2mW3m4ek045fCA=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=PSj8s48Pj/JA/NCauxbbgZIGMvfv5rsjUYuSVKq1aMxhvr7m3cwVBvfK5sWHBqDTs RkOsijNTiQLbC4kJ7ndct6WThClVv/sqPUCb7WQWqBm0PArriI7bwkZT0ZZqyp2QW3 O+FESjWTfFa7DhTpJW54/9oYJ9mioTZQj9vfJCtnUi675s1NOxOAwCEdFPKfyxpvC/ K6T/nHI3gtdo9yOJA5WaKyHtnEdI2iQV8DwbDZVRx/TDuBExGAOT9jbg56NWMxp4dj xisWJltl0GSzp94JMB5ApV8OmeG2tayAUc3n/mXQkqGA51DmfnGwBCDW3xA9kMbege 89q59+aoYh4RA== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp01.mail.de (Postfix) with ESMTPSA id 150C1100118 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Sep 2022 18:15:04 +0200 Message-Id: <20220925161506.80724-2-thilo.borgmann@mail.de> In-Reply-To: <20220925161506.80724-1-thilo.borgmann@mail.de> References: <20220925161506.80724-1-thilo.borgmann@mail.de> MIME-Version: 1.0 X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3417 X-purgate-ID: 154282::1664122508-DDDB75FC-37F9C67D/0/0 Subject: [FFmpeg-devel] [PATCH v5 1/3] lavu/display: Add scaling functions to the display matrix 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: OaeNfeTx0FfO --- doc/APIchanges | 3 +++ libavutil/display.c | 21 +++++++++++++++++++++ libavutil/display.h | 15 +++++++++++++++ libavutil/version.h | 4 ++-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 729f56be7b..42e3391b72 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-09-25 - xxxxxxxxxx - lavu 57.37.100 - display.h + Add av_display_matrix_scale(), av_display_scale_get() + 2022-09-03 - xxxxxxxxxx - lavu 57.36.100 - pixfmt.h Add AV_PIX_FMT_P012, AV_PIX_FMT_Y212, AV_PIX_FMT_XV30, AV_PIX_FMT_XV36 diff --git a/libavutil/display.c b/libavutil/display.c index d31061283c..90758656e3 100644 --- a/libavutil/display.c +++ b/libavutil/display.c @@ -48,6 +48,19 @@ double av_display_rotation_get(const int32_t matrix[9]) return -rotation; } +double av_display_scale_get(const int32_t matrix[9]) +{ + double scale[2]; + + scale[0] = hypot(CONV_FP(matrix[0]), CONV_FP(matrix[3])); + scale[1] = hypot(CONV_FP(matrix[1]), CONV_FP(matrix[4])); + + if (scale[0] == 0.0 || scale[1] == 0.0) + return NAN; + + return scale[0]; +} + void av_display_rotation_set(int32_t matrix[9], double angle) { double radians = -angle * M_PI / 180.0f; @@ -72,3 +85,11 @@ void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip) for (i = 0; i < 9; i++) matrix[i] *= flip[i % 3]; } + +void av_display_matrix_scale(int32_t matrix[9], double scale) +{ + matrix[0] = CONV_DB(CONV_FP(matrix[0]) * scale); + matrix[1] = CONV_DB(CONV_FP(matrix[1]) * scale); + matrix[3] = CONV_DB(CONV_FP(matrix[3]) * scale); + matrix[4] = CONV_DB(CONV_FP(matrix[4]) * scale); +} diff --git a/libavutil/display.h b/libavutil/display.h index 31d8bef361..73767b3a71 100644 --- a/libavutil/display.h +++ b/libavutil/display.h @@ -86,6 +86,14 @@ */ double av_display_rotation_get(const int32_t matrix[9]); +/** + * Extract the scaling component of the transformation matrix. + * + * @param matrix the transformation matrix + * @return the scaling by which the transformation matrix scales the frame + */ +double av_display_scale_get(const int32_t matrix[9]); + /** * Initialize a transformation matrix describing a pure clockwise * rotation by the specified angle (in degrees). @@ -105,6 +113,13 @@ void av_display_rotation_set(int32_t matrix[9], double angle); */ void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip); +/** + * Scale the input matrix. + * + * @param matrix an allocated transformation matrix + * @param scale scale factor by which the matrix should be scaled + */ +void av_display_matrix_scale(int32_t matrix[9], double scale); /** * @} * @} diff --git a/libavutil/version.h b/libavutil/version.h index 0585fa7b80..9c44cef6aa 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 36 -#define LIBAVUTIL_VERSION_MICRO 102 +#define LIBAVUTIL_VERSION_MINOR 37 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ From patchwork Sun Sep 25 16:15:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 38289 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1759827pzh; Sun, 25 Sep 2022 09:15:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM612F8GeFFvN5TKgLIumUUZ22jQcCc0K5AbfUDLHoivRJOav25KZ0rtRYTSdyhKOzmJQNUe X-Received: by 2002:a05:6402:2926:b0:457:3c2c:4ab with SMTP id ee38-20020a056402292600b004573c2c04abmr2264565edb.388.1664122536089; Sun, 25 Sep 2022 09:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664122536; cv=none; d=google.com; s=arc-20160816; b=xkhEvyoTK3tB5YZPXB84UrzvOOZnDJ4PHcZPTuQKJEMyW4z4LIZLEmCPsN6q4jYmfM +ILw+747LtaFWrVEQbHpMfWE0cn6U550U92SLrdUOF4SxDQIPQtUU4NeqyEqYk1UQ511 TsoT88R1hyOf0ozoG9iGa3nwc8uxXBA3UhnLDUomPIe4cwbpXgR9u1S1Oam06ZoGuIqy Jt46cRwv3fnSdqIxAu1Y4Qcyh5GYvJi0o8Arf967D0sbQmoFEaEcPd58oQhnn5GJG500 Hw2RZmP/aXOSbFofsDu0MQzzfzrbGgPXuSMf8kAYRTe6Qcwt1czV6jhY+3ogqktnxZ4T t7BQ== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=V37ZcabfklPGCmskOwy1KxT0qVAN6z2fiSaHvEKIbik=; b=oXZGnbfFiZZz7vaxC9+LMKH+eU2JTSCNMK3W9HLK92J1cLxyIUUpZi8PWZbCZEHxEZ Gy88goVpx/dZHB6+wc3XcalTrCA4/dArrJ65gLKD3dnQ1Zk0OjCADYL2Xwgh4JftVW9M I9kxcpP1OenMokPy5GfZtTONU/FfzPOC38jMdSbQKxb39QRVDJQeGy7R5BC6PZ4zbZ2Z mIaCaR0wZrXm+VGp+LTR6z5iSK/zs1TKwhlNgZ7EG2SdILqL6gbZAS3YBaquPaQ/Fco5 ckmMmjiGMzoVMDTp4bs5M8LYvdf9RxCUlPRCbvyTfkgHwJqGRPDaj1a3+vYw+P53WzPz O5dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b="d/hv0ZmX"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y26-20020a50e61a000000b0044efa57bef2si12714309edm.295.2022.09.25.09.15.35; Sun, 25 Sep 2022 09:15:36 -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; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b="d/hv0ZmX"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 03D6E68BB15; Sun, 25 Sep 2022 19:15:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout01.mail.de (shout01.mail.de [62.201.172.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F5CF68B613 for ; Sun, 25 Sep 2022 19:15:14 +0300 (EEST) Received: from postfix02.mail.de (postfix02.bt.mail.de [10.0.121.126]) by shout01.mail.de (Postfix) with ESMTP id C70B7A0559 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) Received: from smtp01.mail.de (smtp01.bt.mail.de [10.0.121.211]) by postfix02.mail.de (Postfix) with ESMTP id ADC57A03C1 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1664122508; bh=YI8SZZOvxoi1aQTQhSKPhIssPl3Hvrw9oIlBsCHUwno=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=d/hv0ZmXeivKJ13KD0BaZgvt3GioLPx3E8bRGlsy1YJtxkdBmvnYC9UjeW7rDchi9 DhSUGiPK3zgIvUR8Rww+lShF1VHxUk7/rnhUZ/FeLkrWGIKG9pffmBZ+5kgBaGR/yr szAtE3A8tBAwdzhJriLGDeX5J7PYdfR3MBavt3TkuvyhfDZIQa2tFPQKBRXSz0fUzr rnG1aXTljRH7fa/zNfXdI+MywtlokEYt25d2LA9vBiiaL6+AddFRTcKvscluklYmF/ jP6lN4qldK2b0u64CUlebqMuZ7JGnZkWH6g+T581k3aApV1qnKAf2PLpAiioWEN/at GRYvcuHX4rWAg== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp01.mail.de (Postfix) with ESMTPSA id 5DAAD1000B6 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Sep 2022 18:15:05 +0200 Message-Id: <20220925161506.80724-3-thilo.borgmann@mail.de> In-Reply-To: <20220925161506.80724-1-thilo.borgmann@mail.de> References: <20220925161506.80724-1-thilo.borgmann@mail.de> MIME-Version: 1.0 X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 11272 X-purgate-ID: 154282::1664122508-DDDB75FC-9B77DF4F/0/0 Subject: [FFmpeg-devel] [PATCH v5 2/3] ffmpeg: Add display_{rotation, hflip, vflip, scale} options 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: Rvv7CBkxly1f From: Jan Ekström This enables overriding the scale, rotation as well as horizontal/vertical flip state of a specific video stream on the input side. Additionally, switch the singular test that was utilizing the rotation metadata to instead override the input display rotation, thus leading to the same result. --- doc/ffmpeg.texi | 36 ++++++++++++++++++++ fftools/ffmpeg.h | 8 +++++ fftools/ffmpeg_filter.c | 12 +++++++ fftools/ffmpeg_opt.c | 65 +++++++++++++++++++++++++++++++++++++ tests/fate/filter-video.mak | 2 +- 5 files changed, 122 insertions(+), 1 deletion(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 42440d93b4..066aa463b2 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -912,6 +912,42 @@ If used together with @option{-vcodec copy}, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists. +@item -display_rotation[:@var{stream_specifier}] @var{rotation} (@emph{input,per-stream}) +Set the video display rotation in degrees specified by @var{rotation}. + +@var{rotation} is a floating point number that describes a pure +counter-clockwise rotation in degrees. + +When setting this, @code{-autorotate} logic will be affected. +For additional parameters affecting display matrix side data into which this +information is saved, see @code{-display_hflip}, @code{-display_vflip} +and @code{-display_scale}. + +These options work as a unit, so if only one of them is set, then the display +matrix will be overridden to that specific value with the rest being set to +default values. When applied the order of transformations is scale, flip and rotate. + +If unset, the default value if a display matrix is being defined is a rotation +of zero degrees. + +@item -display_hflip[:@var{stream_specifier}] (@emph{input,per-stream}) +Set whether on display the image should be horizontally flipped. + +If unset, the default value if a display matrix is being defined is that there +is no additional horizontal flip. See @code{-display_rotation}. + +@item -display_vflip[:@var{stream_specifier}] (@emph{input,per-stream}) +Set whether on display the image should be vertically flipped. + +If unset, the default value if a display matrix is being defined is that there +is no additional vertical flip. See @code{-display_rotation}. + +@item -display_scale[:@var{stream_specifier}] (@emph{input,per-stream}) +Set whether on display the image should be scaled. + +If unset, the default value if a display matrix is being defined is that there +is no additional scale. See @code{-display_rotation}. + @item -vn (@emph{input/output}) As an input option, blocks all video streams of a file from being filtered or being automatically selected or mapped for any output. See @code{-discard} diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index ede0b2bd96..44a838d29b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -193,6 +193,14 @@ typedef struct OptionsContext { int nb_force_fps; SpecifierOpt *frame_aspect_ratios; int nb_frame_aspect_ratios; + SpecifierOpt *display_rotations; + int nb_display_rotations; + SpecifierOpt *display_hflips; + int nb_display_hflips; + SpecifierOpt *display_vflips; + int nb_display_vflips; + SpecifierOpt *display_scales; + int nb_display_scales; SpecifierOpt *rc_overrides; int nb_rc_overrides; SpecifierOpt *intra_matrices; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 7a5308425d..09e1e0a863 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -779,9 +779,21 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, if (ist->autorotate && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) { int32_t *displaymatrix = ifilter->displaymatrix; double theta; + double scale; if (!displaymatrix) displaymatrix = (int32_t *)av_stream_get_side_data(ist->st, AV_PKT_DATA_DISPLAYMATRIX, NULL); + + if (displaymatrix) { + scale = av_display_scale_get(displaymatrix); + + if (scale != 1.0f) { + char scale_buf[128]; + snprintf(scale_buf, sizeof(scale_buf), "%f*iw:%f*ih", scale, scale); + ret = insert_filter(&last_filter, &pad_idx, "scale", scale_buf); + } + } + theta = get_rotation(displaymatrix); if (fabs(theta - 90) < 1.0) { diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 5febe319e4..52709ca133 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -20,6 +20,7 @@ #include "config.h" +#include #include #if HAVE_SYS_RESOURCE_H @@ -45,6 +46,7 @@ #include "libavutil/avutil.h" #include "libavutil/bprint.h" #include "libavutil/channel_layout.h" +#include "libavutil/display.h" #include "libavutil/getenv_utf8.h" #include "libavutil/intreadwrite.h" #include "libavutil/fifo.h" @@ -86,6 +88,10 @@ static const char *const opt_name_forced_key_frames[] = {"forced_key_fra static const char *const opt_name_fps_mode[] = {"fps_mode", NULL}; static const char *const opt_name_force_fps[] = {"force_fps", NULL}; static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL}; +static const char *const opt_name_display_rotations[] = {"display_rotation", NULL}; +static const char *const opt_name_display_hflips[] = {"display_hflip", NULL}; +static const char *const opt_name_display_vflips[] = {"display_vflip", NULL}; +static const char *const opt_name_display_scales[] = {"display_scale", NULL}; static const char *const opt_name_rc_overrides[] = {"rc_override", NULL}; static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL}; static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL}; @@ -801,6 +807,49 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar return 0; } +static void add_display_matrix_to_stream(OptionsContext *o, + AVFormatContext *ctx, AVStream *st) +{ + double rotation = DBL_MAX, scale = DBL_MAX; + int hflip = -1, vflip = -1; + int hflip_set = 0, vflip_set = 0, rotation_set = 0, scale_set = 0; + uint8_t *buf = NULL; + + MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st); + MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st); + MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st); + MATCH_PER_STREAM_OPT(display_scales, dbl, scale, ctx, st); + + rotation_set = rotation != DBL_MAX; + hflip_set = hflip != -1; + vflip_set = vflip != -1; + scale_set = scale != DBL_MAX; + + if (!rotation_set && !hflip_set && !vflip_set && !scale_set) + return; + + if (scale <= 0.0f) { + av_log(NULL, AV_LOG_FATAL, "Invalid scale factor '%f'\n", scale); + exit_program(1); + } + + if (!(buf = av_stream_new_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, + sizeof(int32_t) * 9))) { + av_log(NULL, AV_LOG_FATAL, "Failed to generate a display matrix!\n"); + exit_program(1); + } + + av_display_rotation_set((int32_t *)buf, + rotation_set ? -(rotation) : + -0.0f); + av_display_matrix_flip((int32_t *)buf, + hflip_set ? hflip : 0, + vflip_set ? vflip : 0); + + av_display_matrix_scale((int32_t *)buf, + scale_set ? scale : 1.0f); +} + static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder) { const AVCodecDescriptor *desc; @@ -935,6 +984,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + add_display_matrix_to_stream(o, ic, st); + MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st); MATCH_PER_STREAM_OPT(hwaccel_output_formats, str, hwaccel_output_format, ic, st); @@ -4021,6 +4072,20 @@ const OptionDef options[] = { { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) }, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, + { "display_rotation", OPT_VIDEO | HAS_ARG | OPT_DOUBLE | OPT_SPEC | + OPT_INPUT, { .off = OFFSET(display_rotations) }, + "set pure counter-clockwise rotation in degrees for stream(s)", + "angle" }, + { "display_hflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_hflips) }, + "set display horizontal flip for stream(s) " + "(overrides any display rotation if it is not set)"}, + { "display_vflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_vflips) }, + "set display vertical flip for stream(s) " + "(overrides any display rotation if it is not set)"}, + { "display_scale", OPT_VIDEO | HAS_ARG | OPT_DOUBLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_scales) }, + "set display scale for stream(s) " + "(overrides any display rotation if it is not set)", + "scale" }, { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) }, "set pixel format", "format" }, diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 372c70bba7..f3c27ed1c8 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -691,7 +691,7 @@ fate-filter-metadata-avf-aphase-meter-out-of-phase: SRC = $(TARGET_SAMPLES)/filt fate-filter-metadata-avf-aphase-meter-out-of-phase: CMD = run $(FILTER_METADATA_COMMAND) "amovie='$(SRC)',aphasemeter=video=0" FATE_FILTER_SAMPLES-$(call TRANSCODE, RAWVIDEO H264, MOV, ARESAMPLE_FILTER AAC_FIXED_DECODER) += fate-filter-meta-4560-rotate0 -fate-filter-meta-4560-rotate0: CMD = transcode mov $(TARGET_SAMPLES)/filter/sample-in-issue-505.mov mov "-c copy -metadata:s:v:0 rotate=0" "-af aresample" "" "" "-flags +bitexact -c:a aac_fixed" +fate-filter-meta-4560-rotate0: CMD = transcode "mov -display_rotation:v:0 0" $(TARGET_SAMPLES)/filter/sample-in-issue-505.mov mov "-c copy" "-af aresample" "" "" "-flags +bitexact -c:a aac_fixed" FATE_FILTER_CMP_METADATA-$(CONFIG_BLOCKDETECT_FILTER) += fate-filter-refcmp-blockdetect-yuv fate-filter-refcmp-blockdetect-yuv: CMD = cmp_metadata blockdetect yuv420p 0.015 From patchwork Sun Sep 25 16:15:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 38290 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1759919pzh; Sun, 25 Sep 2022 09:15:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4AFWiw5ueUY4KZnV6znQ9+fi/XQyRP74pZVNS/snEDBY+Cdhd9I7X4gMM/ihtOxDelCUkQ X-Received: by 2002:a05:6402:380a:b0:451:ae08:7a6c with SMTP id es10-20020a056402380a00b00451ae087a6cmr17906172edb.161.1664122545397; Sun, 25 Sep 2022 09:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664122545; cv=none; d=google.com; s=arc-20160816; b=W76XwxfB+XjXNccyIeP4I9V0xs9dE63w+EhReRELqky2KxcLUkaDreF+IfH2xPIda/ ZfqXQ9S7xgrAUsAB3vQg/oBO8VcDXgT/gjQR/q/mb++jYCbmvkTgNun3m36nmgLdN1OU DBcWa4TKT8e1hQ5RCh2XReGa8jncXARdzdmP4DtQdBcTtM6lfp86sna94Y/CzWuHttdC fm4p1P3FySK51yExZs8L7kZiIC1DWw3tpcZw4L9NKZ3EvhWA7ak4OECb7KEX21CDFPcq Xc/z5v8by25aNSSCq7A80dQf2LGjDqrcL5rjsBBljhiDwX8UtQWgo7rpa4lDLfkyCb5N r0nA== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=C92Z671h6zRTX57AeBH9YodM+w+7rSwqLV2I5ijzYR0=; b=lh1kRVsZ0rVAx6j+bh8SfhMIQLyizTpl5Fs5n4S4NswgrAB4nUlFXz3vbweD1Lzw/c BcI9VZQqZQeBYufucAeW9oZtnmeb7JhEUaw9t4ZweBMOJk/FeJNXG03R0iI6GkwcbktD Y4EW9N/JWiAPK44EaFXCyZR0Fxdezu2mbYIBJfHlIFU1TRl6LMU/1vcVYnomf0T7msqj PXkpnZD8Q/2Wv5iZ7jPLMxz4LmL7fc1MG7THmmdCQfHLSmGpXjQcXki+l5uwknglzoBt htouOdl9ihvMLMYBiCRSwsgNXyEvP1eZ+OLY6ps/lhBfFMypX+Rd65i1X9P+Hc1Y/F9M ekVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=25PLTwiF; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qk30-20020a1709077f9e00b00779a07b4e90si8217502ejc.711.2022.09.25.09.15.45; Sun, 25 Sep 2022 09:15:45 -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; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=25PLTwiF; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF9FE68BB36; Sun, 25 Sep 2022 19:15:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout01.mail.de (shout01.mail.de [62.201.172.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3561768B75F for ; Sun, 25 Sep 2022 19:15:14 +0300 (EEST) Received: from postfix02.mail.de (postfix02.bt.mail.de [10.0.121.126]) by shout01.mail.de (Postfix) with ESMTP id 255FEA057B for ; Sun, 25 Sep 2022 18:15:09 +0200 (CEST) Received: from smtp01.mail.de (smtp01.bt.mail.de [10.0.121.211]) by postfix02.mail.de (Postfix) with ESMTP id 0C80FA03C1 for ; Sun, 25 Sep 2022 18:15:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1664122509; bh=5aQT8xjZOu61UTTEfsF7ywb25VdqzZaomNh0cEbc/00=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=25PLTwiFDdScvMJuGuow8olKC0kmx+9wPD8fvV3rOTwB9zYTrmJMPTeGkkzuo8cob xB0R9SnOxExjOf650CUmqieF0eCdUVTB0yIIvP7xSV21rXLW5k3eI7VpnI35OSy4OH sswUz0s9vQ35dy2mLat/gZStDX/g6dxAN1Jmcby2nQ1P6+UvjtuHyi0rGbMaRdzD55 V04zTn9L8mwBaInw6r/j/Nkkfyj3JfSpTRkHL1J0luUCtb4rO4ucfsYk/Ulhj/Tbll KvoK0UdV7cC8tmmOAWvyZ4HqZwJM4rRV04Lxc5WFV97QjwxLbr6cZ7xiIRvvkqm7sq Q5rRdZPussEvQ== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp01.mail.de (Postfix) with ESMTPSA id BCF4E100114 for ; Sun, 25 Sep 2022 18:15:08 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Sep 2022 18:15:06 +0200 Message-Id: <20220925161506.80724-4-thilo.borgmann@mail.de> In-Reply-To: <20220925161506.80724-1-thilo.borgmann@mail.de> References: <20220925161506.80724-1-thilo.borgmann@mail.de> MIME-Version: 1.0 X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3363 X-purgate-ID: 154282::1664122508-DDDB75FC-3E936B43/0/0 Subject: [FFmpeg-devel] [PATCH v5 3/3] ffmpeg: Deprecate display rotation override with a metadata key 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: bG2PWj2H1DDf From: Jan Ekström Now that we have proper options for defining display matrix overrides, this should no longer be required. fftools does not have its own versioning, so for now the define is just set to 1 and disables the functionality if set to zero. --- fftools/ffmpeg.c | 2 ++ fftools/ffmpeg.h | 5 +++++ fftools/ffmpeg_opt.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0e1477299d..65b0b83a18 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2831,12 +2831,14 @@ static int init_output_stream_streamcopy(OutputStream *ost) } } +#if FFMPEG_ROTATION_METADATA if (ost->rotate_overridden) { uint8_t *sd = av_stream_new_side_data(ost->st, AV_PKT_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9); if (sd) av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value); } +#endif switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 44a838d29b..3d2b39b78a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -53,6 +53,7 @@ #define FFMPEG_OPT_PSNR 1 #define FFMPEG_OPT_MAP_CHANNEL 1 #define FFMPEG_OPT_MAP_SYNC 1 +#define FFMPEG_ROTATION_METADATA 1 enum VideoSyncMethod { VSYNC_AUTO = -1, @@ -538,11 +539,15 @@ typedef struct OutputStream { int is_cfr; int force_fps; int top_field_first; +#if FFMPEG_ROTATION_METADATA int rotate_overridden; +#endif int autoscale; int bitexact; int bits_per_raw_sample; +#if FFMPEG_ROTATION_METADATA double rotate_override_value; +#endif AVRational frame_aspect_ratio; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 52709ca133..a609f01599 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2870,16 +2870,26 @@ static void of_add_metadata(AVFormatContext *oc, const OptionsContext *o) for (int j = 0; j < oc->nb_streams; j++) { OutputStream *ost = output_streams[nb_output_streams - oc->nb_streams + j]; if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) { +#if FFMPEG_ROTATION_METADATA if (!strcmp(o->metadata[i].u.str, "rotate")) { char *tail; double theta = av_strtod(val, &tail); if (!*tail) { ost->rotate_overridden = 1; ost->rotate_override_value = theta; + + av_log(NULL, AV_LOG_WARNING, + "Conversion of a 'rotate' metadata key to a " + "proper display matrix rotation is deprecated. " + "See -display_rotation for setting rotation " + "instead."); } } else { +#endif av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0); +#if FFMPEG_ROTATION_METADATA } +#endif } else if (ret < 0) exit_program(1); }