From patchwork Wed Sep 4 11:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 51336 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:2543:b0:48e:c0f8:d0de with SMTP id hf3csp148266vqb; Wed, 4 Sep 2024 04:19:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVEyU0aWZGFaS7Ej6HBBTw6kLx7EDdsdUcHsAAPRl44zS/un0XrX6UYn7ENGhdL4rdSd444tAAHnbTLxI3XSNkq@gmail.com X-Google-Smtp-Source: AGHT+IF1Ujz+EKR1/fHNNVaBRk4Ci2OmO2I6JNAiah8jvNZFGeAPs53yIdLs4GPe+el+/HxpD91Q X-Received: by 2002:a17:907:7ba8:b0:a86:a178:42da with SMTP id a640c23a62f3a-a8a32e7404emr319812066b.21.1725448751813; Wed, 04 Sep 2024 04:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725448751; cv=none; d=google.com; s=arc-20240605; b=Ca93n+3eTgWpOzoKY+tRVzrwHxw62KnzUzXR7Uvc4haOfoH0bW+Kx3ZX9h8FFfkTSi L9QTo/n0D7iKGP7e0+T4eCbbu6jMa39mnHnLWb/zPpmbOKMBg7q6jmmurGWgfwmmhQCr 9NvPiStpT/00bjVHGgzGGgtc/A1qyrLl/0bvyo3Mt5txrM19piCmcLD8FHNP2+oI6aAq cfeqXiCrB1mhHYQ2veCEt9VicXRCGhweqkPtAkHzYWzqwooUxQC5aX54I9x+J44UEkBU 7OQCxZA7qYv8987peAdD6gaOhRgIEDG8mE1AudzEqx7vRcdJBP+MFTBkqm1MvYLmKbSr OXQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=6M7UHw7Nzj29Uz3pQEtggOIf3ZN9ne7YkTqzl8JKT80=; fh=Avpk+LKcNkHKoWajGZeevGRAc++LPBUE4dPECo0/YT8=; b=bNgAYibghbmoDCEed+x4ANhHOtRVpgO73L2VzAKj+uh+HLf9d88HmSBn5HmbfLnDSO q/HV6IHHoFZ+I6xAIoO6yQj0k4YdUZf0zr2rWkxluJh6H06B7iwR4dXzYS1fS3LQTYtt Z4NWfrN5WRpQCwbaxhj6G8UJfZS2uqlha+sDmGx1T+sTzTAGXvEz6669UvsDt4PrfGz9 Ck1lmbCmxFXcn+7Ot/83ydCtpJfisqNBc7emnJdVR7eDSR1iBnkAlx3/1VOsvPmZfMyG t+pRkfBT2/6GYkLN9Gf8dJfqxZhVY/ovaytmrnje4WgxCYuFi6h7lW8686BLAK1K566d OjNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=rdWK18Ir; 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 a640c23a62f3a-a8988f40e91si1031843466b.6.2024.09.04.04.19.10; Wed, 04 Sep 2024 04:19:11 -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=@haasn.xyz header.s=mail header.b=rdWK18Ir; 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 9751768DEAC; Wed, 4 Sep 2024 14:08:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C472768DDC0 for ; Wed, 4 Sep 2024 14:08:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1725448089; bh=UBbrQS7WNK38offINKvhxW06U8AU74L3U9jE9bJA1ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rdWK18IrNVDlIgMZ5aLHI/yZLKarCSft4VF2my+uLO3nGthqjNDXp3h5ncEnWbCOd rOGWZicekdE8hGJqfllAhrC7s9LYWZIC7km/bvZJWxdoVyd9vnadg6a3LvsEIa+NxC J6U9d0QYXZ56n724IXNye6D66nfIpQFSgrCTcxeU= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9B45741BA4; Wed, 4 Sep 2024 13:08:09 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Sep 2024 13:02:43 +0200 Message-ID: <20240904110720.11713-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904110720.11713-1-ffmpeg@haasn.xyz> References: <20240904110720.11713-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 14/17] fftools/ffmpeg_mux_init: factor out binding filters to output streams 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: Anton Khirnov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bGEhH7W3eneD From: Anton Khirnov --- fftools/ffmpeg_mux_init.c | 137 ++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 59 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6b101dcbbc..c6dc4a0699 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -916,6 +916,82 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, return 0; } +static int +ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, + const OptionsContext *o, char *filters, + AVRational enc_tb, enum VideoSyncMethod vsync_method, + int keep_pix_fmt, int autoscale, int threads_manual) +{ + OutputStream *ost = &ms->ost; + AVCodecContext *enc_ctx = ost->enc_ctx; + char name[16]; + int ret; + + OutputFilterOptions opts = { + .enc = enc_ctx->codec, + .name = name, + .format = (ost->type == AVMEDIA_TYPE_VIDEO) ? + enc_ctx->pix_fmt : enc_ctx->sample_fmt, + .width = enc_ctx->width, + .height = enc_ctx->height, + .vsync_method = vsync_method, + .sample_rate = enc_ctx->sample_rate, + .ch_layout = enc_ctx->ch_layout, + .sws_opts = o->g->sws_dict, + .swr_opts = o->g->swr_opts, + .output_tb = enc_tb, + .trim_start_us = mux->of.start_time, + .trim_duration_us = mux->of.recording_time, + .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ? + 0 : mux->of.start_time, + + .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt | + OFILTER_FLAG_AUTOSCALE * !!autoscale | + OFILTER_FLAG_AUDIO_24BIT * !!(av_get_exact_bits_per_sample(enc_ctx->codec_id) == 24), + }; + + snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index); + + // 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_ctx->codec->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 }; + + if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) + opts.pix_fmts = mjpeg_formats; + } + + if (threads_manual) { + ret = av_opt_get(enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads); + if (ret < 0) + return ret; + } + + if (ofilter) { + ost->filter = ofilter; + ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts); + } else { + ret = init_simple_filtergraph(ost->ist, ost, filters, + mux->sch, ms->sch_idx_enc, &opts); + } + av_freep(&opts.nb_threads); + if (ret < 0) + return ret; + + ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc), + SCH_MSTREAM(mux->sch_idx, ms->sch_idx)); + if (ret < 0) + return ret; + + return ret; +} + static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **encoder_opts) { MuxStream *ms = ms_from_ost(ost); @@ -1398,65 +1474,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { - char name[16]; - OutputFilterOptions opts = { - .enc = enc, - .name = name, - .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, - .vsync_method = vsync_method, - .sample_rate = ost->enc_ctx->sample_rate, - .ch_layout = ost->enc_ctx->ch_layout, - .sws_opts = o->g->sws_dict, - .swr_opts = o->g->swr_opts, - .output_tb = enc_tb, - .trim_start_us = mux->of.start_time, - .trim_duration_us = mux->of.recording_time, - .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ? - 0 : mux->of.start_time, - .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt | - OFILTER_FLAG_AUTOSCALE * !!autoscale | - OFILTER_FLAG_AUDIO_24BIT * !!(av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24), - }; - - snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index); - - // 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 }; - - if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) - opts.pix_fmts = mjpeg_formats; - } - - if (threads_manual) { - ret = av_opt_get(ost->enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads); - if (ret < 0) - goto fail; - } - - if (ofilter) { - ost->filter = ofilter; - ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts); - } else { - ret = init_simple_filtergraph(ost->ist, ost, filters, - mux->sch, ms->sch_idx_enc, &opts); - } - av_freep(&opts.nb_threads); - if (ret < 0) - goto fail; - - ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc), - SCH_MSTREAM(mux->sch_idx, ms->sch_idx)); + ret = ost_bind_filter(mux, ms, ofilter, o, filters, enc_tb, vsync_method, + keep_pix_fmt, autoscale, threads_manual); if (ret < 0) goto fail; } else if (ost->ist) {