From patchwork Fri Aug 30 10:15:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 51249 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:4027:b0:48e:c0f8:d0de with SMTP id ky39csp402801vqb; Fri, 30 Aug 2024 06:30:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW2YQrjk0khu0cHbZTjCihzoGRJd99FM2zFhlZZdYHobmBnKGrHTLlv/sQmDdjf3JrFDkA4y4G+mu0CgXcrepqH@gmail.com X-Google-Smtp-Source: AGHT+IHeS+tLjec0xF6zoKYGsEj3ipW8roRd5pqsA3jIeVQpoF80BxkJGvuxSfLhtzhwcL7Qlti0 X-Received: by 2002:a05:6512:6cd:b0:52e:764b:b20d with SMTP id 2adb3069b0e04-53546b31585mr1556224e87.28.1725024613072; Fri, 30 Aug 2024 06:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725024613; cv=none; d=google.com; s=arc-20240605; b=Rf7FjovWWnewVPhfTG/SH7XrpHpu93HpS3KesTHSWTeOjyKmOHujEtdFtnCpbrNtKn nNw/B+XT6m/VEW6/crmnv9LDyI/7k7a+HIX8XSgvd7fw6YNHj6eYxNiA2SHQ8Gyajeps e4ATvbdEbPK30T0PXzvI4kV9um9DRZXIg+JG7K1IAdZDL+S64R1eLV5xJawddY77qMN3 +PBn5m8olwUXl7bNsHOYU3IU6KRhd+Izc8+aM5bgOw45SigMt1wrxTol9M90dXBa+dcB pxMtsEMxVq85+YNGzxWAi3xpnkVH8T/ppZNK2zMvCCl2qciRWujegfOQAL6l1m76Gv18 0sbQ== 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=VKRtHtOR07CkTWdW5DgMUpy1MDEyBd0cn5UG9g4yf2B1zNBHBn1HWa+hyyi4xuAn74 VbTq0Ze3SYxV4nkDf0s4VTSY9/DCgNUpWBhdnhlLWEySO0w8fAr0MOMQWpPXTLQ+616l 1gxEDdQzCBogjUc16b4rdD3Rf3+n6mMg4qVUZv+c2w7DpsRrhROs4TFcdhd4ajKJYdvp 617cc9XuUnOlTqSN3v0CfddIsyXAiAbif0B2QfgfJqXG/hY9Z3IxXDXjXyEdVhG3/3xH ielWxwWA/eUmYI5m0riWU1FDYGfnzcTshkXEEAy9RsCXbIvhJkkoLx/mc4++Cd4excIw tOdg==; 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=Yg8J877k; 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 2adb3069b0e04-535407eb899si1203919e87.336.2024.08.30.06.30.12; Fri, 30 Aug 2024 06:30:13 -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=Yg8J877k; 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 4B71168DBDB; Fri, 30 Aug 2024 13:24:25 +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 4ADAB68DB63 for ; Fri, 30 Aug 2024 13:24:14 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1725013451; bh=UBbrQS7WNK38offINKvhxW06U8AU74L3U9jE9bJA1ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yg8J877ksR68TW9H1DOHs+IhwI99uiIH6NrOOE0ysYrZBofIQqlFyUP+ewDyMrR92 cH9PuSTaxDOBLnLB7e4TqXNFdEGUzNAKxnDpp8gWKbJ/p50oX1VDcrE6Mx0K5/fQJT 44aUeKBKYQKMEBSFhM7HjXb2tnY5rwMWoTMa5g/M= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2DB494796B; Fri, 30 Aug 2024 12:24:11 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Aug 2024 12:15:37 +0200 Message-ID: <20240830102402.18149-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240830102402.18149-1-ffmpeg@haasn.xyz> References: <20240830102402.18149-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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: XpG6SsdKmRvy 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) {