From patchwork Fri Apr 5 16:11:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47834 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1069366pzd; Fri, 5 Apr 2024 09:14:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXXFxohn3OVeHJZ5fzMO/nWntUxTnyFEgcDn+SyW7Xy+kro12HQOawlcvaKcjlb0XOEig0ROt10/5tMj5pJcCtjJ4ULGtYHJSNwng== X-Google-Smtp-Source: AGHT+IHCBTvLik0qaEO2xvBMhfUPk99LRjxJ7PkTkx+J3ay14r2RZ8rdVDkP3LzD49QM0HrKl8FD X-Received: by 2002:a17:907:9611:b0:a4e:2189:d06b with SMTP id gb17-20020a170907961100b00a4e2189d06bmr1722581ejc.60.1712333648664; Fri, 05 Apr 2024 09:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333648; cv=none; d=google.com; s=arc-20160816; b=jSpKnmhQHVax5gzjnR3LHR4LU37+cET86ymRisTaumqEvpvCQiK++G5F8aIiNsbJts Bf/+TKMtaenOmccKEf2LeorlTAoOXKiCPJyBM3oTXb8JOaTth4qixPdYwnm+wWXPF0BM I4TIkLWtAq8jcbPjFFgo11AJHRD+s6nWFVcUzZRqpGPNNJ2Cq2YR4E7NawBguq2RpqWx 7sgsIKRsFolRofrzvwuuhziuL82rkfo1tC5F5VDfy5FFk1GNoTq+54F7iONn7wRlf8Er ndiAON1Jz0TZ8T43j0cJ5sYLb9KKNl2bPXnIVNKmWsMz8asJhROKHsOmSklkkSui6c4W m0Zg== 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=Eu82G4tQj0yCjHtGOFeV0oaQPdC56EYRZkj2O2LZaXk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=lNwBVmpk7jkMtXbUjSz0CKAOoMML0Awe8BFqNVS953BL7BVanNI5eqKUWM2Uj8/KwQ OScXlCqi8s2AvlgHWlaMIyLuQQH20DcNU3LnHW4RRF+g3Qfj7HPePCIzQUhQHPi0YUUr BlyoMrV+93dUcasEbDzKFr6IoJxYobWvRXiRG+qT5ebNH1YEuYCmHyhyBe1eN0/MAOYI lHSOilgmkhqPWazCI2vmkpy/WsegQnwOnnPBQOJnbU2XNxIQXGRkJz8mMyC7rQQibO8j Cfrj0LwagMySB6Bb/U+19mHKD/kqcgKoG6UactoQgdnz9u7j69jSL/YrPo1Y1l/ELkDt Lbmg==; 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=LDnDP9PX; 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 le30-20020a170907171e00b00a46485678b2si803159ejc.651.2024.04.05.09.14.08; Fri, 05 Apr 2024 09:14:08 -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=LDnDP9PX; 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 9D5C368D22E; Fri, 5 Apr 2024 19:13:16 +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 3B6ED68D158 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=LDnDP9PX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C2EF84D66 for ; Fri, 5 Apr 2024 18:13:05 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id MeO202554SSs for ; Fri, 5 Apr 2024 18:13:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333582; bh=oNILVF1XefeTJpSRCuVtuKvXwkp3Nv8i/YSnCeDTfSg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LDnDP9PXPnFNc0DldM7acZAVkp4fWs3AzKSKPEgL08Cc3BIwxhmyi3r9hZbhrKRCZ Eaj67W5ZekvAW6z/lPG9SDnY3JYJ2wy24xIQ3M7Kadk3l5eRipl+v0/1hnoNc/lOUT O6Rw32vKv+WRuLIiRMYtfQLkmkQ71I+SfxXBzl5snptyKH+73RtlATPb/gSk3H9q6q Hw5g47ixKXUJqlJNuGoke2hNfAFZmNtdqKfGrPD1D3alhH77nZG7DvBDwgaHqoL3ni hds/xkIS168e917VAr4U2/PDcAFwUdnC7ZeyD70243mDA5Cz4JGvgoD9cqxX3osqRx vla1F+oVd4HcQ== 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 41BE14D7E 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 E7F683A0FB8 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:52 +0200 Message-ID: <20240405161212.26167-11-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 11/31] fftools/ffmpeg_filter: stop accessing encoder AVCodecContext 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: OroplGCQE+sO Pass all the necessary value through OutputFilterOptions. Will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 7 +++++++ fftools/ffmpeg_filter.c | 22 +++++++++++----------- fftools/ffmpeg_mux_init.c | 6 ++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d0e896dbe7..598ca2fa96 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -282,6 +282,13 @@ typedef struct OutputFilterOptions { // A combination of OFilterFlags. unsigned flags; + + int format; + int width; + int height; + + int sample_rate; + AVChannelLayout ch_layout; } OutputFilterOptions; typedef struct InputFilter { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 5661dc960a..3c25d2ed65 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -782,12 +782,12 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->ts_offset = opts->ts_offset; ofp->enc_timebase = opts->output_tb; - switch (ost->enc_ctx->codec_type) { + switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: - ofp->width = ost->enc_ctx->width; - ofp->height = ost->enc_ctx->height; - if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { - ofp->format = ost->enc_ctx->pix_fmt; + ofp->width = opts->width; + ofp->height = opts->height; + if (opts->format != AV_PIX_FMT_NONE) { + ofp->format = opts->format; } else if (opts->pix_fmts) ofp->formats = opts->pix_fmts; else if (opts->enc) @@ -812,19 +812,19 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, break; case AVMEDIA_TYPE_AUDIO: - if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { - ofp->format = ost->enc_ctx->sample_fmt; + if (opts->format != AV_SAMPLE_FMT_NONE) { + ofp->format = opts->format; } else if (opts->enc) { ofp->formats = opts->enc->sample_fmts; } - if (ost->enc_ctx->sample_rate) { - ofp->sample_rate = ost->enc_ctx->sample_rate; + if (opts->sample_rate) { + ofp->sample_rate = opts->sample_rate; } else if (opts->enc) { ofp->sample_rates = opts->enc->supported_samplerates; } - if (ost->enc_ctx->ch_layout.nb_channels) { + if (opts->ch_layout.nb_channels) { int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL, - &ost->enc_ctx->ch_layout); + &opts->ch_layout); if (ret < 0) return ret; } else if (opts->enc) { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 04642f5c8b..b031cc59d2 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1378,6 +1378,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { OutputFilterOptions opts = { .enc = enc, + .format = (type == AVMEDIA_TYPE_VIDEO) ? + ost->enc_ctx->pix_fmt : ost->enc_ctx->sample_fmt, + .width = ost->enc_ctx->width, + .height = ost->enc_ctx->height, + .sample_rate = ost->enc_ctx->sample_rate, + .ch_layout = ost->enc_ctx->ch_layout, .output_tb = enc_tb, .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ? 0 : mux->of.start_time,