From patchwork Fri Apr 5 16:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47857 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1071700pzd; Fri, 5 Apr 2024 09:17:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX8/vfePX5gWXGp9Dw1JKGCgAthinXrTRRZV1YqDh+YY/U7CtgwBD2Bw1+xTCMupkltQC3dJSN7OBdYFIkEWjFtkTpzsPQzoFClQw== X-Google-Smtp-Source: AGHT+IHH0F0vfAUxLl5HIJAQxTuR6TXhDGtDzBZWupmr6r0l2rSYqAH1S7D3Q5cUQk/1yyAWedbK X-Received: by 2002:a17:906:3e12:b0:a4e:37ac:79c8 with SMTP id k18-20020a1709063e1200b00a4e37ac79c8mr1263332eji.5.1712333849826; Fri, 05 Apr 2024 09:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333849; cv=none; d=google.com; s=arc-20160816; b=qzRM+P9PhE6qcGPwSxDLuMH9eLQOqxbvhNfh+GA0REdNCb3mr+mPpnupAhZUJiScre FHYYQiPpmaW24hOPQh4b/nVoAOGqSslHozLNJE1yv/sU8hw0Urhc67LTkNisJNQnzYqV KhMeZ1jJ7vunQMMCFSMehCQLKM2G5mIPWQ7MGOJ09R++jmDXj2+9l8wVb86COav5KN+1 ewvWGAFBJqXOfpGf+tyHxs5uUHvJLQJnHyXYwA+4c7ahwcWiyCRceAHrfSk0dDc3vQht IKGy13DhkmBE4k+Q5w46iT4ai2D+o7DLLMPwsMXoTVShLeGtnog4CO90TNw02vgyx4zv 5UJA== 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=W2sqAnj4wYv/SlHceyCIZ+o4s9O214vncinDNLPMp1s=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=lcuKzEXOQZ+OtnyGAWtjkSxZ5rVRhHNY7PHRL6+TozEoWCe3PbGRZw+At0AEaTkcd9 56CG0ocMDuJasnzvGCtXA91iKVQDLGvs3mt5rMSfuR/RO44zjCKUPpkksQHTsl3G8ztp HxaWz6INIPqJgQYgy/6rkrYnQr1rdBIMpR+hk8cjS5piinyHdlyIWOd9iZ+woyf6hOgp /s3uQYOi0LpWPiqndqGQ8Uczv/k4jOmxOBdjeC5TZxpEaHf2GrPVv6cFSzT/SUX0gJgm nZ9sjRwla17wnCFK2xFQT2xhuv7tckb1XcygUZKMJNbBN1u80t1fCbMYMgqndF1o7YA1 WXlQ==; 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=TNmRvIOu; 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 dv25-20020a170906b81900b00a4e2acb2d37si833778ejb.231.2024.04.05.09.17.29; Fri, 05 Apr 2024 09:17:29 -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=TNmRvIOu; 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 D0E0B68D375; Fri, 5 Apr 2024 19:13:39 +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 D307168D225 for ; Fri, 5 Apr 2024 19:13:09 +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=TNmRvIOu; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 043AA4D5C 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 J_fsP5cMrXaZ 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=RM1Ur/F1AhrB7CWVlgjyaiMIm5oiwTPXRnAv8vBaqFg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TNmRvIOu7mTFF3SZJ6ZCDmJt9H0u372dImBSg8w8axn4SB1xom4u/I7xUQUh986o/ 1mt1iblE1g7i0c13RdCsyOztage9PKUrcZo3/8KZtLot0KBVSmGzP7yYT7EXz4292l lqty2kKkizyk+gL5PDHogPuDjnPKEmtnG834JxazTuNkugPI9Y/inygOP0KLFj4t90 1xGphvEuj6lL+2mHijyCM9S4QvfzGf8mWP+YVJ5aDa+YfnZeqYDNoDMaGGS/fzdF18 gE3O6CoFUDxlBTNHCYvof3GEK5GHMfwbB0xzQgvxZa9UeRlkZKFyozvmK5UflEyVCx IpSDygAA/ifeA== 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 E5CFD1D2E for ; Fri, 5 Apr 2024 18:13:01 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9732D3A0B52 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:45 +0200 Message-ID: <20240405161212.26167-4-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 04/31] fftools/ffmpeg_filter: stop accessing AVCodecContext.codec 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: OOionlN+G0Ub Instead pass the encoder through a newly-added output options struct, analogous to previously added input options. Will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 11 +++++++++-- fftools/ffmpeg_filter.c | 36 +++++++++++++++++++----------------- fftools/ffmpeg_mux_init.c | 8 ++++++-- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index a575ee70d5..8455cb23e4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -263,6 +263,11 @@ typedef struct InputFilterOptions { AVFrame *fallback; } InputFilterOptions; +typedef struct OutputFilterOptions { + // Codec used for encoding, may be NULL + const AVCodec *enc; +} OutputFilterOptions; + typedef struct InputFilter { struct FilterGraph *graph; uint8_t *name; @@ -684,7 +689,8 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id int filtergraph_is_simple(const FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc, - Scheduler *sch, unsigned sch_idx_enc); + Scheduler *sch, unsigned sch_idx_enc, + const OutputFilterOptions *opts); int fg_finalise_bindings(FilterGraph *fg); /** @@ -699,7 +705,8 @@ FrameData *packet_data (AVPacket *pkt); const FrameData *packet_data_c(AVPacket *pkt); int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, - unsigned sched_idx_enc); + unsigned sched_idx_enc, + const OutputFilterOptions *opts); /** * Create a new filtergraph in the global filtergraph list. diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ba6c6c7673..0d359303f7 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -763,13 +763,13 @@ static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layout } int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, - unsigned sched_idx_enc) + unsigned sched_idx_enc, + const OutputFilterOptions *opts) { const OutputFile *of = ost->file; OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); FilterGraph *fg = ofilter->graph; FilterGraphPriv *fgp = fgp_from_fg(fg); - const AVCodec *c = ost->enc_ctx->codec; int ret; av_assert0(!ofilter->ost); @@ -786,14 +786,14 @@ 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 { - ofp->formats = c->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(c->name, "mjpeg")) { + 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[] = @@ -822,11 +822,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->fps.framerate = ost->frame_rate; ofp->fps.framerate_max = ost->max_frame_rate; - ofp->fps.framerate_supported = ost->force_fps ? - NULL : c->supported_framerates; + ofp->fps.framerate_supported = ost->force_fps && opts->enc ? + NULL : opts->enc->supported_framerates; // reduce frame rate for mpeg4 to be within the spec limits - if (c->id == AV_CODEC_ID_MPEG4) + if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4) ofp->fps.framerate_clip = 65535; ofp->fps.dup_warning = 1000; @@ -835,20 +835,21 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, case AVMEDIA_TYPE_AUDIO: if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { ofp->format = ost->enc_ctx->sample_fmt; - } else { - ofp->formats = c->sample_fmts; + } else if (opts->enc) { + ofp->formats = opts->enc->sample_fmts; } if (ost->enc_ctx->sample_rate) { ofp->sample_rate = ost->enc_ctx->sample_rate; - } else { - ofp->sample_rates = c->supported_samplerates; + } else if (opts->enc) { + ofp->sample_rates = opts->enc->supported_samplerates; } if (ost->enc_ctx->ch_layout.nb_channels) { - int ret = set_channel_layout(ofp, c->ch_layouts, &ost->enc_ctx->ch_layout); + int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL, + &ost->enc_ctx->ch_layout); if (ret < 0) return ret; - } else if (c->ch_layouts) { - ofp->ch_layouts = c->ch_layouts; + } else if (opts->enc) { + ofp->ch_layouts = opts->enc->ch_layouts; } break; } @@ -1079,7 +1080,8 @@ fail: int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc, - Scheduler *sch, unsigned sched_idx_enc) + Scheduler *sch, unsigned sched_idx_enc, + const OutputFilterOptions *opts) { FilterGraph *fg; FilterGraphPriv *fgp; @@ -1111,7 +1113,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, if (ret < 0) return ret; - ret = ofilter_bind_ost(fg->outputs[0], ost, sched_idx_enc); + ret = ofilter_bind_ost(fg->outputs[0], ost, sched_idx_enc, opts); if (ret < 0) return ret; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index d3d7d022ff..b5869feb80 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1371,14 +1371,18 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + OutputFilterOptions opts = { + .enc = enc, + }; + if (ofilter) { ost->filter = ofilter; - ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc); + ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts); if (ret < 0) return ret; } else { ret = init_simple_filtergraph(ost->ist, ost, filters, - mux->sch, ms->sch_idx_enc); + mux->sch, ms->sch_idx_enc, &opts); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error initializing a simple filtergraph\n");