From patchwork Fri Apr 5 16:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1069263pzd; Fri, 5 Apr 2024 09:14:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUifR/2Vw382dw7gTs4MOO6S/C5xF/OSjgU8FANXy9orU+PbU9gcQCWTCmvXzp8ga+C2MIy54/m1WIeXwMhn3RAA3dEur+XLFyznQ== X-Google-Smtp-Source: AGHT+IESuPnoHqjWP8Dwx+r+JcFUfFuxjPjzft2pkRM8KMyRDsBEZQ1fh6bu/RqutHrP9wYdoSwt X-Received: by 2002:a05:6512:ac5:b0:513:e249:65fc with SMTP id n5-20020a0565120ac500b00513e24965fcmr1712418lfu.61.1712333640153; Fri, 05 Apr 2024 09:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333640; cv=none; d=google.com; s=arc-20160816; b=Tb1BMUztIwBq7OC8BVoDpb5dQEI1R+1qaBI7YsS87DeZqiUp3CkrPV3V2JQ2aAb7BZ m7LIlL+CQXy/voP+nuHpsLx9OZhDeZa9w10CLd1eRTqq5IZC5wvW8zxUo/iT8bg4Iu71 xb0bilkeIikzbrIrzpUIGcAXkf50bW+1tvWB49KQkx+ic0MGGSjP0EFH+oloKPluns/t eeH9WJTFA+BHLO6x1elMkQ4+/eUbqd41nD2xL0RkGGHAH5CU7azPbZFPfT295amCj6oM hTwFXeZsO4aVXVVJB/0ErVMwT2JBB12GfzjoXsp8PY/riWSwDyGf19885oD1SmL3mcEF iCAg== 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=OGiHSeREIrnwvJ9ChtdS6AVKPYk8J41/GPjY9DWc2jA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=VMFo4TT1R93Kf8mjKPgdF/4FNcSShmhCsLCoI9StHqxPEK8tQTLTj1gYcgpH0UXMIU y+sJoj9xiYu73Q84rCAO10sJOfQj46lkacSNX3bmhSRKxB+shAd6+3wHs3UiaNCGdSeD QWDQQ65DiYHXaIWb8BCGZaw7fil2kuimwp92fIUEBCUmDr+XcY7I0jhAboY1/IBtQXAO YYxWpHXL8+gulosewyS6fYksSMwGl2LNlHYIQ5ZaU0U+4xhrrzpe3fbKrQzs4cEyLOXd ZWp4uKOOsXQh6bj0+MpNw2XaiQaEGoXKchtWFSeawrKUbrpOJl66I9SV2eml6lE2Wv3b rYWQ==; 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=LKehudCC; 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 p22-20020a170906229600b00a5187f82094si810030eja.1.2024.04.05.09.13.59; Fri, 05 Apr 2024 09:14:00 -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=LKehudCC; 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 BDBFD68D226; Fri, 5 Apr 2024 19:13:15 +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 D94B168D158 for ; Fri, 5 Apr 2024 19:13:04 +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=LKehudCC; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DDB491C2D for ; Fri, 5 Apr 2024 18:13:03 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id nFOUmjVfoRrN for ; Fri, 5 Apr 2024 18:13:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333582; bh=dWjQT1LCqbuxp7FoipYB5TAkxT59bPzdJZK/3av37l8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LKehudCCCu+tuKTuvOd1WMRupcY6VOyVYiaVftOj8A1X2HTXNOzODuDfqWhTAiqyl qw0ay9i0SnIAVFumeMo8CcN46FCnG7yGVxZln3xiY1kktyd06WbmhMPP+kuyuC6LU3 ErBZCEDc+FWhKZzH9C+vYG0Ym6auO8+AzpiJTFwJP14FEoN2LhTxEe6ZuMYeL77UuM lVhgPOEdg1VQSRb+Q7SbH4+hNtnDT658tkxvBOb7dznTJMXKBoQ0NAkhbC8WqAhIzl Jx5YmBc/m1crlLOeSXWsZPNv4b9r0LdmvJuxptfyGOhNc/q9WwpwNKlNgCi9wKWYxX 4I5Tvck2ZkyxQ== 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 1B1B64D66 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 B91FB3A0CB6 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:48 +0200 Message-ID: <20240405161212.26167-7-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 07/31] fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions 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: F56orE2o6SzL Reduces the need to access OutputStream, which will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 9 +++++++-- fftools/ffmpeg_filter.c | 8 +++++--- fftools/ffmpeg_mux_init.c | 9 +++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 7288a48aa1..300ad8a987 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -263,11 +263,18 @@ typedef struct InputFilterOptions { AVFrame *fallback; } InputFilterOptions; +enum OFilterFlags { + OFILTER_FLAG_DISABLE_CONVERT = (1 << 0), +}; + typedef struct OutputFilterOptions { // Codec used for encoding, may be NULL const AVCodec *enc; int64_t ts_offset; + + // A combination of OFilterFlags. + unsigned flags; } OutputFilterOptions; typedef struct InputFilter { @@ -556,8 +563,6 @@ typedef struct OutputStream { char *attachment_filename; - int keep_pix_fmt; - /* stats */ // number of packets send to the muxer atomic_uint_least64_t packets_written; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 8b05262622..5f2dbc387e 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -214,6 +214,8 @@ typedef struct OutputFilterPriv { int64_t ts_offset; int64_t next_pts; FPSConvContext fps; + + unsigned flags; } OutputFilterPriv; static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter) @@ -355,11 +357,10 @@ static int choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint, const char **dst) { OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); - OutputStream *ost = ofilter->ost; *dst = NULL; - if (ost->keep_pix_fmt || ofp->format != AV_PIX_FMT_NONE) { + if (ofp->flags & OFILTER_FLAG_DISABLE_CONVERT || ofp->format != AV_PIX_FMT_NONE) { *dst = ofp->format == AV_PIX_FMT_NONE ? NULL : av_get_pix_fmt_name(ofp->format); } else if (ofp->formats) { @@ -777,6 +778,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofilter->ost = ost; av_freep(&ofilter->linklabel); + ofp->flags = opts->flags; ofp->ts_offset = opts->ts_offset; ofp->enc_timebase = ost->enc_timebase; @@ -814,7 +816,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, } } - fgp->disable_conversions |= ost->keep_pix_fmt; + fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT); ofp->fps.last_frame = av_frame_alloc(); if (!ofp->fps.last_frame) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 83eab4276e..d79ae1f491 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -580,7 +580,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) } static int new_stream_video(Muxer *mux, const OptionsContext *o, - OutputStream *ost) + OutputStream *ost, int *keep_pix_fmt) { AVFormatContext *oc = mux->fc; AVStream *st; @@ -638,7 +638,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st); if (frame_pix_fmt && *frame_pix_fmt == '+') { - ost->keep_pix_fmt = 1; + *keep_pix_fmt = 1; if (!*++frame_pix_fmt) frame_pix_fmt = NULL; } @@ -1041,7 +1041,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, OutputStream *ost; const AVCodec *enc; AVStream *st; - int ret = 0; + int ret = 0, keep_pix_fmt = 0; const char *bsfs = NULL, *time_base = NULL; char *filters = NULL, *next, *codec_tag = NULL; double qscale = -1; @@ -1356,7 +1356,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ms->copy_initial_nonkeyframes, oc, st); switch (type) { - case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost); break; + case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt); break; case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break; case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break; } @@ -1375,6 +1375,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, .enc = enc, .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ? 0 : mux->of.start_time, + .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt, }; if (ofilter) {