From patchwork Sat Sep 28 09:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51901 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp895648vqb; Sat, 28 Sep 2024 02:54:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXlLuIOj/JspsEdU0YcKmQ7K7SYEUuzzx8tx20UjmKD9mCpZoN76GtPvhBdpIZ/WDnOUfBZgCfF0b5as5l776Hg@gmail.com X-Google-Smtp-Source: AGHT+IF9DKCPaQSyN4NI5ijuL/2JFCpIgxwKsPmxWKkU8AGvAKppMpzAuHHHR9P+4XTfDPqRXWPd X-Received: by 2002:a05:6512:1046:b0:538:9e1e:b06f with SMTP id 2adb3069b0e04-5389fc46d48mr5317773e87.27.1727517280307; Sat, 28 Sep 2024 02:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517280; cv=none; d=google.com; s=arc-20240605; b=PxWS0X9MJ3LOmls/EOL/pZ2ECTZ6qs2bM97i4h1G0u4w8iZ34aJlA3qOS0s0+5WWRj sTO9rheZ/7SfyCoVSMOFse5lbY6iDNpd3zrl1+C0OlcOsWGPnWU0bLVJLL6GvYmsB6uC g/GT2FPwDNfMKjsXm6PtOoalOiT4IsDcey0EZkO7NzcSzGuR1N76gcKYt1YB6v/V7JXd NreLjuG0sye50HZYWBiMV2XvkcO+X7OKcpoa6r8UC7hzqlzEZozPUVDIdEFhBJjlUofD kNNLdXKNvRrx1rqIOq1TU1EGKWOmrB7ovzTrKl467LttOasoeRdSxNWW4xkrxz6vu2Qt zfFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=6igXVkj/GIu7Wi2vm88OX6UyCiYvCzhrbPpMoFDb3sM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=LwOSFOazApLjj/ybuY/uL7Oev28D6LIXBro5L5ndRNDrNd+rMLLEpNk+YzkDIRZdKK pIC0RzX0YHYyZXMq3vFQI06hPQhh3pbFjQFNhRRmGofKKuGTGNXf3k8Bnp4w2O3bfm8o Hh3JITbv/rv/J7iLb1YY8oU+UQTca4A6p4JdMu0PNMFb0eN0wWnH/3hGbcxD0Uyn22nU w4rPTw4g/KBnRRPSuNU1s1Rvf+BV6ijxzjXmGw0uB+g0md3PrDUVqDsASgcXviLRTC2X +Uy0wxh4gf/g8UeZOXKDKv2HMlUE2CALXJ5YaSMkHtjKHKeTEi1peYtNmfi0WguPEkep LrvQ==; 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=J09qMy+2; 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 38308e7fff4ca-2f9d460c14fsi12294041fa.345.2024.09.28.02.54.39; Sat, 28 Sep 2024 02:54:40 -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=J09qMy+2; 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 03E4468DB62; Sat, 28 Sep 2024 12:54:06 +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 CA02B68DA92 for ; Sat, 28 Sep 2024 12:53:56 +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=J09qMy+2; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DE11B4E18 for ; Sat, 28 Sep 2024 11:53:55 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id oj2LagJp1xWi for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=H9SVrTWi2Ku3ZuSZBU7tXzzTVaE/Pv+cbJv9vkYakxk=; h=From:To:Subject:Date:From; b=J09qMy+2J2DwY2211EH+JlCSNlR524Q6Z11HkXAQWAXwFSTfgS/t5kfmd3TnRSDSr aMGOX8IxJiH7mj0G8U6hM0PjQt4hcEaCZnIbWEcZQJxtWCY3d3o+P1bDpI5kTCpoUF Dr6052AnXgn+rTySlYPdGSSdJShYghWe/Njr0thitO62CF6d8eYfv3RLkhjps5SUCe vDibavlC6rLowZw6cVT2GZvtnio/pVZbxjO4WbEY5sVNyyriVRmrc6jAq+EpCLGhNt BLtF08sJJ0Y8iYqW2j9ioc6h2BNp/WPi1pu/jYlZU4QueLCAEPKhtoTBd2WID8UkqY h3G7TAQJVbRsw== 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 B549D4D9D for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 532403A0229 for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:33 +0200 Message-ID: <20240928095341.15552-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_demux: drop InputStream.[nb_]outputs 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: BnrWe0D/iKfA It is write-only after d119ae2fd82a494d9430ff4d4fc262961a68c598. --- fftools/ffmpeg.h | 8 -------- fftools/ffmpeg_demux.c | 7 ------- 2 files changed, 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b5c95439e5..13e0fd14cd 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -463,14 +463,6 @@ typedef struct InputStream { * currently video and audio only */ InputFilter **filters; int nb_filters; - - /* - * Output targets that do not go through lavfi, i.e. subtitles or - * streamcopy. Those two cases are distinguished by the OutputStream - * having an encoder or not. - */ - struct OutputStream **outputs; - int nb_outputs; } InputStream; typedef struct InputFile { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 13aef15eab..9a3ae67e3a 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -840,7 +840,6 @@ static void ist_free(InputStream **pist) av_dict_free(&ds->decoder_opts); av_freep(&ist->filters); - av_freep(&ist->outputs); av_freep(&ds->dec_opts.hwaccel_device); avcodec_parameters_free(&ist->par); @@ -985,12 +984,6 @@ int ist_output_add(InputStream *ist, OutputStream *ost) if (ret < 0) return ret; - ret = GROW_ARRAY(ist->outputs, ist->nb_outputs); - if (ret < 0) - return ret; - - ist->outputs[ist->nb_outputs - 1] = ost; - return ost->enc ? ds->sch_idx_dec : ds->sch_idx_stream; } From patchwork Sat Sep 28 09:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51900 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp895547vqb; Sat, 28 Sep 2024 02:54:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV1Ecwss1d1Mur+vecEtRDBK5eb2FOqedNAm+nbhcUb17pSbJASh2wbQSa8ToUJa67JiWGL+7IMScKRedguf+BM@gmail.com X-Google-Smtp-Source: AGHT+IHlQ8uuv0jcaNOJvOQgm3l6NvmhSomfR3MZfrNsjbA7LnKFpJOzU69Scct6basAC1szObAE X-Received: by 2002:a05:6512:258b:b0:52f:cdb0:11c0 with SMTP id 2adb3069b0e04-5389fc3afb1mr3801750e87.21.1727517258728; Sat, 28 Sep 2024 02:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517258; cv=none; d=google.com; s=arc-20240605; b=l3Sz1jlQM5yAtVn0O8LpecJ5K+2hLz/WUArNwKY5TdSUbpKiXPlWjwEt15vu0SW8jp w02HdpQrD7uZpjx3ZjDsrdPzAF+UOrhBtxjlSvTd+dlg0ALChC+0iwlHW3T924qo5hho 4NJvpXZog0jIZ8yFO9rzxO8DKh2JHX/lnPQtJh65ef+0enfPeDZ+Ob7RWIrhr6Ik12KZ rNXhYTsbV8SukfjAiz/V2hVeFu8ERKaDrJD/9Z0bfvVyBqo5QEbKeA6ttL1IJC5Gbne1 TXeT2Xf4hWqancZqOYeZdJmQNm5Wxq98s9zQ25VrAzgnJ5ZyT6AImx6/8MO65NW2i40t Gmlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=J2lZABtT7Hd5sLRhEtcJ4vxF58ERgjfPYSgxrguwvzI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=JDrzHcIindTDDOcU9TH58PAaFngrTGCiOdQmdtOucKBT6kNfC6FaLi0udJVMYVbVT6 FkcADWJ8PpluV3Wvtbo5OTPLDvl/u0C+Ajj8Unyw6ghygCWKFs5oaWqdZvNyshRm127K 5fQJETDiu9L1E1MKSL++yXWQxieKWjtoB15u6ocyZlJwnWK9zkKPtcm1NhCk7cTuEN7K MNt0a4vJAQlDMk3vNEu1/TQoJOr+6+YUTQgxp5ERJ4jUi+DQd3FCCxJEggonsyWqac4a dGxlIJGnoby065UOfbarW4hBhuAqZfEaxNnnng4MBKI+6FTZvluVT6fHBbh3eJJPoCSj sbPA==; 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="gc/t/ov7"; 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-538a04623bfsi1304289e87.645.2024.09.28.02.54.18; Sat, 28 Sep 2024 02:54:18 -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="gc/t/ov7"; 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 1D2B168DB90; Sat, 28 Sep 2024 12:54:04 +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 CCF4068DA94 for ; Sat, 28 Sep 2024 12:53:56 +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=gc/t/ov7; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 546A64D9D for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id hWG7hEV0DXO0 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=83QGSTOUdo1x3t0b+2zV8kokdVYmsbi5+DNDGxS8BsA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gc/t/ov7xoNsxioTpQFmhliHQxu8HpyVPml95mMn6Jkjdydh0m5EyhBIfJO8Rze9+ My9dxze+lVvp5bxElmv2RC5KqIglILEaWvsCfeWZuvElIGqSAm3vLncZhxkBtE0bB0 79Gq6kpMk/KaNLxcMO4YvHZAGZnD2uEtkyvc5yUcWwhR+a93nVVV44uJvWJpdBfbch vTeXxGVeSbVg9ZWVpaG0D9FaQ4Oa4ktLGwMKRgGbIIHOep/GzGiQAWLF73wgxHoaQ+ Wqvjly7B1KSuubjPmrGJb8VJL4RKhg8ksDw7ud0OWlwKpOXuiQhThZ6PPy2geYedCv msEp/Nj/o8A/Q== 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 B7D544DE2 for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5FCFB3A086F for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:34 +0200 Message-ID: <20240928095341.15552-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg_demux: drop ist_output_add() 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: FLwLO/j59rRO It is now a trivial wrapper over ist_use(), so export that directly. --- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_demux.c | 17 ++--------------- fftools/ffmpeg_mux_init.c | 17 +++++++++-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 13e0fd14cd..d12b0e0d88 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -870,7 +870,8 @@ int64_t of_filesize(OutputFile *of); int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch); void ifile_close(InputFile **f); -int ist_output_add(InputStream *ist, OutputStream *ost); +int ist_use(InputStream *ist, int decoding_needed, + const ViewSpecifier *vs, SchedulerNode *src); int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, const ViewSpecifier *vs, InputFilterOptions *opts, SchedulerNode *src); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 9a3ae67e3a..364f148f60 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -873,8 +873,8 @@ void ifile_close(InputFile **pf) av_freep(pf); } -static int ist_use(InputStream *ist, int decoding_needed, - const ViewSpecifier *vs, SchedulerNode *src) +int ist_use(InputStream *ist, int decoding_needed, + const ViewSpecifier *vs, SchedulerNode *src) { Demuxer *d = demuxer_from_ifile(ist->file); DemuxStream *ds = ds_from_ist(ist); @@ -974,19 +974,6 @@ static int ist_use(InputStream *ist, int decoding_needed, return 0; } -int ist_output_add(InputStream *ist, OutputStream *ost) -{ - DemuxStream *ds = ds_from_ist(ist); - SchedulerNode src; - int ret; - - ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0, NULL, &src); - if (ret < 0) - return ret; - - return ost->enc ? ds->sch_idx_dec : ds->sch_idx_stream; -} - int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, const ViewSpecifier *vs, InputFilterOptions *opts, SchedulerNode *src) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index ec9f328e90..2541be59da 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1537,18 +1537,19 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ret < 0) goto fail; } else if (ost->ist) { - int sched_idx = ist_output_add(ost->ist, ost); - if (sched_idx < 0) { + SchedulerNode src; + + ret = ist_use(ost->ist, !!ost->enc, NULL, &src); + if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error binding an input stream\n"); - ret = sched_idx; goto fail; } - ms->sch_idx_src = sched_idx; + ms->sch_idx_src = src.idx; if (ost->enc) { - ret = sch_connect(mux->sch, SCH_DEC_OUT(sched_idx, 0), - SCH_ENC(ms->sch_idx_enc)); + ret = sch_connect(mux->sch, + src, SCH_ENC(ms->sch_idx_enc)); if (ret < 0) goto fail; @@ -1557,8 +1558,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ret < 0) goto fail; } else { - ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file->index, sched_idx), - SCH_MSTREAM(ost->file->index, ms->sch_idx)); + ret = sch_connect(mux->sch, + src, SCH_MSTREAM(ost->file->index, ms->sch_idx)); if (ret < 0) goto fail; } From patchwork Sat Sep 28 09:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51905 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp897811vqb; Sat, 28 Sep 2024 03:01:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUjvQ3CIXanpF4UVa9VUe9XuGWVYx43Jm1Y6rbK8II3uPFeKAP9xOyLDjeLVUtHPB2AKx93toZMaHHnx/A4jlDt@gmail.com X-Google-Smtp-Source: AGHT+IF1zv9jjJ2M4wLgb+N5NJYSV//J5wgA92j9ST/7fIZoVQIgCQFxFyM/590EIoZfmUNercMZ X-Received: by 2002:a17:907:748:b0:a7a:b73f:7584 with SMTP id a640c23a62f3a-a93c492a391mr597909866b.34.1727517675875; Sat, 28 Sep 2024 03:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517675; cv=none; d=google.com; s=arc-20240605; b=Bst3vfjUijbMW0BdodyiTxsmuzMjyHfTjDjfNQXCalPEM6mXf1BTmnZMpFX7zAmfml A81ZRkufO3Ye1DAUEB3whgUd04lWo2bgREISW8EFPuRI8htfWI/kSoftHV3t5rO0hjs+ Tw4czQ3g1R80vkj54KJppzmqFsSPRyHX6MUUF8i+TpuHoapz7mxdlPuZNsVEZXCzZiv5 k03Cc2Rc3wd3MAlzjXTVuVV7hR6SP0LDMBCgqxCcNJqjprL7zOAMQ4TwtCDur5FvAYss oWiIghyeg1pBkKa0ZcS2tDs+00wGndAOVpBD8zDWB7aKkpNaxRtb3KKYL9/fWye6tUcA z/OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=IZ1CBzPZBlNVkY7AOPYg0DN35fYo8kenhr8EOMdcFzQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BI1v760w7zXV8lndwJ8i7K91laY1apmSvlyN5AnIMl/7MOHslxajOBnlGd1I699pSk TenYhM3sXSKpoMPH/ic/ED4OILZBMi6UtRbsTFjEt0xfkwVOEI/MHunXUyFry7DPbOjv rHNCt6U/+Ty70eKMSnTtNIJtGINUqIeA5rLQkvwo4CX3RGRW1OS60n0fM0jXmPm7ANU8 zcHIzGjTOmdIBqFsQNVswqASx5MB3a7kgTXDBEpaf9GxYygEzgQxSHbWCWe+voBkMyoo tgshw55eVDqRNJktrN+5z4QYwXr6H6mwfrkj0ElObs/wDOZ9ndm0spPaSAEt8rhbdMhQ bZLQ==; 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=WCIxa6zm; 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 4fb4d7f45d1cf-5c8824b0874si2710066a12.659.2024.09.28.03.01.15; Sat, 28 Sep 2024 03:01:15 -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=WCIxa6zm; 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 5860F68DCA9; Sat, 28 Sep 2024 12:54:11 +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 5AA9B68DA92 for ; Sat, 28 Sep 2024 12:54:02 +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=WCIxa6zm; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id D2FFC4DE2 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 269mIvLFrwZc for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=ImHPlb5RzOEwt+Emwl1+cdgpNuT5MrpuEqtXQWoqDu4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WCIxa6zmKYibVEmo40ODiJPE2VYrb0KSWezzpjsYagrTjHiZjpbTZIVKaPPWO5eEV ljIDJFDqh67MdikkVpM4zgRkGLO4+7oZYOMCwkcD2A8dpkV+kmYt/9ULk7sfsVHaG+ XvaMKRFHauUBt1Dau/ruYvlRs0GCWlQtrqKp9HyXBzlBdyGo8ZT5YRbONBESP7jtOq pnSbPvs4lbAYTqxgyCaR0nW7Z8hBUYrUTE5HfGlfosmW1K+172llEZ1b3LipTZyVZo B4zp2IuoYbJ7bnIXMmqbvppAHsvchjt7XfnAhxf4XQQAMfZiOk/FV68WyntdupogsN Oke4qLokhGdeA== 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 BA4A44DE6 for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6B1453A0998 for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:35 +0200 Message-ID: <20240928095341.15552-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg_enc: split Encoder into a private and public part 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: yoRnAj7b7TAN Similar to what was previously done for other components, e.g. decoders (see 3b84140a1bb5a5b3044915888a40a7b619921633). Start by moving {samples,frames}_encoded into the public struct. --- fftools/ffmpeg.h | 11 +++--- fftools/ffmpeg_enc.c | 86 +++++++++++++++++++++++++------------------- fftools/ffmpeg_mux.c | 4 +-- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d12b0e0d88..9aeb217e73 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -569,7 +569,13 @@ typedef struct KeyframeForceCtx { int dropped_keyframe; } KeyframeForceCtx; -typedef struct Encoder Encoder; +typedef struct Encoder { + const AVClass *class; + + // number of frames/samples sent to the encoder + uint64_t frames_encoded; + uint64_t samples_encoded; +} Encoder; enum CroppingType { CROP_DISABLED = 0, @@ -621,9 +627,6 @@ typedef struct OutputStream { /* stats */ // number of packets send to the muxer atomic_uint_least64_t packets_written; - // number of frames/samples sent to the encoder - uint64_t frames_encoded; - uint64_t samples_encoded; /* packet quality factor */ atomic_int quality; diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 4b3efb8db1..c8623ed343 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -38,8 +38,9 @@ #include "libavcodec/avcodec.h" -struct Encoder { - const AVClass *class; +typedef struct EncoderPriv { + Encoder e; + void *log_parent; char log_name[32]; @@ -54,7 +55,12 @@ struct Encoder { Scheduler *sch; unsigned sch_idx; -}; +} EncoderPriv; + +static EncoderPriv *ep_from_enc(Encoder *enc) +{ + return (EncoderPriv*)enc; +} // data that is local to the decoder thread and not visible outside of it typedef struct EncoderThread { @@ -74,38 +80,38 @@ void enc_free(Encoder **penc) static const char *enc_item_name(void *obj) { - const Encoder *e = obj; + const EncoderPriv *ep = obj; - return e->log_name; + return ep->log_name; } static const AVClass enc_class = { .class_name = "Encoder", .version = LIBAVUTIL_VERSION_INT, - .parent_log_context_offset = offsetof(Encoder, log_parent), + .parent_log_context_offset = offsetof(EncoderPriv, log_parent), .item_name = enc_item_name, }; int enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx, void *log_parent) { - Encoder *enc; + EncoderPriv *ep; *penc = NULL; - enc = av_mallocz(sizeof(*enc)); - if (!enc) + ep = av_mallocz(sizeof(*ep)); + if (!ep) return AVERROR(ENOMEM); - enc->class = &enc_class; - enc->log_parent = log_parent; + ep->e.class = &enc_class; + ep->log_parent = log_parent; - enc->sch = sch; - enc->sch_idx = sch_idx; + ep->sch = sch; + ep->sch_idx = sch_idx; - snprintf(enc->log_name, sizeof(enc->log_name), "enc:%s", codec->name); + snprintf(ep->log_name, sizeof(ep->log_name), "enc:%s", codec->name); - *penc = enc; + *penc = &ep->e; return 0; } @@ -166,6 +172,7 @@ int enc_open(void *opaque, const AVFrame *frame) OutputStream *ost = opaque; InputStream *ist = ost->ist; Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); AVCodecContext *enc_ctx = ost->enc_ctx; Decoder *dec = NULL; const AVCodec *enc = enc_ctx->codec; @@ -174,7 +181,7 @@ int enc_open(void *opaque, const AVFrame *frame) int frame_samples = 0; int ret; - if (e->opened) + if (ep->opened) return 0; // frame is always non-NULL for audio and video @@ -320,7 +327,7 @@ int enc_open(void *opaque, const AVFrame *frame) return ret; } - e->opened = 1; + ep->opened = 1; if (enc_ctx->frame_size) frame_samples = enc_ctx->frame_size; @@ -352,6 +359,7 @@ static int do_subtitle_out(OutputFile *of, OutputStream *ost, const AVSubtitle * AVPacket *pkt) { Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i, ret; AVCodecContext *enc; @@ -403,7 +411,7 @@ static int do_subtitle_out(OutputFile *of, OutputStream *ost, const AVSubtitle * local_sub.rects += i; } - ost->frames_encoded++; + e->frames_encoded++; subtitle_out_size = avcodec_encode_subtitle(enc, pkt->data, pkt->size, &local_sub); if (subtitle_out_size < 0) { @@ -425,7 +433,7 @@ static int do_subtitle_out(OutputFile *of, OutputStream *ost, const AVSubtitle * } pkt->dts = pkt->pts; - ret = sch_enc_send(e->sch, e->sch_idx, pkt); + ret = sch_enc_send(ep->sch, ep->sch_idx, pkt); if (ret < 0) { av_packet_unref(pkt); return ret; @@ -440,6 +448,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, uint64_t frame_num) { Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); AVIOContext *io = es->io; AVRational tb = frame ? frame->time_base : pkt->time_base; int64_t pts = frame ? frame->pts : pkt->pts; @@ -477,7 +486,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, if (frame) { switch (c->type) { - case ENC_STATS_SAMPLE_NUM: avio_printf(io, "%"PRIu64, ost->samples_encoded); continue; + case ENC_STATS_SAMPLE_NUM: avio_printf(io, "%"PRIu64, e->samples_encoded); continue; case ENC_STATS_NB_SAMPLES: avio_printf(io, "%d", frame->nb_samples); continue; default: av_assert0(0); } @@ -495,7 +504,7 @@ void enc_stats_write(OutputStream *ost, EncStats *es, } case ENC_STATS_AVG_BITRATE: { double duration = pkt->dts * av_q2d(tb); - avio_printf(io, "%g", duration > 0 ? 8.0 * e->data_size / duration : -1.); + avio_printf(io, "%g", duration > 0 ? 8.0 * ep->data_size / duration : -1.); continue; } default: av_assert0(0); @@ -515,7 +524,7 @@ static inline double psnr(double d) static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { - Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(ost->enc); const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, NULL); AVCodecContext *enc = ost->enc_ctx; @@ -549,7 +558,7 @@ static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_ } } - frame_number = e->packets_encoded; + frame_number = ep->packets_encoded; if (vstats_version <= 1) { fprintf(vstats_file, "frame= %5"PRId64" q= %2.1f ", frame_number, quality / (float)FF_QP2LAMBDA); @@ -569,9 +578,9 @@ static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_ ti1 = 0.01; bitrate = (pkt->size * 8) / av_q2d(enc->time_base) / 1000.0; - avg_bitrate = (double)(e->data_size * 8) / ti1 / 1000.0; + avg_bitrate = (double)(ep->data_size * 8) / ti1 / 1000.0; fprintf(vstats_file, "s_size= %8.0fKiB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", - (double)e->data_size / 1024, ti1, bitrate, avg_bitrate); + (double)ep->data_size / 1024, ti1, bitrate, avg_bitrate); fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(pict_type)); return 0; @@ -581,6 +590,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt) { Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); AVCodecContext *enc = ost->enc_ctx; const char *type_desc = av_get_media_type_string(enc->codec_type); const char *action = frame ? "encode" : "flush"; @@ -596,10 +606,10 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, if (ost->enc_stats_pre.io) enc_stats_write(ost, &ost->enc_stats_pre, frame, NULL, - ost->frames_encoded); + e->frames_encoded); - ost->frames_encoded++; - ost->samples_encoded += frame->nb_samples; + e->frames_encoded++; + e->samples_encoded += frame->nb_samples; if (debug_ts) { av_log(e, AV_LOG_INFO, "encoder <- type:%s " @@ -653,7 +663,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, // attach stream parameters to first packet if requested avcodec_parameters_free(&fd->par_enc); - if (e->attach_par && !e->packets_encoded) { + if (ep->attach_par && !ep->packets_encoded) { fd->par_enc = avcodec_parameters_alloc(); if (!fd->par_enc) return AVERROR(ENOMEM); @@ -673,7 +683,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, if (ost->enc_stats_post.io) enc_stats_write(ost, &ost->enc_stats_post, NULL, pkt, - e->packets_encoded); + ep->packets_encoded); if (debug_ts) { av_log(e, AV_LOG_INFO, "encoder -> type:%s " @@ -685,11 +695,11 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); } - e->data_size += pkt->size; + ep->data_size += pkt->size; - e->packets_encoded++; + ep->packets_encoded++; - ret = sch_enc_send(e->sch, e->sch_idx, pkt); + ret = sch_enc_send(ep->sch, ep->sch_idx, pkt); if (ret < 0) { av_packet_unref(pkt); return ret; @@ -826,6 +836,7 @@ int encoder_thread(void *arg) { OutputStream *ost = arg; Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); EncoderThread et; int ret = 0, input_status = 0; int name_set = 0; @@ -848,11 +859,11 @@ int encoder_thread(void *arg) } while (!input_status) { - input_status = sch_enc_receive(e->sch, e->sch_idx, et.frame); + input_status = sch_enc_receive(ep->sch, ep->sch_idx, et.frame); if (input_status < 0) { if (input_status == AVERROR_EOF) { av_log(e, AV_LOG_VERBOSE, "Encoder thread received EOF\n"); - if (e->opened) + if (ep->opened) break; av_log(e, AV_LOG_ERROR, "Could not open encoder before EOF\n"); @@ -905,6 +916,7 @@ finish: int enc_loopback(Encoder *enc) { - enc->attach_par = 1; - return enc->sch_idx; + EncoderPriv *ep = ep_from_enc(enc); + ep->attach_par = 1; + return ep->sch_idx; } diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index d38f1ec317..1980e3287c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -723,9 +723,9 @@ static void mux_final_stats(Muxer *mux) of->index, j, av_get_media_type_string(type)); if (ost->enc) { av_log(of, AV_LOG_VERBOSE, "%"PRIu64" frames encoded", - ost->frames_encoded); + ost->enc->frames_encoded); if (type == AVMEDIA_TYPE_AUDIO) - av_log(of, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded); + av_log(of, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->enc->samples_encoded); av_log(of, AV_LOG_VERBOSE, "; "); } From patchwork Sat Sep 28 09:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51899 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp895500vqb; Sat, 28 Sep 2024 02:54:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUSE/h7gJSfwG/7VpIspEF8Vs1W32ZHB0gW2cZ4QLqA8ml/2ONAwA8+T6lFvaemI0TgMjUcqtgICPAK1Q0Aq46G@gmail.com X-Google-Smtp-Source: AGHT+IFZrbTfZJE+wcSxG50PivjHlEhgidIil64LiMY1f3/dh4C+VTK6bNx02zJVGKsdd3zRBMAK X-Received: by 2002:a2e:4e19:0:b0:2f7:631a:6e0d with SMTP id 38308e7fff4ca-2f9d3e478a3mr28745541fa.12.1727517247774; Sat, 28 Sep 2024 02:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517247; cv=none; d=google.com; s=arc-20240605; b=OonGbt1AaSIdkynw3ek/EvswKOG2TnHsalJAmFi37iSZxLsgK0irbARSthkN+rUMRW hv2mtJq9qj7XmkWCZr5KZ7s8agpJcRRjE8yO1H5i4322kxm6IfXOBz/5srZReYBDZ0ZN 80/01JcXMBSGVii5gzw4Vs13NG/WQXV0a2gJGXF536x8c0uLW0cG9lnGzip86YJ1SQNe WHuTSlDDHMdpwBxN1prCqhp6Vtwv3xqJ26+SLs4lF+GA9sVxJo7nHqlcQu5niRV2yEf4 Tdx6YfmuXY0eq6Vr3CT7/MumN+ZTF6FX8znUHnjVgUuVhBAHsWz3iKEwcZFKDMg1pf1p qurA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=ONQSvGrdZDOcQbXpmKZx6YMLQdg4m0fgU2RbipZlhuw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=GR22C9opYwN59BMLAYOccUq9lzgLSkqH40bzCsHImii4h4XxiXA7zDOrBwSJ90RtJe 1sLlJfbyPKBbTV7IIoFqY7Gjr1f9tU+H33RsJ7qdLAb3lnQkhV+8aN3bwXhF3iXfLgAp Vv4YcN8hOogcFzxJ4LvPdl5/MxxSEc9cIV7WGbOOnx/izuEKd6IxVJ1bR5zfosNHVsC4 9fGqoP+4tpNZVReMEgWydjZbxlVxP2O5oI8pRh5ARaWDlSO+RnKLbxAaqXz3vKnRRSUS XiM2gzIQuZ+XQ+7Rjd1+arcfWVY+RqpkRWyWxdb9mYnMFvv1MlcwZZQQbSrNqi1QYeLq 5GKg==; 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=sCG+JnwQ; 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 38308e7fff4ca-2f9d460306bsi11833471fa.290.2024.09.28.02.54.07; Sat, 28 Sep 2024 02:54:07 -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=sCG+JnwQ; 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 D910868DA92; Sat, 28 Sep 2024 12:54:02 +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 C644468D72C for ; Sat, 28 Sep 2024 12:53:56 +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=sCG+JnwQ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E8C864E1A for ; Sat, 28 Sep 2024 11:53:55 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Ou6jTKvySvZL for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=PC/P3hHGaKHXgoOlZ6JK5rQdBedojE84G9KrOP2EZ1c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sCG+JnwQrrh6IM17x9sUASY5NLZkdMNhRWWDHhcTo8WqQbSxPeZQH036PRG2SCfJ6 8EinXVaTtWNwWeGRXDRD/tActYsuyd0e/4pSiVwkkt6Ed/0Jcc/yfJ2VFAFZXxk+XX pSTL/M9a1fXkIyO1xP8iJJ7tmq87sdebzZwK58FwjPMMzXIw9GJv9oOk86eEVvZdZ3 sq6LyGpJcfys/X0wei1il8hXEhdiLLYj5pDn4pzL+zngIGw4/j/PUMgW8lumwkreDP IB/lowsbYJ3g4EB4OA9F//AW5sk/iNhN0neg2g+kW/FIHoFfdqbbm7U8mDqs2bjAFo F9umug5zZbb+w== 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 BBCFE4DEE for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 76FA63A0F02 for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:36 +0200 Message-ID: <20240928095341.15552-4-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/9] fftools/ffmpeg_mux: move OutputStream.enc_ctx to Encoder 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: 9gF3wHvWII4i The encoding AVCodecContext is a part of the encoder, and so should live there. --- fftools/ffmpeg.c | 6 ++-- fftools/ffmpeg.h | 3 +- fftools/ffmpeg_enc.c | 33 ++++++++++++++------ fftools/ffmpeg_mux.c | 8 ++--- fftools/ffmpeg_mux_init.c | 66 ++++++++++++++++++--------------------- 5 files changed, 62 insertions(+), 54 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 420ba3c6e4..dc321fb4a2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -728,7 +728,7 @@ static void print_stream_maps(void) av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index); av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\n", ost->file->index, - ost->index, ost->enc_ctx->codec->name); + ost->index, ost->enc->enc_ctx->codec->name); continue; } @@ -737,9 +737,9 @@ static void print_stream_maps(void) ost->ist->index, ost->file->index, ost->index); - if (ost->enc_ctx) { + if (ost->enc) { const AVCodec *in_codec = ost->ist->dec; - const AVCodec *out_codec = ost->enc_ctx->codec; + const AVCodec *out_codec = ost->enc->enc_ctx->codec; const char *decoder_name = "?"; const char *in_codec_name = "?"; const char *encoder_name = "?"; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9aeb217e73..c796de19f5 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -572,6 +572,8 @@ typedef struct KeyframeForceCtx { typedef struct Encoder { const AVClass *class; + AVCodecContext *enc_ctx; + // number of frames/samples sent to the encoder uint64_t frames_encoded; uint64_t samples_encoded; @@ -602,7 +604,6 @@ typedef struct OutputStream { AVStream *st; /* stream in the output file */ Encoder *enc; - AVCodecContext *enc_ctx; /* video only */ #if FFMPEG_OPT_TOP diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index c8623ed343..a46af4dce1 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -75,6 +75,10 @@ void enc_free(Encoder **penc) if (!enc) return; + if (enc->enc_ctx) + av_freep(&enc->enc_ctx->stats_in); + avcodec_free_context(&enc->enc_ctx); + av_freep(penc); } @@ -96,6 +100,7 @@ int enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx, void *log_parent) { EncoderPriv *ep; + int ret = 0; *penc = NULL; @@ -111,9 +116,18 @@ int enc_alloc(Encoder **penc, const AVCodec *codec, snprintf(ep->log_name, sizeof(ep->log_name), "enc:%s", codec->name); + ep->e.enc_ctx = avcodec_alloc_context3(codec); + if (!ep->e.enc_ctx) { + ret = AVERROR(ENOMEM); + goto fail; + } + *penc = &ep->e; return 0; +fail: + enc_free((Encoder**)&ep); + return ret; } static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx, @@ -173,7 +187,7 @@ int enc_open(void *opaque, const AVFrame *frame) InputStream *ist = ost->ist; Encoder *e = ost->enc; EncoderPriv *ep = ep_from_enc(e); - AVCodecContext *enc_ctx = ost->enc_ctx; + AVCodecContext *enc_ctx = e->enc_ctx; Decoder *dec = NULL; const AVCodec *enc = enc_ctx->codec; OutputFile *of = ost->file; @@ -372,7 +386,7 @@ static int do_subtitle_out(OutputFile *of, OutputStream *ost, const AVSubtitle * if ((of->start_time != AV_NOPTS_VALUE && sub->pts < of->start_time)) return 0; - enc = ost->enc_ctx; + enc = e->enc_ctx; /* Note: DVB subtitle need one packet to draw them and one other packet to clear them */ @@ -524,10 +538,11 @@ static inline double psnr(double d) static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { - EncoderPriv *ep = ep_from_enc(ost->enc); + Encoder *e = ost->enc; + EncoderPriv *ep = ep_from_enc(e); const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, NULL); - AVCodecContext *enc = ost->enc_ctx; + AVCodecContext *enc = e->enc_ctx; enum AVPictureType pict_type; int64_t frame_number; double ti1, bitrate, avg_bitrate; @@ -591,7 +606,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, { Encoder *e = ost->enc; EncoderPriv *ep = ep_from_enc(e); - AVCodecContext *enc = ost->enc_ctx; + AVCodecContext *enc = e->enc_ctx; const char *type_desc = av_get_media_type_string(enc->codec_type); const char *action = frame ? "encode" : "flush"; int ret; @@ -775,7 +790,7 @@ static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) return AVERROR_EOF; if (type == AVMEDIA_TYPE_VIDEO) { - frame->quality = ost->enc_ctx->global_quality; + frame->quality = e->enc_ctx->global_quality; frame->pict_type = forced_kf_apply(e, &ost->kf, frame); #if FFMPEG_OPT_TOP @@ -785,8 +800,8 @@ static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) } #endif } else { - if (!(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - ost->enc_ctx->ch_layout.nb_channels != frame->ch_layout.nb_channels) { + if (!(e->enc_ctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && + e->enc_ctx->ch_layout.nb_channels != frame->ch_layout.nb_channels) { av_log(e, AV_LOG_ERROR, "Audio channel count changed and encoder does not support parameter changes\n"); return 0; @@ -801,7 +816,7 @@ static void enc_thread_set_name(const OutputStream *ost) { char name[16]; snprintf(name, sizeof(name), "enc%d:%d:%s", ost->file->index, ost->index, - ost->enc_ctx->codec->name); + ost->enc->enc_ctx->codec->name); ff_thread_setname(name); } diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 1980e3287c..25f66dd185 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -661,8 +661,8 @@ static int check_written(OutputFile *of) total_packets_written += packets_written; - if (ost->enc_ctx && - (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) + if (ost->enc && + (ost->enc->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) != AV_CODEC_FLAG_PASS1) pass1_used = 0; @@ -837,10 +837,6 @@ static void ost_free(OutputStream **post) av_freep(&ost->attachment_filename); - if (ost->enc_ctx) - av_freep(&ost->enc_ctx->stats_in); - avcodec_free_context(&ost->enc_ctx); - enc_stats_uninit(&ost->enc_stats_pre); enc_stats_uninit(&ost->enc_stats_post); enc_stats_uninit(&ms->stats); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 2541be59da..033fa6aba8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -555,7 +555,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) return AV_PIX_FMT_NONE; } - ret = avcodec_get_supported_config(ost->enc_ctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT, + ret = avcodec_get_supported_config(ost->enc->enc_ctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void **) &fmts, NULL); if (ret < 0) return AV_PIX_FMT_NONE; @@ -587,7 +587,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) } if (fmts && !fmt_in_list(fmts, fmt)) - fmt = choose_pixel_fmt(ost->enc_ctx, fmt); + fmt = choose_pixel_fmt(ost->enc->enc_ctx, fmt); return fmt; } @@ -632,8 +632,8 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, ost->frame_aspect_ratio = q; } - if (ost->enc_ctx) { - AVCodecContext *video_enc = ost->enc_ctx; + if (ost->enc) { + AVCodecContext *video_enc = ost->enc->enc_ctx; const char *p = NULL, *fps_mode = NULL; const char *frame_size = NULL; const char *frame_pix_fmt = NULL; @@ -746,10 +746,10 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, ost->logfile_prefix ? ost->logfile_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, ost_idx); - if (!strcmp(ost->enc_ctx->codec->name, "libx264") || !strcmp(ost->enc_ctx->codec->name, "libvvenc")) { - if (av_opt_is_set_to_default_by_name(ost->enc_ctx, "stats", + if (!strcmp(video_enc->codec->name, "libx264") || !strcmp(video_enc->codec->name, "libvvenc")) { + if (av_opt_is_set_to_default_by_name(video_enc, "stats", AV_OPT_SEARCH_CHILDREN) > 0) - av_opt_set(ost->enc_ctx, "stats", logfilename, + av_opt_set(video_enc, "stats", logfilename, AV_OPT_SEARCH_CHILDREN); } else { if (video_enc->flags & AV_CODEC_FLAG_PASS2) { @@ -842,8 +842,8 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, AVFormatContext *oc = mux->fc; AVStream *st = ost->st; - if (ost->enc_ctx) { - AVCodecContext *audio_enc = ost->enc_ctx; + if (ost->enc) { + AVCodecContext *audio_enc = ost->enc->enc_ctx; int channels = 0; const char *layout = NULL; const char *sample_fmt = NULL; @@ -881,8 +881,8 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, st = ost->st; - if (ost->enc_ctx) { - AVCodecContext *subtitle_enc = ost->enc_ctx; + if (ost->enc) { + AVCodecContext *subtitle_enc = ost->enc->enc_ctx; AVCodecDescriptor const *input_descriptor = avcodec_descriptor_get(ost->ist->par->codec_id); @@ -923,7 +923,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, const ViewSpecifier *vs) { OutputStream *ost = &ms->ost; - AVCodecContext *enc_ctx = ost->enc_ctx; + AVCodecContext *enc_ctx = ost->enc->enc_ctx; char name[16]; int ret; @@ -1245,10 +1245,6 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, } if (enc) { - ost->enc_ctx = avcodec_alloc_context3(enc); - if (!ost->enc_ctx) - return AVERROR(ENOMEM); - ret = sch_add_enc(mux->sch, encoder_thread, ost, ost->type == AVMEDIA_TYPE_SUBTITLE ? NULL : enc_open); if (ret < 0) @@ -1290,21 +1286,21 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (!ms->pkt) return AVERROR(ENOMEM); - if (ost->enc_ctx) { + if (ost->enc) { AVIOContext *s = NULL; char *buf = NULL, *arg = NULL; const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL; const char *enc_time_base = NULL, *preset = NULL; - ret = filter_codec_opts(o->g->codec_opts, ost->enc_ctx->codec_id, - oc, st, ost->enc_ctx->codec, &encoder_opts, + ret = filter_codec_opts(o->g->codec_opts, enc->id, + oc, st, enc, &encoder_opts, &mux->enc_opts_used); if (ret < 0) goto fail; opt_match_per_stream_str(ost, &o->presets, oc, st, &preset); opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale); - if (preset && (!(ret = get_preset_file_2(preset, ost->enc_ctx->codec->name, &s)))) { + if (preset && (!(ret = get_preset_file_2(preset, enc->name, &s)))) { AVBPrint bprint; av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); do { @@ -1404,7 +1400,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, threads_manual = !!av_dict_get(encoder_opts, "threads", NULL, 0); - ret = av_opt_set_dict2(ost->enc_ctx, &encoder_opts, AV_OPT_SEARCH_CHILDREN); + ret = av_opt_set_dict2(ost->enc->enc_ctx, &encoder_opts, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error applying encoder options: %s\n", av_err2str(ret)); @@ -1417,7 +1413,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, // default to automatic thread count if (!threads_manual) - ost->enc_ctx->thread_count = 0; + ost->enc->enc_ctx->thread_count = 0; } else { ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL, &encoder_opts, @@ -1429,8 +1425,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (o->bitexact) { ost->bitexact = 1; - } else if (ost->enc_ctx) { - ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT); + } else if (ost->enc) { + ost->bitexact = !!(ost->enc->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT); } if (enc) { @@ -1482,14 +1478,14 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, } ost->st->codecpar->codec_tag = tag; ms->par_in->codec_tag = tag; - if (ost->enc_ctx) - ost->enc_ctx->codec_tag = tag; + if (ost->enc) + ost->enc->enc_ctx->codec_tag = tag; } opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale); - if (ost->enc_ctx && qscale >= 0) { - ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE; - ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; + if (ost->enc && qscale >= 0) { + ost->enc->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE; + ost->enc->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } if (ms->sch_idx >= 0) { @@ -1511,8 +1507,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat, oc, st, &ost->fix_sub_duration_heartbeat); - if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) - ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc) + ost->enc->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes, oc, st, &ms->copy_initial_nonkeyframes); @@ -2047,7 +2043,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int limit_frames = 0, limit_frames_av_enc = 0; #define IS_AV_ENC(ost, type) \ - (ost->enc_ctx && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) + (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) #define IS_INTERLEAVED(type) (type != AVMEDIA_TYPE_ATTACHMENT) for (int i = 0; i < oc->nb_streams; i++) { @@ -2059,8 +2055,8 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, nb_interleaved += IS_INTERLEAVED(type); nb_av_enc += IS_AV_ENC(ost, type); - nb_audio_fs += (ost->enc_ctx && type == AVMEDIA_TYPE_AUDIO && - !(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)); + nb_audio_fs += (ost->enc && type == AVMEDIA_TYPE_AUDIO && + !(ost->enc->enc_ctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)); limit_frames |= ms->max_frames < INT64_MAX; limit_frames_av_enc |= (ms->max_frames < INT64_MAX) && IS_AV_ENC(ost, type); @@ -3193,7 +3189,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) mux->fc, ost->st, &forced_keyframes); if (!(ost->type == AVMEDIA_TYPE_VIDEO && - ost->enc_ctx && forced_keyframes)) + ost->enc && forced_keyframes)) continue; if (!strncmp(forced_keyframes, "expr:", 5)) { From patchwork Sat Sep 28 09:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51902 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp895746vqb; Sat, 28 Sep 2024 02:55:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXQ/u78umSd4U3uBaO8vXnxND2xHbVqlOp6ef/LU2DSGzK1KJGMF5R3fUXnnNVHvo1k/IC83ZKv5recAbRziDOP@gmail.com X-Google-Smtp-Source: AGHT+IEkJri7O4fkz6J8RysaYqBkuZj59mASyHZoG0G9fbzRdKMc04b26BHfQnldHrS2YWV5Pk/q X-Received: by 2002:a05:6402:1d48:b0:5c8:784e:149c with SMTP id 4fb4d7f45d1cf-5c882607903mr5250789a12.31.1727517299999; Sat, 28 Sep 2024 02:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517299; cv=none; d=google.com; s=arc-20240605; b=LHlMoMgLED+HlOJ6Frwv+o+gB9GuRY4/wIb54iCpH8wCQkHJLkjKszTu+MndTl0KEK iqCQklwbi8ZYEjtXWpgW6O8YCEFUHhh5AJ6QtLYrIvbdrtRBAkzWMGgzk00oZSHP72xP PY156ZeItjn8ZYdpK64GXTkf1sYE02BGU/Pf05s7iBjPgXjXzsOXTXC/uqKZGME6LKCS CvmlvXS3MBfJD0eU2BdABiDoZxKhlFp1iZ/xHMXXOjMZTqpFBnqrSBHz6huHL5PHc7dS Jor99tm2i8zfKpUR+CLZP2Rl9lfJ+9N59o45Dihep52GqUbrpbCYNU1BWvzNIka8gL6W Qb+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=yTPHAZpkM+IiHxl72h6L/iOoLlBAtHEVnqAV7tzOIRk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Pr8WiRfyeZwU8fewsEalyY+QiHzt/9qt0STnX8J08R0iByh4Uq2lQ9UFKqYyyf0150 vuIBJABIy++ZDN2wrGE9LmZJLStQENAdxci8UO0p+3Cbpi+iF3QO16NJwKsMEdcrfwOg KKIqfZKBh8bG+wyCCQhDnXlEQ0kbu6nKs3W5dleBHUDh5qhACrZaj4tx7nd4nvDYxM3C aikXkida5uF4Suj/N0PFqpjk2Trqvh2O8KwOtYI8sjC/r+8yyyuvRyC88LXUFZlMgTph VqysldaC9s9Glm7lkl0NXcEZTJr9OKzQ0kFDV4njxTJwcOHjQd5YrHlNC+AOaBjfV7aD Iqmw==; 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=iNihUgBC; 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 4fb4d7f45d1cf-5c88248fdb8si2699711a12.226.2024.09.28.02.54.59; Sat, 28 Sep 2024 02:54:59 -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=iNihUgBC; 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 DE71D68DB09; Sat, 28 Sep 2024 12:54:07 +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 1017D68DA94 for ; Sat, 28 Sep 2024 12:53:57 +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=iNihUgBC; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 9943E4E16 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 8VHIPiCtvAPv for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=YFRPAnjhCsiqzxVenLTDUeEUj/BZ3DYR3o3jp/78uLY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iNihUgBCdn3yifP6452U4jHRH0KLzAhwYK7oW9+p91qrNY9bOl4RljBxKH26lWkLr FvXm6Hj142Navg90ccUwyM80mPtlKQz3wTuzlzIkEI5pwbcSF/t4EuZFvgxTox2u3T kOhJrRFP6TCZtTjpU01r8U67YIyjqwcvV665XR7Qs3aUalnRCaAUhY8ZCw5EPDv6PB MeGXHvjjFtVn6zOTF7o/r9GoiTH9Oh/qHUFNwC0c4zLhVjEcnPSvXTt4/tl3spmu6D r+ATPv8W/utRuvtSRcY9BaaSmcU41puvcu3B/9PWLlYoRVjlnGxdyAvbD01Pf2dhaB gyoDE4f1VzzCA== 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 C3D214DF6 for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8E35E3A0F6F for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:38 +0200 Message-ID: <20240928095341.15552-6-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg_mux_init: do not export forced_keyframes_const_names[] 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: K1PAawMz6hTu It is only used in this file. --- fftools/ffmpeg.h | 2 -- fftools/ffmpeg_mux_init.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 0f5809b752..9439be0f41 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -539,8 +539,6 @@ typedef struct EncStats { int lock_initialized; } EncStats; -extern const char *const forced_keyframes_const_names[]; - enum { KF_FORCE_SOURCE = 1, #if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 033fa6aba8..117b1a4338 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -3087,7 +3087,7 @@ finish: return ret; } -const char *const forced_keyframes_const_names[] = { +static const char *const forced_keyframes_const_names[] = { "n", "n_forced", "prev_forced_n", From patchwork Sat Sep 28 09:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51906 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp897894vqb; Sat, 28 Sep 2024 03:01:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX/ZP7iOAZEnP65QhQWJwGVsaAGAbr1d0PVcII4GzghmG4M0bxTt5oAQMXAqibfIt1Pwjh1ZtAlNpmgTPcD/FWt@gmail.com X-Google-Smtp-Source: AGHT+IFA7zLl97aRVNxcgnMXSfBpkD70+apWAiHkvUlxctq2hKr8CHVDBp+JkTfvu2R2OKumOyc7 X-Received: by 2002:a05:651c:198c:b0:2f7:7c97:22b0 with SMTP id 38308e7fff4ca-2f9c6c58239mr37055851fa.4.1727517684372; Sat, 28 Sep 2024 03:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517684; cv=none; d=google.com; s=arc-20240605; b=cezb5y9dF6h3iSoA6StkerskaU4M4x/YAfqtPtuIufgABIfGHrhxYPuMTkeRjELqvn 9WB6l3u/iF0+mrFvpnGlL3JbCFj+n1NltSdqLyTHZaufIbbXcSWmFlqbaops9ow/n1QF ldbJ4LjdISAe9cm0MnaR+xgkequ6PrrIBe7Nn4ISJx7z0F1t/oJJ5W8wXdbWRyA2EdL9 UyiQtEJx9wRoeCGxp3hoq6fjieherBHumBSMbdFctCj045QufY5GO46m1bFkDM/BmPQD ZiFGod84eRLT9J/bCYfbqRHiX3akApOZtBIvtQa6Ko3NMh3PFwvDmG7ZZKI7CAHx5FgZ WAZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=1kAtPixJGk0fV1ewnV0YoznqRH6Ctde1ubvvpwC639Q=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Oiu2OZw1zDPNlqV8/elyMhZlT2ZKym+l4Psyj6K4YSuHPvvh6ZXqmxEKKlF8F/WLmu kojGLuKtvrqe8VUpvv73odWg71OH7Gqo+OEfK8oWcWheh2qDYMRzRL+DAs5nZnuELhX8 Yk3DBJ6MINbghFxJmOXFyB/TgTMDflBzneIVMhgvPLEk9wPqdjjf2ppPorT3aO+Lc79X DyYFFVdx2XjeDjVBP2NT7Q4rj9QbOCDJCUt8PbWIBeJqPqVd43nESsOTyZ3q+sps48kv ILVmdRVu4EsW3xNTZ5LbCtkJ70s1MRovtMrbih0l29rM857LEnZjKQ0Von5V9MLgDrEy /aAA==; 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=nQA+gBib; 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 38308e7fff4ca-2f9d4649a32si12317311fa.558.2024.09.28.03.01.23; Sat, 28 Sep 2024 03:01:24 -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=nQA+gBib; 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 E4B9968DC56; Sat, 28 Sep 2024 12:54:06 +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 5AAEC68DB31 for ; Sat, 28 Sep 2024 12:54:02 +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=nQA+gBib; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 2FEC44DF6 for ; Sat, 28 Sep 2024 11:53:57 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id FYUSbpQbPBI1 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=T6Sk6HHbhBUqmQloPKltj49LQCeQN6xVSZVarsY2dIc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nQA+gBibu6Uqpovj9zj4Lfb9P8VvmcHujUsgKZVPf7g/+4Sc6KYfSt5me1NV06DEn csKePBkcxVk2tzfG9FUURRhi9M7V2gii4227DXqg55hZn3S1BvLheBAWf3WVUrLHoS W3WTmjtjx5BsL3XjHfHUKzrkSdFJyS6gIC/EmHbXKMsbYFbjVfueFBOGP+tnhe7vzl IL20UMiA2jQsyBzMfXsATBWoYblc26xDLnMQaTj+hUh3vYpnE6xdjKh2s1TeNR+lBz ZbxX7wSDP+/mAPGKSsagEFv5HIyCSzlJRiM4JlzkZ2hftmcAIJuzn1wB3kEUA+wC3r FKf2qiS8+Cq4g== 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 CC6534E0B for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 999F33A164C for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:39 +0200 Message-ID: <20240928095341.15552-7-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/9] fftools/ffmpeg_mux_init: move the check for filtering+streamcopy 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: /lNSThoijfDe To streamcopy_init(). This will allow to simplify the control flow in ost_add() by moving the ost_get_filters() call (which previously had to handle both encoding and streamcopy streams) to ost_bind_filter() (which is only called for audio/video encoding). Also, return EINVAL rather than ENOSYS, as trying to combine filtering with streamcopy is a parameter error. --- fftools/ffmpeg_mux_init.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 117b1a4338..1ddd1d7492 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -424,27 +424,6 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, #endif opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters); - if (!ost->enc) { - if ( -#if FFMPEG_OPT_FILTER_SCRIPT - filters_script || -#endif - filters) { - av_log(ost, AV_LOG_ERROR, - "%s '%s' was specified, but codec copy was selected. " - "Filtering and streamcopy cannot be used together.\n", -#if FFMPEG_OPT_FILTER_SCRIPT - filters ? "Filtergraph" : "Filtergraph script", - filters ? filters : filters_script -#else - "Filtergraph", filters -#endif - ); - return AVERROR(ENOSYS); - } - return 0; - } - if (!ost->ist) { if ( #if FFMPEG_OPT_FILTER_SCRIPT @@ -1028,7 +1007,8 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, return ret; } -static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **encoder_opts) +static int streamcopy_init(const OptionsContext *o, const Muxer *mux, + OutputStream *ost, AVDictionary **encoder_opts) { MuxStream *ms = ms_from_ost(ost); @@ -1044,6 +1024,32 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **e int ret = 0; + const char *filters = NULL; +#if FFMPEG_OPT_FILTER_SCRIPT + const char *filters_script = NULL; + + opt_match_per_stream_str(ost, &o->filter_scripts, mux->fc, ost->st, &filters_script); +#endif + opt_match_per_stream_str(ost, &o->filters, mux->fc, ost->st, &filters); + + if ( +#if FFMPEG_OPT_FILTER_SCRIPT + filters_script || +#endif + filters) { + av_log(ost, AV_LOG_ERROR, + "%s '%s' was specified, but codec copy was selected. " + "Filtering and streamcopy cannot be used together.\n", +#if FFMPEG_OPT_FILTER_SCRIPT + filters ? "Filtergraph" : "Filtergraph script", + filters ? filters : filters_script +#else + "Filtergraph", filters +#endif + ); + return AVERROR(EINVAL); + } + codec_ctx = avcodec_alloc_context3(NULL); if (!codec_ctx) return AVERROR(ENOMEM); @@ -1562,7 +1568,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, } if (ost->ist && !ost->enc) { - ret = streamcopy_init(mux, ost, &encoder_opts); + ret = streamcopy_init(o, mux, ost, &encoder_opts); if (ret < 0) goto fail; } From patchwork Sat Sep 28 09:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51903 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp895785vqb; Sat, 28 Sep 2024 02:55:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXYvnXpKDHXR0eOt6EDo0TD6D08KGOPHG2QBrayncIqZ5djzMrh3uciJ6/kyH4VhGw0TUXz2C/eTaKfzG9qsjPm@gmail.com X-Google-Smtp-Source: AGHT+IGyDl1NDWaMGe0+oc9FvMVjrQTNvgG13TdAn8auy1IfglH84SZSTtxAA6DgMVUwSzkQImUJ X-Received: by 2002:a17:907:1c9f:b0:a8d:2623:dd17 with SMTP id a640c23a62f3a-a93d8b8384bmr96376066b.12.1727517309654; Sat, 28 Sep 2024 02:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517309; cv=none; d=google.com; s=arc-20240605; b=MOVPMTy7gXoaQn1IlLc2Rdk8F76Vb47djGao7bRwN07xKeOMiiM7w7dZc8lTA6Qi8t NBw4fbDN0eKZedmvYKwVu/OmT9753ohiHq6xsDt593bjo7vFBe7YXMvr43BenAuaAVY6 j4JKQE8RC0pU8keBiDOGrLLArj5u2dn/msYvCkfrSctnfctONsHfU9GRL9QIwqImKEY1 /BjkAscGhV9xLG/M3vz3tzJm6Lfut2HvRIE0h8AZFmo8z7NwCmqKBc/9iEQodUfROkk7 DTyOaYpbNrSQJNZ0vRzRL8sVbETq0L6ZF+0CSicVBH9w83oIpCykl+AKZg98GbfKMR8H ZY6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=pZ5aHTYw7JbLYMa427UxsdAGtZdZOq7V0uBZYhdDSC0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BETO3CvqM7uJo3yOVwSB9Wlq/OlPfsecO5npaAokflnXqCanbJROPFWl8nlHFyOEBX q9LXwLD+eAlAn9eYQHYyK9Zh694DWe3P05RBipNEDGutC99P5k2LosY2p4n6NkB1sWRD BeWEnYiXN5maBgNe7X75gws3Kcuxx1l1gROaKCgKoGvbCwJvNO+OY2RwFUGDRbkywsON QkXQHqMzkqRHilMjzLALw1nNHEmHlvjUTc7hAnk32v3OUzE9in6Lo5LdNtZBSzqA4vOv nNdf62x/5i6R6FkQb715wYUAcUwKdFO+Ka5zEoMfV3Sf5+viaoW55EPPYHqDl2JdnnQG HHLg==; 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=GQlODzeN; 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-a93c29ee94dsi276856866b.667.2024.09.28.02.55.09; Sat, 28 Sep 2024 02:55:09 -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=GQlODzeN; 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 DFD1B68DC89; Sat, 28 Sep 2024 12:54:08 +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 5B24968DB33 for ; Sat, 28 Sep 2024 12:54:02 +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=GQlODzeN; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E336D4DE6 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 3_BOZwIyFWfW for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=/xhyq7f7gOn3vmRqZlYdyVi0yK4gfIg2jXSHmVO87Yk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GQlODzeNwWHvY6nspbyRz//t1e0zM+EEeXviGrjoArG7IEsxyuRKOE+6/8X5mvMfu J66ks+aSECFpVvF48dvuBeXED8syjZuhMQLCqghOBCVX38hWlCKcMFD1QT496e9oFC 1oFV5iGvphNghZk7xrNDdDr0aFbspWpWVwLQGRrqSkbU8EHCkxdQHbeBV7Dalvt6cb Mx5wsI39kaKaQPlq32YgGpTImNc/by1zIoggaVAUqnk/XSiICCIgoUNQLtdXaTd6Ja K6nQFfMnPL84niEaOcIpxCofsAo4yIHac5dDAaAdfnw91/vvs+hNu1TA+PzUWUoCcJ uUJ1WLMkUsYKA== 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 C8C7A4E05 for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A45983A17BA for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:40 +0200 Message-ID: <20240928095341.15552-8-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_mux_init: move the ost_get_filters() call to ost_bind_filter() 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: yXHHKgJeOiee That is a more appropriate place for it. --- fftools/ffmpeg_mux_init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 1ddd1d7492..50ce45ef1b 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -896,7 +896,7 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, static int ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, - const OptionsContext *o, char *filters, + const OptionsContext *o, AVRational enc_tb, enum VideoSyncMethod vsync_method, int keep_pix_fmt, int autoscale, int threads_manual, const ViewSpecifier *vs) @@ -904,6 +904,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, OutputStream *ost = &ms->ost; AVCodecContext *enc_ctx = ost->enc->enc_ctx; char name[16]; + char *filters = NULL; int ret; OutputFilterOptions opts = { @@ -985,7 +986,12 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, return ret; } + ret = ost_get_filters(o, mux->fc, ost, &filters); + if (ret < 0) + return ret; + if (ofilter) { + av_assert0(!filters); ost->filter = ofilter; ret = ofilter_bind_enc(ofilter, ms->sch_idx_enc, &opts); } else { @@ -1188,7 +1194,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, AVRational enc_tb = { 0, 0 }; enum VideoSyncMethod vsync_method = VSYNC_AUTO; const char *bsfs = NULL, *time_base = NULL, *codec_tag = NULL; - char *filters = NULL, *next; + char *next; double qscale = -1; st = avformat_new_stream(oc, NULL); @@ -1526,15 +1532,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ret < 0) goto fail; - if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) { - ret = ost_get_filters(o, oc, ost, &filters); - if (ret < 0) - goto fail; - } - if (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { - ret = ost_bind_filter(mux, ms, ofilter, o, filters, enc_tb, vsync_method, + ret = ost_bind_filter(mux, ms, ofilter, o, enc_tb, vsync_method, keep_pix_fmt, autoscale, threads_manual, vs); if (ret < 0) goto fail; From patchwork Sat Sep 28 09:53:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51904 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d8ca:0:b0:48e:c0f8:d0de with SMTP id dy10csp897790vqb; Sat, 28 Sep 2024 03:01:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWepRJMrCUOwH+v9cEIKVRYobedZp5gtEI6aLrZAfn/sTt7JJuLAHBnd2xT9vQUIqb3TqsSAguCl7L6aveobmf+@gmail.com X-Google-Smtp-Source: AGHT+IEqhVmRCQTMeq5mK7kVw1GcX0ZzQt7olD1ip+cMu6vlfnfUnA8cnB3LuqrPG+Exanp+F1pw X-Received: by 2002:a2e:bea0:0:b0:2fa:c55b:1af1 with SMTP id 38308e7fff4ca-2fac55b2100mr740741fa.0.1727517674476; Sat, 28 Sep 2024 03:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727517674; cv=none; d=google.com; s=arc-20240605; b=WRnmlMPLg1g1o37/3RePwlxCZVAa0/hOWqbr4/IUYuSZswXyjzpUxZtjS8kMl2Ha+v /Dl+dsqB4Ajryhx7LOsdkKHk9Y8+vt+3wuwGk6vylNk/x/dM99AEN5aht5b59Q4ENn9K F3+ZqdPi0j2NmHGwwV1rePIL3SginiVlAQfBMGF4iWrzyQ2lqt1jSW6toMv8ODeQ426b 6+ishZnqFLX8isocLF0ni3xnFVxG3ar4AoyCCagDA8wW5hknTL7G3Y4z5/6IaGkPJJ0c 3fgRHMQjT5c095EL7tms6qKSPW3/dNYLFJAfDZhTmuUprngMEEnTCg/1VEO1+Na3Ova/ IXow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=zeLoTkUGBzQo9wOo5G8gSCAuvvmvdjrgK1DIGJNjpSc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=DV8KOJmKzCK3VBIcRa0TwFNJETcrHFp2lJB1ZHlkF3QV5HdUFymuNYOJzxCu1NWuGN MO18a9ZJx4fI1/Kdx08vE6vUKUtWm/aid5rz0NW30K50BWqs1JfNzOAGyIGvQqHgXGg8 NqZG8VxPY8pKMStpZRYcrV9yPVF2nA/kYw9KXU0cL2to+++YM2usMdiNNaI1JQ4MGmEn /9DEyhuSoaMZXk715ZtzHcl7aKX4x3sw4D1RVdpEeCMnfVFoju6icpX4m3rjrG5WJNXM GpGlfo2RKYypqqAEVBAWWq5Tw2WbHwyqYlv3DAQCwowobFsrqg/oNah82wJSR3ZdbtTz qdzQ==; 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=F7VpQFuu; 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 38308e7fff4ca-2f9d466833dsi12452591fa.645.2024.09.28.03.01.13; Sat, 28 Sep 2024 03:01:14 -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=F7VpQFuu; 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 293C868DC95; Sat, 28 Sep 2024 12:54:10 +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 5EA8268DB34 for ; Sat, 28 Sep 2024 12:54:02 +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=F7VpQFuu; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3E9D04DEE for ; Sat, 28 Sep 2024 11:53:57 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ET5yvDyVQfK1 for ; Sat, 28 Sep 2024 11:53:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727517234; bh=n/FpK33CqW+5kLvt0cD+QxMz3DZODU+DkI6a337Z8OI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=F7VpQFuuhBlIbZFF9KnNWpjSuGOKRi0jTVvp9sIzOj4aziHzJUr5jj8RKfqp8kzgx AJ+/B6xCXEEGvqRhMsikgs5UtZIQoyFz2liIf2a/XuHpj31tLwlpUr9cOzdF0CeUbc RgepepnzxHbwwwaxrxqDXc2mCyd/nJMBOTCFiE3uwJeR5Kgi6+aZ7sMpfMxHxZHrI7 9VEoaCuvH8WMJZ5HjSqy9nuvbJXa6iTXEtO5C1wlXYqhHGbEfAbfafZOkPxBGcb3yc QQ4vq1PQMtvccK+f6Ny4z9cflX0w0mGBqlIQftRShS41fgjZdGw0vBeZcITp5ZUXZ9 ZmuyitMInWK2Q== 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 C8C194E02 for ; Sat, 28 Sep 2024 11:53:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AF72A3A19A6 for ; Sat, 28 Sep 2024 11:53:48 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Sep 2024 11:53:41 +0200 Message-ID: <20240928095341.15552-9-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240928095341.15552-1-anton@khirnov.net> References: <20240928095341.15552-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg_mux_init: consolidate connecting source to mux stream 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: p+fqA9QdEp5Y --- fftools/ffmpeg_mux_init.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 50ce45ef1b..944176ca5d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -899,7 +899,8 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, const OptionsContext *o, AVRational enc_tb, enum VideoSyncMethod vsync_method, int keep_pix_fmt, int autoscale, int threads_manual, - const ViewSpecifier *vs) + const ViewSpecifier *vs, + SchedulerNode *src) { OutputStream *ost = &ms->ost; AVCodecContext *enc_ctx = ost->enc->enc_ctx; @@ -1005,12 +1006,9 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, 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; + *src = SCH_ENC(ms->sch_idx_enc); - return ret; + return 0; } static int streamcopy_init(const OptionsContext *o, const Muxer *mux, @@ -1188,6 +1186,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, OutputStream *ost; const AVCodec *enc; AVStream *st; + SchedulerNode src = { .type = SCH_NODE_TYPE_NONE }; AVDictionary *encoder_opts = NULL; int ret = 0, keep_pix_fmt = 0, autoscale = 1; int threads_manual = 0; @@ -1535,12 +1534,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { ret = ost_bind_filter(mux, ms, ofilter, o, enc_tb, vsync_method, - keep_pix_fmt, autoscale, threads_manual, vs); + keep_pix_fmt, autoscale, threads_manual, vs, &src); if (ret < 0) goto fail; } else if (ost->ist) { - SchedulerNode src; - ret = ist_use(ost->ist, !!ost->enc, NULL, &src); if (ret < 0) { av_log(ost, AV_LOG_ERROR, @@ -1549,24 +1546,26 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, } ms->sch_idx_src = src.idx; + // src refers to a decoder for transcoding, demux stream otherwise if (ost->enc) { ret = sch_connect(mux->sch, src, SCH_ENC(ms->sch_idx_enc)); if (ret < 0) goto fail; - - ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc), - SCH_MSTREAM(mux->sch_idx, ms->sch_idx)); - if (ret < 0) - goto fail; - } else { - ret = sch_connect(mux->sch, - src, SCH_MSTREAM(ost->file->index, ms->sch_idx)); - if (ret < 0) - goto fail; + src = SCH_ENC(ms->sch_idx_enc); } } + if (src.type != SCH_NODE_TYPE_NONE) { + ret = sch_connect(mux->sch, + src, SCH_MSTREAM(mux->sch_idx, ms->sch_idx)); + if (ret < 0) + goto fail; + } else { + // only attachment streams don't have a source + av_assert0(type == AVMEDIA_TYPE_ATTACHMENT && ms->sch_idx < 0); + } + if (ost->ist && !ost->enc) { ret = streamcopy_init(o, mux, ost, &encoder_opts); if (ret < 0)