From patchwork Fri Apr 5 16:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47835 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1069562pzd; Fri, 5 Apr 2024 09:14:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU6aersAup83d/edTkfiqcflmBhGW5vAtpXOZW/yH4kD3a74BtU9fxd9I07Z6+qL9+sgP9SoSdxA60/HM36p51JQjFOi25Pkh/x9A== X-Google-Smtp-Source: AGHT+IGnVJ4tjzfNi2noCcp9wN2QAddBNsv5/lytWDTZDKa2tbSTJ4Pax5vu2ed2qfkMfQQXksWO X-Received: by 2002:a17:907:75d7:b0:a4d:f5e0:6157 with SMTP id jl23-20020a17090775d700b00a4df5e06157mr1250294ejc.7.1712333666042; Fri, 05 Apr 2024 09:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333666; cv=none; d=google.com; s=arc-20160816; b=iMbcAgpHtjwBY9lNS+/mo8gH6KDSYz1fpD7FpFPiU0Au15P3isghIMN176f6LvPNUM nP9cz1YMKVLelW8gkoNJAHoZxNQLYL6JeZxZtArTQqvCMHYf60VtkTfFrBNt1HiMosDq Ti9fMwWNZY6I+Qqtb7vokGQtCIdxXAKbBrqvH3uh5ppfg/SGaglDs4VQgbV7acb70UJw g3kGTKPVRI6+00OvBIWOrjYx6UJ0Eh2vVQ6XVslYvilPnOScD5sxQ4uT8z2Vf6NM/web AzLkR8mJDdwRVxO5iDxTzRffzHgpF20dmYlg7MQWTQ0+Fk6XBPPQjHkRPnqBfNEQzbpy hstQ== 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=nnseFfKfwqw+NlEGRel0w7wwU0yrvH0XsRC6p/YCdA0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=So6OJJdbbJ78EYvEjtEG8vkR2yISOsRRW1/7ZA9xgLn+UQVS5buRcSHeGFgqTIneIo UxzquwBHjEf0dmR+AErnBaw1tELTUUoKBc6P0+2xqpTi312ebR7WIgmjxbvi6CUZBH4S zVTtTU+CvvaJ6aEbucR1avfbCUp5C9YPHHI882my2qfyOTUSOeA+UggXCYf2AVOu4kd6 KDRIVAA+YKPCthNyuX49N1unk+wUFxN2qv/wBU1tb5Uwuw2PQW0D11+Fh53H+3LOsFES NiaUAocn5qTU3Ymi9111AkSs19j1ixEb0OVdsesTyT4QHvHltI9jMXYQj41NhHnDjn5M g/0Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=P76rwBwc; 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 o25-20020a1709062e9900b00a51a78f4ed7si615954eji.220.2024.04.05.09.14.25; Fri, 05 Apr 2024 09:14:26 -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=@khirnov.net header.s=mail header.b=P76rwBwc; 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 530E168D18A; Fri, 5 Apr 2024 19:13:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 415EC68D16D for ; Fri, 5 Apr 2024 19:13:10 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=P76rwBwc; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id F419F4D79 for ; Fri, 5 Apr 2024 18:13:04 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id LDcD4bHljEtx for ; Fri, 5 Apr 2024 18:13:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333582; bh=Ev6m59ZqcZ3VXvTbzJz+b4jr9WP+wE/ldwFphrMydJU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=P76rwBwcc4wajCWlJeeEzEFc8OnJXXt8GzZz1gRnpWa2by/L+J88wCupAkw/zlO4m GAKlDNyCQls0HAvcePEuqE0uvM8zhTHgxMjnVFvCJsxROV6qbqUUby4eFuuz0Orviz Jja/Df47IX48rO1s3RV+xadd0LHR4uPaxcgPiOpa2gZ18TVOz6Zy4DhqI6FqpGznwv qNpdtTVwS91/WuT6I78E/yQuFbLFZavx0E0Lp3qu+mN6vrYCCZfwcmlzzp1jvcMKcB b4RJOasD2ZiPUP4zNhrBcnZtw1BNM6Xslyn9puPDmgeFyqWrmWV0xol68pM3NssGGR zs8OCCLTLP5Mw== 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 3BACC4D7D for ; Fri, 5 Apr 2024 18:13:02 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DC7403A0F49 for ; Fri, 5 Apr 2024 18:12:55 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 18:11:51 +0200 Message-ID: <20240405161212.26167-10-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240405161212.26167-1-anton@khirnov.net> References: <20240405161212.26167-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/31] fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup 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: YJ1QaFyfxIe1 That, if anywhere, is a more appropriate place for it. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_filter.c | 29 +++-------------------------- fftools/ffmpeg_mux_init.c | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 56c2fedcc4..d0e896dbe7 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -270,6 +270,8 @@ enum OFilterFlags { typedef struct OutputFilterOptions { // Codec used for encoding, may be NULL const AVCodec *enc; + // Overrides encoder pixel formats when set. + const enum AVPixelFormat *pix_fmts; int64_t ts_offset; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 0b78898af0..5661dc960a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -788,34 +788,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->height = ost->enc_ctx->height; if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { ofp->format = ost->enc_ctx->pix_fmt; - } else if (opts->enc) { + } else if (opts->pix_fmts) + ofp->formats = opts->pix_fmts; + else if (opts->enc) ofp->formats = opts->enc->pix_fmts; - // MJPEG encoder exports a full list of supported pixel formats, - // but the full-range ones are experimental-only. - // Restrict the auto-conversion list unless -strict experimental - // has been specified. - if (!strcmp(opts->enc->name, "mjpeg")) { - // FIXME: YUV420P etc. are actually supported with full color range, - // yet the latter information isn't available here. - static const enum AVPixelFormat mjpeg_formats[] = - { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, - AV_PIX_FMT_NONE }; - - const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0); - int strict_val = ost->enc_ctx->strict_std_compliance; - - if (strict) { - const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0); - av_assert0(o); - av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val); - } - - if (strict_val > FF_COMPLIANCE_UNOFFICIAL) - ofp->formats = mjpeg_formats; - } - } - fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT); ofp->fps.last_frame = av_frame_alloc(); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 28090423c6..04642f5c8b 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1384,6 +1384,30 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt, }; + // MJPEG encoder exports a full list of supported pixel formats, + // but the full-range ones are experimental-only. + // Restrict the auto-conversion list unless -strict experimental + // has been specified. + if (!strcmp(enc->name, "mjpeg")) { + // FIXME: YUV420P etc. are actually supported with full color range, + // yet the latter information isn't available here. + static const enum AVPixelFormat mjpeg_formats[] = + { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, + AV_PIX_FMT_NONE }; + + const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0); + int strict_val = ost->enc_ctx->strict_std_compliance; + + if (strict) { + const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0); + av_assert0(o); + av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val); + } + + if (strict_val > FF_COMPLIANCE_UNOFFICIAL) + opts.pix_fmts = mjpeg_formats; + } + if (ofilter) { ost->filter = ofilter; ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts);