From patchwork Fri Apr 5 16:11:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 47853 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1071366pzd; Fri, 5 Apr 2024 09:16:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX+9i4dJwcIcjFd5UBMdyZyHZuZyXL38H53dFFJ9sqCyrtLuKdPRB6NvUEzFpggG4ryGUewYFTnHwNE1O29JSCfu2qHYd9QUPWS1A== X-Google-Smtp-Source: AGHT+IH+gSwPAJSpYMTD18j+PH/Hu8v+fXaD0iV+AoWmhMBbZ8RC4svj9a/Y3ehwjk7lLHc/fo8q X-Received: by 2002:a2e:9887:0:b0:2d8:5af9:90c5 with SMTP id b7-20020a2e9887000000b002d85af990c5mr1999449ljj.39.1712333817912; Fri, 05 Apr 2024 09:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712333817; cv=none; d=google.com; s=arc-20160816; b=v6F+i3Klw67szg3K4eH3YZrevLKVWtDoPjm5TozJ9B9ZoJbvCxVepFBvvs4sOjVkLS 9ufatGAG2LoWcCSzMgIC/ffwIpy32jR2SrOvGlGqk3bwFPVcC2MUlg7+LMOiXEWnZIcS Yc/PZVQBgC5JK/UH+XMc/pCPfXT4xoyRMON8wxwAJtzSTsfpmhsbS8MllpKBv8YHY208 L3jndrfC8kxUgCm7l0X3pbvZX9gLYKWsdxEK72cMfn97LUvJaSAmOeavH5dBKmo3nPds 7tXtp/Ya07o2s2VGfBDCe0eR+crNUtk64Ext6Ta/T+l2Z3UoLI+Wv1llaDE+5XA413gx y2dg== 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=BTbrE7vQNtLZ8C/+LKv+VYjXZ5reUCk3yNQsrk8p8NI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=h+ItBu1mtfIDYNkkllLgQaLpaDU3R/EsPkv+/BPSBOejzlyrCNeAy38bcuJaMuCkl9 pJnqdO95wwLLmX7n/AuMKafeHguebMw4X8k+WEVFr5B1k9AgtOXaN9QjLnysEXhQ8v7H lOevBuMhcEFqe5DT43G4MIQ0stlm21MvBpXrFwLfE3ZqrCNV8SZrUErMc7SjR3SL6b7k z9GwKu1dFRNWBmdALjKlyEPYHL4hFTLkSlrCNCb7GuESR21tbKB4Cf0dO+o9mVLKumSN AtoeJPAxDUNCGfd11fQLB+H2z1eVInQ9OKQ0k3wsYpG7S/69wP1ZPwCat7xXC7xEaGGA 0gnA==; 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=qkwjmLDy; 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 s6-20020a1709067b8600b00a4e6cdf8ea3si822180ejo.715.2024.04.05.09.16.57; Fri, 05 Apr 2024 09:16:57 -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=qkwjmLDy; 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 E8D6968D315; Fri, 5 Apr 2024 19:13:35 +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 9471F68D16C 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=qkwjmLDy; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id B03614D91 for ; Fri, 5 Apr 2024 18:13:07 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id VGFObdOn88gg for ; Fri, 5 Apr 2024 18:13:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712333583; bh=Eoq48a4W1o2ejS3sixphWC3FuMbNCjYVuYNqJWqNeIk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qkwjmLDySheq1dwWENN+P5e9N2M7tUgFNNLvtsYjMHNkoKIbsxbd44ZQsM6yqkIGu QlI4pd3fOQXhdTuSSKNrjmMgA3+5O72XFtyqKh2ctIwaqlTZb1ATzGTOoZ9YrW6HM2 ucSX7NWFnCucWdYPe1qNPAqWUWEQqJgUkZFUdOJ1CygR0Vh3Ge329O/oyndohCgc5k KuVu+otpw3uRa5Lxt++uo2mMDQ/kbRCMM1FWEqMrg2JCOkcUZgSeyOqaYu7bPibCJA 0iFvyg7aFlAhIhC6dIshZ5YVMQgiXIRNAtsIcN55JR5mCSa/lv070Ukk2Q0Thbkmll +t+HR0hqZhK1A== 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 5610F4D88 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 173023A11EF for ; Fri, 5 Apr 2024 18:12:56 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 18:11:55 +0200 Message-ID: <20240405161212.26167-14-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 14/31] fftools/ffmpeg_filter: accept a caller-provided output name 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: zAWWWLyWhUgS Do not construct it from OutputStream manually. Will allow decoupling filtering from encoding in future commits. --- fftools/ffmpeg.h | 3 +++ fftools/ffmpeg_filter.c | 36 +++++++++++++++++++----------------- fftools/ffmpeg_mux_init.c | 4 ++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 16497105e1..3c196c25e5 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -268,6 +268,9 @@ enum OFilterFlags { }; typedef struct OutputFilterOptions { + // Caller-provided name for this output + char *name; + // Codec used for encoding, may be NULL const AVCodec *enc; // Overrides encoder pixel formats when set. diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 022c42e9c7..ceab58da19 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -188,6 +188,8 @@ typedef struct OutputFilterPriv { int index; + char *name; + AVFilterContext *filter; /* desired output stream properties */ @@ -784,6 +786,10 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->ts_offset = opts->ts_offset; ofp->enc_timebase = opts->output_tb; + ofp->name = av_strdup(opts->name); + if (!ofp->name) + return AVERROR(EINVAL); + switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: ofp->width = opts->width; @@ -911,6 +917,7 @@ void fg_free(FilterGraph **pfg) av_freep(&ofilter->linklabel); av_freep(&ofilter->name); + av_freep(&ofp->name); av_channel_layout_uninit(&ofp->ch_layout); av_freep(&fg->outputs[j]); } @@ -1076,9 +1083,8 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, fgp->is_simple = 1; - snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf#%d:%d", - av_get_media_type_string(ost->type)[0], - ost->file->index, ost->index); + snprintf(fgp->log_name, sizeof(fgp->log_name), "%cf%s", + av_get_media_type_string(ost->type)[0], opts->name); if (fg->nb_inputs != 1 || fg->nb_outputs != 1) { av_log(fg, AV_LOG_ERROR, "Simple filtergraph '%s' was expected " @@ -1305,7 +1311,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, const char *pix_fmts; char name[255]; - snprintf(name, sizeof(name), "out_%d_%d", ost->file->index, ost->index); + snprintf(name, sizeof(name), "out_%s", ofp->name); ret = avfilter_graph_create_filter(&ofp->filter, avfilter_get_by_name("buffersink"), name, NULL, NULL, graph); @@ -1325,8 +1331,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value); } - snprintf(name, sizeof(name), "scaler_out_%d_%d", - ost->file->index, ost->index); + snprintf(name, sizeof(name), "scaler_out_%s", ofp->name); if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"), name, args, NULL, graph)) < 0) return ret; @@ -1358,8 +1363,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, pad_idx = 0; } - snprintf(name, sizeof(name), "trim_out_%d_%d", - ost->file->index, ost->index); + snprintf(name, sizeof(name), "trim_out_%s", ofp->name); ret = insert_trim(of->start_time, of->recording_time, &last_filter, &pad_idx, name); if (ret < 0) @@ -1384,7 +1388,7 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, char name[255]; int ret; - snprintf(name, sizeof(name), "out_%d_%d", ost->file->index, ost->index); + snprintf(name, sizeof(name), "out_%s", ofp->name); ret = avfilter_graph_create_filter(&ofp->filter, avfilter_get_by_name("abuffersink"), name, NULL, NULL, graph); @@ -1424,8 +1428,7 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, if (args.len) { AVFilterContext *format; - snprintf(name, sizeof(name), "format_out_%d_%d", - ost->file->index, ost->index); + snprintf(name, sizeof(name), "format_out_%s", ofp->name); ret = avfilter_graph_create_filter(&format, avfilter_get_by_name("aformat"), name, args.str, NULL, graph); @@ -1452,8 +1455,7 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, } } - snprintf(name, sizeof(name), "trim for output stream %d:%d", - ost->file->index, ost->index); + snprintf(name, sizeof(name), "trim for output %s", ofp->name); ret = insert_trim(of->start_time, of->recording_time, &last_filter, &pad_idx, name); if (ret < 0) @@ -2699,10 +2701,10 @@ static void fg_thread_set_name(const FilterGraph *fg) { char name[16]; if (filtergraph_is_simple(fg)) { - OutputStream *ost = fg->outputs[0]->ost; - snprintf(name, sizeof(name), "%cf#%d:%d", - av_get_media_type_string(ost->type)[0], - ost->file->index, ost->index); + OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[0]); + snprintf(name, sizeof(name), "%cf%s", + av_get_media_type_string(ofp->ofilter.type)[0], + ofp->name); } else { snprintf(name, sizeof(name), "fc%d", fg->index); } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 1791905d7e..219be5f965 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1381,8 +1381,10 @@ 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, @@ -1396,6 +1398,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt, }; + 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