From patchwork Tue Aug 16 13:30:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 37313 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1867815pzi; Tue, 16 Aug 2022 06:31:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+qp/Pf483vrcAgqbdxndPLyIwhydhSGgCPc/V3PS3X4ZHEKhCpkLVVuqeSD6JnDD6PoA5 X-Received: by 2002:a17:907:94d6:b0:730:bfe6:8352 with SMTP id dn22-20020a17090794d600b00730bfe68352mr13364949ejc.348.1660656663361; Tue, 16 Aug 2022 06:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656663; cv=none; d=google.com; s=arc-20160816; b=DMsi0mk/DWxEc40eZZMVP6O1ZpajKeogEsXBWnVE64+oiZEgB+EEGLjcNQtZiO9/tB gVhl/iNH+tRAnAjIwNC7gf3N1grkbM7nPP/dFALPUBs0i60GCrzfvbe38puIJVK9HXlS Fo2SXYXYVh/uxuz1nnbCMtGYQ1ex+6lvYE6TfVBuf3M8FdSUuzQ65TnW+HRdeA2I/2X8 QXB7iaIrjoqjpn8dnCn8aMQ/jOYMKQX2/Psz8KyqY7FJb6RKtiX7/HbsrU/MERfLWyrE beuijni85GuROBJ0GSV6nDizl5M7nd2L1DJthC9c31OhIcyHDyRgYmT6k1nj+kFCYXPa Seug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=QG2215PAkAZZNX4RF/pm7Wbv2RymcmD+/fc1rFZj9h8=; b=kf05ORJdmWcMbvrRD+QNSGoB6a1KGlh+2lwHc4aW87u2wQuW3hV3in0OOA/JY+T2Hr 0h22cgW4MtrhE0/xhRuuoJ05dWgdf8tfdK612oyrq7vBs1cFYuwJZF20ApN55DDdeJVV EqbsWrLPzcUfCuERDjBjXfGuL0bMJo5AU58Fsl/yjW355iuD4UDZtKXWXO4p2K9q4Sff owi4lOcJVMGqlkq2M5aLMLTPVs/GnXMtKoMMZSb8ne7tk+rymexYHAmh2fyXWETnlI47 v7HDUgYtPgo0QbyT8KTLrgOSzyABdfTE3bxuLXyup5MDz71STXoZkTC340DwWCuLWeKz xPqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b="ljmD+5/r"; 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 b3-20020a0564021f0300b00443367b756bsi8867032edb.194.2022.08.16.06.31.02; Tue, 16 Aug 2022 06:31:03 -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="ljmD+5/r"; 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 96D8068B876; Tue, 16 Aug 2022 16:30:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7CD668B205 for ; Tue, 16 Aug 2022 16:30:51 +0300 (EEST) Received: from postfix02.mail.de (postfix02.bt.mail.de [10.0.121.126]) by shout02.mail.de (Postfix) with ESMTP id 97795A0340; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix02.mail.de (Postfix) with ESMTP id 7CD2BA03C3; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1660656651; bh=xfxpkNGgMjxrmuJfUcBHz0zRShF9+l/QWkIdix6vdc0=; h=From:To:Cc:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=ljmD+5/rjII8jTPcOJFNbxzHupB9B3Kca3L8e0RCICyhNbdUA3PuwSWaJfuUgmMFT SZzD5PMr4V26c2xc07jWT9MrhGUmwQz+DQsRZLhW+Rfi1g61cvec42H12qxIJG5jix agfRk86mx6E8YUuoyIexy96T5qhmSY78KslFCBIFGub476L3Mt+MQvT1LQW5Hk5qWY ynxhkkqkQM1CGK1YPGp8KsuFw9txvghcSlKQREajZ6Wikb9gza+zsRIxOXzEk3Hgxy 7N0NQlTgn9ukUfJFe7eV+QPeqOf/EEPgBeIyuNbqryna2IAiDrsq/vbSAnqAzZwnG3 VyYez5vcfrRXw== 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 smtp04.mail.de (Postfix) with ESMTPSA id 37B68C1338; Tue, 16 Aug 2022 15:30:50 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 15:30:42 +0200 Message-Id: <20220816133046.70846-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: 3535 X-purgate-ID: 154282::1660656651-000016C9-A69E3EFB/0/0 Subject: [FFmpeg-devel] [PATCH 1/5] fftools: Add support for dictionary 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 Cc: =?utf-8?q?Jan_Ekstr=C3=B6m?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qjKg/mSdeqJh From: Jan Ekström --- fftools/cmdutils.c | 18 ++++++++++++++++++ fftools/cmdutils.h | 2 ++ fftools/ffmpeg_opt.c | 11 +++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 18e768b386..22ba654bb0 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -131,6 +131,22 @@ int64_t parse_time_or_die(const char *context, const char *timestr, return us; } +static AVDictionary *parse_dict_or_die(const char *context, + const char *dict_str) +{ + AVDictionary *dict = NULL; + int ret = av_dict_parse_string(&dict, dict_str, "=", ",", 0); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, + "Failed to create a dictionary from '%s': %s!\n", + dict_str, av_err2str(ret)); + exit_program(1); + } + + + return dict; +} + void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags) { @@ -288,6 +304,8 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); } else if (po->flags & OPT_DOUBLE) { *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY); + } else if (po->flags & OPT_DICT) { + *(AVDictionary **)dst = parse_dict_or_die(opt, arg); } else if (po->u.func_arg) { int ret = po->u.func_arg(optctx, opt, arg); if (ret < 0) { diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index d87e162ccd..6a519c6546 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -129,6 +129,7 @@ typedef struct SpecifierOpt { uint64_t ui64; float f; double dbl; + AVDictionary *dict; } u; } SpecifierOpt; @@ -157,6 +158,7 @@ typedef struct OptionDef { #define OPT_DOUBLE 0x20000 #define OPT_INPUT 0x40000 #define OPT_OUTPUT 0x80000 +#define OPT_DICT 0x100000 union { void *dst_ptr; int (*func_arg)(void *, const char *, const char *); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 97f14b2a5b..cc038aae6b 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -62,6 +62,7 @@ #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64 #define SPECIFIER_OPT_FMT_f "%f" #define SPECIFIER_OPT_FMT_dbl "%lf" +#define SPECIFIER_OPT_FMT_dict "%p" static const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL}; static const char *const opt_name_audio_channels[] = {"ac", NULL}; @@ -208,11 +209,17 @@ static void uninit_options(OptionsContext *o) av_freep(&(*so)[i].specifier); if (po->flags & OPT_STRING) av_freep(&(*so)[i].u.str); + else if (po->flags & OPT_DICT) + av_dict_free(&(*so)[i].u.dict); } av_freep(so); *count = 0; - } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING) - av_freep(dst); + } else if (po->flags & OPT_OFFSET) { + if (po->flags & OPT_STRING) + av_freep(dst); + else if (po->flags & OPT_DICT) + av_dict_free((AVDictionary **)&dst); + } po++; } From patchwork Tue Aug 16 13:30:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 37314 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1867971pzi; Tue, 16 Aug 2022 06:31:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR682xPdZaEog6upt9Z/1J9c+Q3P5/1+AtAtIrzuidanMAKleRN8G09tS+jpmAbvSVc27Ep1 X-Received: by 2002:a17:907:1ca8:b0:730:871e:498c with SMTP id nb40-20020a1709071ca800b00730871e498cmr13333799ejc.651.1660656673669; Tue, 16 Aug 2022 06:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656673; cv=none; d=google.com; s=arc-20160816; b=UAlTfqLUvr3aygmatrmZsXPMGlQKMpTVufpCaDnhP0aCWgp5JsK7RB8BhOnzVXMSJJ QlPEvo2X4HUUw1nrswibatAcbbp+H53g72CN8wAhhsN3y/OrTLj29eVtw1pJwUaCT7Go 8ogWMfI5htLr3xwYfu8oG7t1BTjTtyN8mRTeefLQnH20fSZb/K6bKrT0NDtZhmdR0n0E hBlXnqzGSh0O2Uv/0yzI1/NgGbepdlbh1fUbudNJskcw7x3tbPRIsNaappovSGI+PEp6 OIIgpwRKTjoxIXJghpVpFyOSN73YU5+rRYbKbY1WQZqpRjYWPwEaO+/15Ck/qJkiTnFP GIcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=FdOgDmx5s+UNv2bwxz+c1TQKH0Wy6I+r+UKOmbJ17Uo=; b=CFrslEQDoSAx7CzRkcKZtSaR8rJcMvK6ZzXBsAP/ONeiFKaVlmpAKt4RsgoWTes1ER vwAvK+lBwBvCdC5As7+n+6tEsRZhg59uozmvdhVn3H2xYnH5gyJnVZNtBReCFhafcm4B x9qS6pucXtsBPYDMDhvzr+l/IN8zKH9ISxw8wPJncSettI3SmsX9A41DTR14RCmbqkoT G4TelIdl8OYo3nBqsFFcU1yeDcM9wE8hoisHcYlFFYXPpfSCQle3C7H7k5xJ79LhD0ZS yUcsVJb5R3etkI2Pwf9VsGrPiUJqki0O9MBpswLu2tBPy0WD8kV3YSPK87t52OpiLUHT fGwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=X39Djjnw; 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 dv13-20020a170906b80d00b006feba25b350si8573552ejb.106.2022.08.16.06.31.13; Tue, 16 Aug 2022 06:31:13 -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=X39Djjnw; 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 A2AC568B8DA; Tue, 16 Aug 2022 16:30:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5067F68B205 for ; Tue, 16 Aug 2022 16:30:52 +0300 (EEST) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout02.mail.de (Postfix) with ESMTP id F0B2DA0DD0; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix01.mail.de (Postfix) with ESMTP id D74278014A; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1660656651; bh=gGg85hlqQYn/JIvMTdZSoWn1oqgMsMrniiMVv0km1ZM=; h=From:To:Cc:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=X39DjjnwWFYCFDIbXFQk/T6XCqMZsNmhX9K1M9Tw+AJd79qR+B4sqbtMysOY9V9CO HNbyxYTZDByTZ/PCWfkAf+CA2LVgN4am9sIPx3eCfVYeL1nT/GsiTAO1drYaMRqvcF IG5SKfZp4dd9iDMmZZsUhMzBJxsGhvOQqk4LmEoZAzZ8OidGS/n4POQb4xVPILILnk mrQX6ay96rj+s/hnQjb5p92s42Jc8sfM5mVPMCeFpdGsddSHuoIT3+igqOku1P+USb 6UGElroGQEwvFWmJ4pnJi1SNolN89mBTWSVSbV3IrvjPAy2vFgtPfwazPNjFvwHLDP ADauFiXtCF9cA== 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 smtp04.mail.de (Postfix) with ESMTPSA id 888E6C2081; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 15:30:43 +0200 Message-Id: <20220816133046.70846-2-thilo.borgmann@mail.de> In-Reply-To: <20220816133046.70846-1-thilo.borgmann@mail.de> References: <20220816133046.70846-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: 10648 X-purgate-ID: 154282::1660656651-000016C9-D624736D/0/0 Subject: [FFmpeg-devel] [PATCH 2/5] ffmpeg: Add display_matrix option 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 Cc: =?utf-8?q?Jan_Ekstr=C3=B6m?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: N11h2CYRZ052 From: Jan Ekström This enables overriding the 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 | 13 +++++ fftools/cmdutils.h | 1 + fftools/ffmpeg.h | 2 + fftools/ffmpeg_opt.c | 107 ++++++++++++++++++++++++++++++++++++ tests/fate/filter-video.mak | 2 +- 5 files changed, 124 insertions(+), 1 deletion(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 42440d93b4..5d3e3b3052 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -912,6 +912,19 @@ 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_matrix[:@var{stream_specifier}] @var{opt1=val1[,opt2=val2]...} (@emph{input,per-stream}) +Set the video display matrix according to given options. + +@table @option +@item rotation=@var{number} +Set the rotation using a floating point number that describes a pure +counter-clockwise rotation in degrees. +The @code{-autorotate} logic will be affected. +@item hflip=@var{[0,1]} +@item vflip=@var{[0,1]} +Set a horizontal or vertical flip. +@end table + @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/cmdutils.h b/fftools/cmdutils.h index 6a519c6546..df90cc6958 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -166,6 +166,7 @@ typedef struct OptionDef { } u; const char *help; const char *argname; + const AVClass *args; } OptionDef; /** diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6991ba7632..0ea730fd42 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -193,6 +193,8 @@ typedef struct OptionsContext { int nb_force_fps; SpecifierOpt *frame_aspect_ratios; int nb_frame_aspect_ratios; + SpecifierOpt *display_matrixes; + int nb_display_matrixes; SpecifierOpt *rc_overrides; int nb_rc_overrides; SpecifierOpt *intra_matrices; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index cc038aae6b..e184b4239c 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" @@ -87,6 +89,7 @@ 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_matrixes[] = {"display_matrix", 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}; @@ -112,6 +115,32 @@ static const char *const opt_name_time_bases[] = {"time_base", NU static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL}; static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_sample", NULL}; +// XXX this should probably go into a seperate file _args.c and #included here + struct display_matrix_s { + const AVClass *class; + double rotation; + int hflip; + int vflip; + }; +#define OFFSET(x) offsetof(struct display_matrix_s, x) + static const AVOption display_matrix_args[] = { + { "rotation", "set rotation", OFFSET(rotation), AV_OPT_TYPE_DOUBLE, + { .dbl = DBL_MAX }, -(DBL_MAX), DBL_MAX - 1.0f, AV_OPT_FLAG_ARGUMENT}, + { "hflip", "set hflip", OFFSET(hflip), AV_OPT_TYPE_BOOL, + { .i64 = -1 }, 0, 1, AV_OPT_FLAG_ARGUMENT}, + { "vflip", "set vflip", OFFSET(vflip), AV_OPT_TYPE_BOOL, + { .i64 = -1 }, 0, 1, AV_OPT_FLAG_ARGUMENT}, + { NULL }, + }; + static const AVClass class_display_matrix_args = { + .class_name = "display_matrix_args", + .item_name = av_default_item_name, + .option = display_matrix_args, + .version = LIBAVUTIL_VERSION_INT, + }; +#undef OFFSET +// XXX + #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\ {\ char namestr[128] = "";\ @@ -808,6 +837,75 @@ 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) +{ + int hflip_set = 0, vflip_set = 0, display_rotation_set = 0; + uint8_t *buf = NULL; + + static struct display_matrix_s test_args = { + .class = &class_display_matrix_args, + .rotation = DBL_MAX, + .hflip = -1, + .vflip = -1, + }; + + AVDictionary *global_args = NULL; + AVDictionary *local_args = NULL; + AVDictionaryEntry *en = NULL; + + MATCH_PER_STREAM_OPT(display_matrixes, dict, global_args, ctx, st); + + if (!global_args) + return; + + // make a copy of the dict so it doesn't get freed from underneath us + if (av_dict_copy(&local_args, global_args, 0) < 0) { + av_log(NULL, AV_LOG_FATAL, + "Failed to copy argument dict for display matrix!\n"); + } + + if (av_opt_set_dict2(&test_args, &local_args, 0) < 0) { + av_log(NULL, AV_LOG_FATAL, + "Failed to set options for a display matrix!\n"); + exit_program(1); + } + + while ((en = av_dict_get(local_args, "", en, AV_DICT_IGNORE_SUFFIX))) { + av_log(NULL, AV_LOG_FATAL, + "Unknown option=value pair for display matrix: " + "key: '%s', value: '%s'!\n", + en->key, en->value); + } + + if (av_dict_count(local_args)) { + exit_program(1); + } + + av_dict_free(&local_args); + + display_rotation_set = test_args.rotation != DBL_MAX; + hflip_set = test_args.hflip != -1; + vflip_set = test_args.vflip != -1; + + if (!display_rotation_set && !hflip_set && !vflip_set) + return; + + 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, + display_rotation_set ? -(test_args.rotation) : + -0.0f); + av_display_matrix_flip((int32_t *)buf, + hflip_set ? test_args.hflip : 0, + vflip_set ? test_args.vflip : 0); +} + + static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder) { const AVCodecDescriptor *desc; @@ -942,6 +1040,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); @@ -1865,6 +1965,8 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->frame_aspect_ratio = q; } + add_display_matrix_to_stream(o, oc, st); + MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); @@ -3992,6 +4094,11 @@ 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_matrix", OPT_VIDEO | HAS_ARG | OPT_DICT | OPT_SPEC | + OPT_INPUT, { .off = OFFSET(display_matrixes) }, + "define a display matrix with rotation and/or horizontal/vertical " + "flip for stream(s)", + "arguments", &class_display_matrix_args }, { "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..763390ea51 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_matrix:v:0 rotation=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 Tue Aug 16 13:30:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 37315 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1868091pzi; Tue, 16 Aug 2022 06:31:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR5I2pXjeAXriUpyitAufw95nHUu6XovrXYM1HYNR35IDb2ZHPUUWxoSj2UN0RTM45Yalz89 X-Received: by 2002:a17:907:d07:b0:72e:ec79:ad0f with SMTP id gn7-20020a1709070d0700b0072eec79ad0fmr13758744ejc.296.1660656684579; Tue, 16 Aug 2022 06:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656684; cv=none; d=google.com; s=arc-20160816; b=rrzi8krFkEErsgoAiG3nEAiS4SARS/iV1C5FLUXMLkCBEgcsW+Q6MIQ8vdEycROAvq px9g+/6CIaFXT0bYoF4B7v9nfbD0QcRlr5u0EdIBrE/GMNeHZdtgqU6sKZbQf8HMx+tO DaQjjKhSLW3itX+s8+/HaLEs8wmbAcTSE0mTsu6e7Udn8+K3gNTfXM5JSgHR+g4N0Qj1 i3qVmvIV6sKY8Poe43SCv/b/+1EbI6s8BBYiVH6VLrbubnh4wYhP6ttwfaJozXUmrto4 F3Xp7zBfjKZKXhEg2wZuSgLsGKig7IwJj+7aAI2uhjvpJsYS2VpLc6p3wvl57/2UymVN n98g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=hdKxkcYyudJO3xVaibTXM7B2Zokx8/zeLWFRplZ0fP0=; b=Bmv1Ss8rWyUoHvzHST3FPHN+MP/vv5epjM8t6ADVsOQ7W79ZFqY+S6NnRuyhkTAP7N kT10bzFZcccG21badhjW2EhPSMmD5ixK/kNgBjCzemvB6XsnBdcXZHOM0tXoGmaJKRFl n38+zBo2bHoINPxPuAzzJyWLq+aC9BROmvhmlQG0tpDkfBQ8BdOrc8mgKpcGnot/nRqH trpHTB89BHJRolkKxfjvNRAzuAB9mIqXP6q5G5Ktuys3jO9S0edeYAsqb+JYBy/lyayJ 0YSbVw5f6GO0q+j+PybDho1lPWDqxPNz/ZyJKq4lqPDLQ+Gsk4cdWdTiOtB/naYJvXH7 S/Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=WR7qD5D2; 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 p27-20020a1709060e9b00b00730d106e832si8729479ejf.248.2022.08.16.06.31.23; Tue, 16 Aug 2022 06:31:24 -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=WR7qD5D2; 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 CAD1768B8E0; Tue, 16 Aug 2022 16:31:00 +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 A79B368B205 for ; Tue, 16 Aug 2022 16:30:52 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout01.mail.de (Postfix) with ESMTP id 539E0A0940; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 384B580127; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1660656652; bh=k1u15UryNV8eawtG67y7rzGAt1E/8HFtrk4hHBYICzc=; h=From:To:Cc:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=WR7qD5D2egpAnIpMp4bFbhGUuRisGussjE5GGhqYBtVqckHryDQ+7oNjalPboU2ZF UepltKiYe3HuhB3c6gczZrxlc22mjInssTbkiXVT1yLWky/ua10xC71Yi9igROVtvD w3Z6bh0DWUvCSX4GeJws0yqh342m+9X27rwRiT56NFnb4Mi15WSFXhjwya1AgNyewX dZ6TQpSEU4cqGVSud6tGjnwe9jsa/lpMjLeS/ymEMZdOwRCdmB1vQngbW9NoGSvb2f 1KXSyXP43bwctD9++nkjITku8WepSwzxniDHwaMyAxqkS+j/wLX7sy7M62EncI9ANV RXSdmVlUCtG+A== 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 smtp04.mail.de (Postfix) with ESMTPSA id E334DC1338; Tue, 16 Aug 2022 15:30:51 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 15:30:44 +0200 Message-Id: <20220816133046.70846-3-thilo.borgmann@mail.de> In-Reply-To: <20220816133046.70846-1-thilo.borgmann@mail.de> References: <20220816133046.70846-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: 3371 X-purgate-ID: 154282::1660656652-000016C9-BE6E54EA/0/0 Subject: [FFmpeg-devel] [PATCH 3/5] 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 Cc: =?utf-8?q?Jan_Ekstr=C3=B6m?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aysDra5O9Wyc 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 8eb7759392..b0a8839129 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2824,12 +2824,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 0ea730fd42..12125ac006 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, @@ -520,11 +521,15 @@ typedef struct OutputStream { const char *fps_mode; 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 e184b4239c..f6551621c3 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2930,16 +2930,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_matrix 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); } From patchwork Tue Aug 16 13:30:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 37316 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1868229pzi; Tue, 16 Aug 2022 06:31:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR56d8MLl7vj28RyDsgCAjA24Gy+YeEWbi9Ng+CM8wGqT3nGoVgpp1AZBd1cL7BhFcluXwFS X-Received: by 2002:a17:907:2d0b:b0:730:63dd:748e with SMTP id gs11-20020a1709072d0b00b0073063dd748emr13716651ejc.307.1660656695088; Tue, 16 Aug 2022 06:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656695; cv=none; d=google.com; s=arc-20160816; b=chv6pG2uo+oa8q7Yiq/Jq3zbqad5EiDsmha+7SgD/jRfkdDPkep9dAsTD7rBTDeH2Q 8i0OjZH2Z1NwK4UbvEEgoXNxBt27AO0u6MK3zLZXOXbZmSAyJx/iec4E6RWxbMVpOOl0 Y6pXzFIPMoCDglarYSXacNum4UX6c6aOPy2Uet0vbQoCAq22ajNNJl3ET1TXf4lpAY3r but2Mrlxtnx8ZBqelcYK8UW3lYn7TNLPf9GwbDiay+v4hUlht0uWMEhbEX1N1Q154zfU moQjQ50C397TF6Z4OvD9CbTC6prGseozTjfWdXcw33sj38e9P2wiMYCuHhyM8a4/4f73 6fzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=vqK9PWtFjbeqehEvtZxuNQbQSJ5KmGsKwsvseVM8gzc=; b=NflDjsxvsxdPSIzb2hcfeGb2NPfcuAmJWRkRUYdRJaVqJIggoinQLn1mvxf+0Thpyo fw2d1vdrlp9FvPLgsjpOEtnv0IEQHsgyt1fX+yJakkh/q8OcDtbkmdQk2FVK7I+V3dEp am9WvAvvytwpwbrYzi0VZIK19lxhShtRxT0qZxuVvl66Byyt5w31hFs9SG4Twvuaa41i XTpBT+LwP2oEEPPIrN/ilrxJjzpUsGB+YfkfGyf5lwfeuc8tYxv3EkT51FLJybAgXVu6 Zqq0Ox0U4uw9YKeEBw8wjLa9m9dt/iCjDdj49qOAeVixQ1L78WtQDVzXj4yrPGb9f541 Ec3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b="MdC//XZr"; 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 d14-20020a056402144e00b0043d5dd96fcfsi8759750edx.272.2022.08.16.06.31.34; Tue, 16 Aug 2022 06:31:35 -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="MdC//XZr"; 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 C810C68B205; Tue, 16 Aug 2022 16:31:01 +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 1300A68B205 for ; Tue, 16 Aug 2022 16:30:53 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout01.mail.de (Postfix) with ESMTP id B188DA09CA for ; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 96C8680127; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1660656652; bh=cggqMXDrXlikqW6eDMcJrixnhOxnmsRU1j7VbRKUK/I=; h=From:To:Cc:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=MdC//XZr1RSCPq77LtvnDZrR4ujJN7h9bbiufbYz6ewk6BwvFvjGp7puV8ZHqAQQ6 7ToUIqpOgFlgKY5+hSF6Ax+sn5b6MOsqxM8TUecYBiThIAZ4495fQb28G6pUIDNNPm 28HV8hEDw31RTOSdqB9oH1TC85+WgNdk0/VPz/q+GBpm5tRflbjMWGS1G/rNSpCwFS fhnpEIuOEOE4zMjFItAS0maoyahErQ0hOoJHNz3+RkWpHvoJQn1rOb0LWQVLLVqioM lWe54kUOl1MA245GGQS4jwGSH5QxM2F4vGEXngFBIVss1mHBTytRRscTNA8KPbGJ9g faJygWrdkLyYg== 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 smtp04.mail.de (Postfix) with ESMTPSA id 43AF5C2081; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 15:30:45 +0200 Message-Id: <20220816133046.70846-4-thilo.borgmann@mail.de> In-Reply-To: <20220816133046.70846-1-thilo.borgmann@mail.de> References: <20220816133046.70846-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: 3604 X-purgate-ID: 154282::1660656652-000016C9-AF428384/0/0 Subject: [FFmpeg-devel] [PATCH 4/5] ffmpeg: Allow printing of option arguments in help output 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 Cc: Thilo Borgmann Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RUrNsy5CyHLL --- fftools/cmdutils.c | 5 +++++ libavutil/opt.c | 14 +++++++++++++- libavutil/opt.h | 8 ++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 22ba654bb0..dae018f83a 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -172,6 +172,11 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags, av_strlcat(buf, po->argname, sizeof(buf)); } printf("-%-17s %s\n", buf, po->help); + + if (po->args) { + const AVClass *p = po->args; + av_arg_show(&p, NULL); + } } printf("\n"); } diff --git a/libavutil/opt.c b/libavutil/opt.c index a3940f47fb..89ef111690 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1256,7 +1256,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); else av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ", - (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-", + (opt->flags & (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_ARGUMENT)) ? " " : "-", opt->name); switch (opt->type) { @@ -1329,6 +1329,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); break; } + if (!(opt->flags & AV_OPT_FLAG_ARGUMENT)) { av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.', (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.', @@ -1341,6 +1342,7 @@ FF_ENABLE_DEPRECATION_WARNINGS (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.', (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.', (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.'); + } if (opt->help) av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); @@ -1456,6 +1458,16 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags) return 0; } +int av_arg_show(void *obj, void *av_log_obj) +{ + if (!obj) + return -1; + + opt_list(obj, av_log_obj, NULL, AV_OPT_FLAG_ARGUMENT, 0, -1); + + return 0; +} + void av_opt_set_defaults(void *s) { av_opt_set_defaults2(s, 0, 0); diff --git a/libavutil/opt.h b/libavutil/opt.h index 461b5d3b6b..dce3483237 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -297,6 +297,7 @@ typedef struct AVOption { #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering #define AV_OPT_FLAG_DEPRECATED (1<<17) ///< set if option is deprecated, users should refer to AVOption.help text for more information #define AV_OPT_FLAG_CHILD_CONSTS (1<<18) ///< set if option constants can also reside in child objects +#define AV_OPT_FLAG_ARGUMENT (1<<19) ///< set if option is an argument to another option //FIXME think about enc-audio, ... style flags /** @@ -386,6 +387,13 @@ typedef struct AVOptionRanges { */ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags); +/** + * Show the obj arguments. + * + * @param av_log_obj log context to use for showing the options + */ +int av_arg_show(void *obj, void *av_log_obj); + /** * Set the values of all AVOption fields to their default values. * From patchwork Tue Aug 16 13:30:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 37317 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1868351pzi; Tue, 16 Aug 2022 06:31:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR4bSOlV5U/U/Cak9EaUt9u+On80jAobraS/mxJWKt1X7ijUkwZjzQVNs/NY0E4qzfxgnx09 X-Received: by 2002:a17:906:9b14:b0:730:984e:a51c with SMTP id eo20-20020a1709069b1400b00730984ea51cmr13120994ejc.435.1660656705549; Tue, 16 Aug 2022 06:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656705; cv=none; d=google.com; s=arc-20160816; b=XcCBiSvLt9HddAkds2BMGdrId4fBoA/KD9VJ6c28PfFPZYRpdR0TN4zE+EdpGExKT2 C6q6GBSyGS5fTk+9LybB5jwLzx5HJjiPkvoloH+ILsvUVIX7I3a+626LdxlpfVqi1fWt IFwhS7P1IDDML/yKADf7LA5IINMOZ6TR8WksJo+q2sGIvxPYsV81ztg4HeaSz3SmBAdR RJ6e9kM/fzbXXZXwau4iuHr2Sx76EGjqlFT2eFh1V+soq/ZkF9iZfs4EkJAIFZMS5pih nsSP90q+MZ3AbPQK2VxvQvUkwRNhtKhCSxJNGdVFpkgO2iPuuu2sXTh7IeWOqhXLlxTd tC8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=uNC77xOIgjgXQsKpTM0vX1cXKn0qm9EqkWl6wH9rZE8=; b=RaJ1uTWLVu85PdSW3yE/PeH9EVdbWcUMOm42tjvqpxtFemwQELd17XPFaqtX1uoBt4 57Sf2Ldndhsc4bOA+CVmPID9jQOJ6/9pUSdIeYBzZ1aDhrV9DmDwqDrVa9U4SRDu+SKT f/scWoEqYyydYqvOcVNj6+Hc6WJtxxr/d9Ru8avPzTKlFLvvTA/YmNKyfmwVqReyBuAK wfTlKkbvQZNoPijWDN5g2dk6kfakfpWpoxSNd0vJK7CXtugHwolHXSJ1Gz0g5lZuWVCJ 6QSwSoY+JjH083vkB0Lxz5JdM4AKUAOjRQc1N6YEMe+u5airrAG3TqThY0maB3jLFDCf 4DgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b="ajV/ioMB"; 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 hs28-20020a1709073e9c00b00730bcba7f70si12575928ejc.635.2022.08.16.06.31.44; Tue, 16 Aug 2022 06:31: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="ajV/ioMB"; 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 CDF6A68B912; Tue, 16 Aug 2022 16:31:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A90868B8F3 for ; Tue, 16 Aug 2022 16:30:57 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id 54347A0E05 for ; Tue, 16 Aug 2022 15:30:53 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 37AF780127; Tue, 16 Aug 2022 15:30:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1660656653; bh=/gUeW16e89jjuD6RmZb00agceKr48ZS3etvr4g9yDFo=; h=From:To:Cc:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=ajV/ioMBkoFzvonXO0Dn8/rO5hrbxofzBq9uURmt0nSo1U498ZQW85dt776cHaQvg SRDoIb04/dDnwYhhiWPOHxseMIY1trCFlMN9PIug4mFl32GlkvsyoA2SSefE0epB0g VLKPMHieSYLeDXCVifcmfGuVu1HUV2GHSNzYUJePtlvvUMi1pmJqJ9aI8S1FLs2Axe gvUG+dJN9/Vog4jk5RY6o5h51juoKtbzmTAoaNM9Y0hPwEFjaNeQGC6XmUfGlBnZol Vw6Z3WhexZLmmszgx3CcxQqDNLGpkoNuCESSQ/5Cgx8C2vURi4ojebTghmnMxZa5pw ssO6lh8HItUcA== 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 smtp04.mail.de (Postfix) with ESMTPSA id A1D5FC1338; Tue, 16 Aug 2022 15:30:52 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 15:30:46 +0200 Message-Id: <20220816133046.70846-5-thilo.borgmann@mail.de> In-Reply-To: <20220816133046.70846-1-thilo.borgmann@mail.de> References: <20220816133046.70846-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: 7062 X-purgate-ID: 154282::1660656652-000016C9-67B526D3/0/0 Subject: [FFmpeg-devel] [PATCH 5/5] ffmpeg: Add {h, v}scale argument to display_matrix option to allow for scaling via 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 Cc: Thilo Borgmann Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cdQZ7WT+1k5h --- doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg_filter.c | 15 +++++++++++++++ fftools/ffmpeg_opt.c | 10 ++++++++++ libavutil/display.c | 21 +++++++++++++++++++++ libavutil/display.h | 28 ++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 5d3e3b3052..52cca7a407 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -923,6 +923,10 @@ The @code{-autorotate} logic will be affected. @item hflip=@var{[0,1]} @item vflip=@var{[0,1]} Set a horizontal or vertical flip. +@item hscale=@var{[0,2]} +Set a horizontal scaling by factor of the given floating-point value. +@item vscale=@var{[0,2]} +Set a vertical scaling by factor of the given floating-point value. @end table @item -vn (@emph{input/output}) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index f9ae76f76d..0759c08687 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -778,9 +778,24 @@ 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 hscale = 1.0f; + double vscale = 1.0f; if (!displaymatrix) displaymatrix = (int32_t *)av_stream_get_side_data(ist->st, AV_PKT_DATA_DISPLAYMATRIX, NULL); + + if (displaymatrix) { + hscale = av_display_hscale_get(displaymatrix); + vscale = av_display_vscale_get(displaymatrix); + + if (hscale != 1.0f || vscale != 1.0f) { + char scale_buf[128]; + snprintf(scale_buf, sizeof(scale_buf), "%f*iw:%f*ih", hscale, vscale); + 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 f6551621c3..4fae6cbfbf 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -121,6 +121,8 @@ static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_s double rotation; int hflip; int vflip; + double hscale; + double vscale; }; #define OFFSET(x) offsetof(struct display_matrix_s, x) static const AVOption display_matrix_args[] = { @@ -130,6 +132,10 @@ static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_s { .i64 = -1 }, 0, 1, AV_OPT_FLAG_ARGUMENT}, { "vflip", "set vflip", OFFSET(vflip), AV_OPT_TYPE_BOOL, { .i64 = -1 }, 0, 1, AV_OPT_FLAG_ARGUMENT}, + { "hscale", "set scale factor", OFFSET(hscale), AV_OPT_TYPE_DOUBLE, + { .dbl = 1.0f }, 0.0f, 2.0f, AV_OPT_FLAG_ARGUMENT}, + { "vscale", "set scale factor", OFFSET(vscale), AV_OPT_TYPE_DOUBLE, + { .dbl = 1.0f }, 0.0f, 2.0f, AV_OPT_FLAG_ARGUMENT}, { NULL }, }; static const AVClass class_display_matrix_args = { @@ -848,6 +854,8 @@ static void add_display_matrix_to_stream(OptionsContext *o, .rotation = DBL_MAX, .hflip = -1, .vflip = -1, + .hscale = 1.0f, + .vscale = 1.0f, }; AVDictionary *global_args = NULL; @@ -903,6 +911,8 @@ static void add_display_matrix_to_stream(OptionsContext *o, av_display_matrix_flip((int32_t *)buf, hflip_set ? test_args.hflip : 0, vflip_set ? test_args.vflip : 0); + + av_display_matrix_scale((int32_t *)buf, test_args.hscale, test_args.vscale); } diff --git a/libavutil/display.c b/libavutil/display.c index d31061283c..b89763ff48 100644 --- a/libavutil/display.c +++ b/libavutil/display.c @@ -28,9 +28,11 @@ // fixed point to double #define CONV_FP(x) ((double) (x)) / (1 << 16) +#define CONV_FP2(x) ((double) (x)) / (1 << 30) // double to fixed point #define CONV_DB(x) (int32_t) ((x) * (1 << 16)) +#define CONV_DB2(x) (int32_t) ((x) * (1 << 30)) double av_display_rotation_get(const int32_t matrix[9]) { @@ -48,6 +50,17 @@ double av_display_rotation_get(const int32_t matrix[9]) return -rotation; } +double av_display_hscale_get(const int32_t matrix[9]) +{ + return fabs(CONV_FP2(matrix[2])); +} + +double av_display_vscale_get(const int32_t matrix[9]) +{ + return fabs(CONV_FP2(matrix[5])); +} + +#include void av_display_rotation_set(int32_t matrix[9], double angle) { double radians = -angle * M_PI / 180.0f; @@ -60,6 +73,8 @@ void av_display_rotation_set(int32_t matrix[9], double angle) matrix[1] = CONV_DB(-s); matrix[3] = CONV_DB(s); matrix[4] = CONV_DB(c); + matrix[2] = 1 << 30; + matrix[5] = 1 << 30; matrix[8] = 1 << 30; } @@ -72,3 +87,9 @@ 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 hscale, double vscale) +{ + matrix[2] = CONV_DB2(CONV_FP2(matrix[2]) * hscale); + matrix[5] = CONV_DB2(CONV_FP2(matrix[5]) * vscale); +} diff --git a/libavutil/display.h b/libavutil/display.h index 31d8bef361..b875e1cfdd 100644 --- a/libavutil/display.h +++ b/libavutil/display.h @@ -86,6 +86,26 @@ */ double av_display_rotation_get(const int32_t matrix[9]); +/** + * Extract the horizontal scaling component of the transformation matrix. + * + * @param matrix the transformation matrix + * @return the horizontal scaling by which the transformation matrix scales the frame + * in the horizontal direction. The scaling factor will be in the range + * [0.0, 2.0]. + */ +double av_display_hscale_get(const int32_t matrix[9]); + +/** + * Extract the vertical scaling component of the transformation matrix. + * + * @param matrix the transformation matrix + * @return the vertical scaling by which the transformation matrix scales the frame + * in the vertical direction. The scaling factor will be in the range + * [0.0, 2.0]. + */ +double av_display_vscale_get(const int32_t matrix[9]); + /** * Initialize a transformation matrix describing a pure clockwise * rotation by the specified angle (in degrees). @@ -105,6 +125,14 @@ 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 horizontally and/or vertically. + * + * @param matrix an allocated transformation matrix + * @param hscale whether the matrix should be scaled horizontally + * @param vscale whether the matrix should be scaled vertically + */ +void av_display_matrix_scale(int32_t matrix[9], double hscale, double vscale); /** * @} * @}