From patchwork Thu Nov 17 10:16:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39312 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997262pzb; Thu, 17 Nov 2022 02:17:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf42DkAK5mWIfA5ZULonWqVRfOurikHWk+FA3mYCNxyAYzeSCOSswHhCDHEJEh0IPUNjrsgZ X-Received: by 2002:a17:906:3096:b0:7ae:eae9:25a5 with SMTP id 22-20020a170906309600b007aeeae925a5mr1568256ejv.394.1668680231649; Thu, 17 Nov 2022 02:17:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680231; cv=none; d=google.com; s=arc-20160816; b=FricKpyF27NA+cnQJUBHyJ3GwBqgmEP7Q9rfLjtXjBj2oaPqSQHyV40nmlrY/m0nBA Wzikum2A5HNCmEcBbzNRVVUE4JHpdiWFXdiUu/fwhVTCby3MsLWWnsYMMcOu5anI7IQz F3fTjLsVgQ0bIXh8M58vubecG5X6FjdTcRFydb2Kh2sy2DSGv91yVjp7ytohzJYhTnFo 73CzF5aC2xx6kmNKvQRGW+QhG5h5wh4h9X+G1Q+qVqUmB+9dVbo6rMnsQ/HfBROWka3a a24ljxPXIm/kBgx8QXfKY+4E2emAf5GuUs1ujhKSTG4Yun56Kn0SvKCFeobcblmKjGNN Ut9A== 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:message-id:date:to:from :delivered-to; bh=8g3nkLYkCsjasWkU8VbyUIExlohjtjfcXGzauMfe+i4=; b=u1cWon9xyTp3rbg7b4g468x5wUXtFLmCr+fs7fkJTreGjog4a8lStcccxgRjHq6yNn GOw83DfdqPBE8Aego5u6zy6O8O85JJndYGVZOQsC8Z88A40t/fMe6RmV6urww8FxLZdO ET1H60EFVvTlIDX+cXy02d1WZg5kuqcLKM7Jczmx3XceQ1L+scHb16U5i2DgtZbA5S7p FRUwNq6Ee3osg+cIka4fGCXd0vjWnU36+CzIT/+jLpFWwi5+U5DcyFxZ8zLHon3zdqsa oNKya+x2R6iZsZNP7Sxo09lXhEAkNcFyHPnaxBhKZhMOZ2rB7ows+UgoZOq3Lu9SWvyr UsKA== ARC-Authentication-Results: i=1; mx.google.com; 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 x14-20020a05640226ce00b00459dc4e4b7fsi530948edd.143.2022.11.17.02.17.10; Thu, 17 Nov 2022 02:17:11 -0800 (PST) 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; 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 A849568BD2B; Thu, 17 Nov 2022 12:16:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FAB168BA62 for ; Thu, 17 Nov 2022 12:16:45 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D710A240591 for ; Thu, 17 Nov 2022 11:16:44 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id N9a8i2IsGVHz for ; Thu, 17 Nov 2022 11:16:44 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 47E132404F8 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E8D653A01E5 for ; Thu, 17 Nov 2022 11:16:42 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:31 +0100 Message-Id: <20221117101640.6789-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg: move freeing an input stream into a separate function 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: SKtBLf/DXPgo --- fftools/ffmpeg.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index dfdfad3ce4..25155e155e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -502,6 +502,28 @@ static int decode_interrupt_cb(void *ctx) const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; +static void ist_free(InputStream **pist) +{ + InputStream *ist = *pist; + + if (!ist) + return; + + av_frame_free(&ist->decoded_frame); + av_packet_free(&ist->pkt); + av_dict_free(&ist->decoder_opts); + avsubtitle_free(&ist->prev_sub.subtitle); + av_frame_free(&ist->sub2video.frame); + av_freep(&ist->filters); + av_freep(&ist->hwaccel_device); + av_freep(&ist->dts_buffer); + + avcodec_free_context(&ist->dec_ctx); + avcodec_parameters_free(&ist->par); + + av_freep(pist); +} + static void ffmpeg_cleanup(int ret) { int i, j; @@ -558,23 +580,8 @@ static void ffmpeg_cleanup(int ret) for (i = 0; i < nb_input_files; i++) ifile_close(&input_files[i]); - for (i = 0; i < nb_input_streams; i++) { - InputStream *ist = input_streams[i]; - - av_frame_free(&ist->decoded_frame); - av_packet_free(&ist->pkt); - av_dict_free(&ist->decoder_opts); - avsubtitle_free(&ist->prev_sub.subtitle); - av_frame_free(&ist->sub2video.frame); - av_freep(&ist->filters); - av_freep(&ist->hwaccel_device); - av_freep(&ist->dts_buffer); - - avcodec_free_context(&ist->dec_ctx); - avcodec_parameters_free(&ist->par); - - av_freep(&input_streams[i]); - } + for (i = 0; i < nb_input_streams; i++) + ist_free(&input_streams[i]); if (vstats_file) { if (fclose(vstats_file)) From patchwork Thu Nov 17 10:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39307 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997086pzb; Thu, 17 Nov 2022 02:16:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4O9eK0JujHPsaXMgRoaJ8CqeA8Xu4Y0J/qeeIFYe0aXLV8HocWAXzMoWeCYP5buiota+0c X-Received: by 2002:a05:6402:3205:b0:467:3015:ad42 with SMTP id g5-20020a056402320500b004673015ad42mr1579273eda.259.1668680213974; Thu, 17 Nov 2022 02:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680213; cv=none; d=google.com; s=arc-20160816; b=sPChBYc8V7/KLxnF/KZTWb/CWzheGsXzfVdjHI053BKn6fxN+wG3HecELL9WgMU8b5 4Q3+mkbiXAzkUZ5J+YPsd2o2d18srFovTYTnOZrBFjGwq23pvV7YsQkxoCXNX0cY9uFl hGtG9TiBqmI2ak2lI2wwSz5oAPsLocZW5xYO4Rnfb4xt4dr7q5cg4/pEq4IaRizkkFf0 u3xZzLTwWOLPDfpFpq5ZMuPOviihD4ETtegeQnOcSVG4XF/Je/QBtoxF11jYmug5a7j3 p57n2J/bEeU3G6GdKHo5cLz03mAVVyvzFSIf+1Xso1r4Gfc+xENrXZWmNpTNlqAip6Kv 1P2g== 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:delivered-to; bh=j1v7w/XUdn5BaxNlK9G2dGblJ54nBy7eSdKoVZTw8Yk=; b=I0dcMfvS3BApB3xuFBp0sLg7JHmcpCEOWR9SeDu4uy0OW7tqvzphNVmPsG/9YnOJh4 F7cRzQoQfhezxgoaAvyaCVr9nlQRMIRe5McYbSHDtF5NknzI2febAVpzYKCsVABk5Ygb D3SiDN73ZbwY7EGCiA+BeBbcOiX1MWM9Jhu29MGpLDjMcK6YYi0EZUtR/X7lqY+Z6qyw 9V75nXFJK2kbSHaWeZzKB4gzG+Dc93yY+kZYj+eOkPoagVYMNQ1qCkAKP7KRTF+iwq56 TpY0Lf8XAzOvBxVNiPbWceM5DWxR7Our3kO8YWPThvn04rqBotWSiGX4kcpY5+tFyp81 /7Dw== ARC-Authentication-Results: i=1; mx.google.com; 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 hz1-20020a1709072ce100b007894b9de062si268940ejc.631.2022.11.17.02.16.53; Thu, 17 Nov 2022 02:16:53 -0800 (PST) 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; 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 391F668BCBB; Thu, 17 Nov 2022 12:16:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0497E68BA62 for ; Thu, 17 Nov 2022 12:16:44 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BA93A2406CD for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wRo8VvWMx80O for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 3B3C0240499 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 01DED3A02FD for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:32 +0100 Message-Id: <20221117101640.6789-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/10] fftools/ffmpeg: drop an arbitrary condition 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: VGq4qstCJpPF Encoding init code will currently fall back to a 25fps default when no framerate is known or specified, but only if there is a known source input stream. There is no good reason for this condition, so drop it. --- fftools/ffmpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 25155e155e..2c4dc83f03 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2877,7 +2877,7 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { if (!ost->frame_rate.num) ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter); - if (ist && !ost->frame_rate.num && !ost->max_frame_rate.num) { + if (!ost->frame_rate.num && !ost->max_frame_rate.num) { ost->frame_rate = (AVRational){25, 1}; av_log(NULL, AV_LOG_WARNING, "No information " From patchwork Thu Nov 17 10:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39311 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997178pzb; Thu, 17 Nov 2022 02:17:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4HetN++pGvXNa5HF9lJeITcTYhfHLiCVw5RqWQ8f1XtII4k/EJn2hp96wEGVIbunrMtO+l X-Received: by 2002:a05:6402:504:b0:461:5542:6884 with SMTP id m4-20020a056402050400b0046155426884mr1447670edv.390.1668680221718; Thu, 17 Nov 2022 02:17:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680221; cv=none; d=google.com; s=arc-20160816; b=0We8BKrQQ9jT01OdOEr2v8keEFwUcTLe/M+vNMYRT2l0d0eKggJKc/oR1/R/Nn1ob/ GGGbXRDoJZ9pSLcLx9VUybKPnPwWR4AO0M/0rF32MJK+oUVOPbM4I2+F2wjyik/+7xXu ZWIuQgJgDArIv6AX1XDZSaN0yraURX2vwyi4OiAHirE4u4xwP+/zNiEPU/ayjySlSyip Xa01XpcITUoEE3EgyowwkyiGQh3b/3+rA5oJJrvqxy9hBsVhJYnXFe1Gm9TCLbAXnQOP Jf8HOjPsEE/DomL77Ht8eDF2NkT0E6DqQJwZl7oA6pPbRZuplKCLD+m1d2K7tNj+jLjQ b6yQ== 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:delivered-to; bh=9mk5/CucabIQb/dF2sJGJlrJVC+ctevfTUfL3VDk32M=; b=KtaABxo4R96xjgc7Qov+VrnxQ2GwsSnHD2P+qb7qwK198NciIX1dj+JYO4275M/GN0 VO8BTRh6AqqlhrjZQBbuG9DGItpHT/FstPoBNg2QA2mtUm0fkUiEc2sVWPpJ+a0ha18N A/nwscEm38c3f2l9czsnzADaf1VehJC8jp2kUXF0NluiIuyjHrdc7OwZdNRnqWV7hhms KrNnLhQiZx/6tM+WkFq4gpWbz5dL8mrDwOcFYmGDylQFqfjYnZ6IhyQxO0+lbeZ3LTC0 gDRNyaiu2expglgaMFSItFB2w416cf7oIg3/gTtDPHFItHHuU/ztQVQMqmX6rL/yOCfh BJGQ== ARC-Authentication-Results: i=1; mx.google.com; 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 q14-20020a056402248e00b0046184b7c4besi492345eda.462.2022.11.17.02.17.01; Thu, 17 Nov 2022 02:17:01 -0800 (PST) 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; 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 9669F68BB60; Thu, 17 Nov 2022 12:16:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8251768BA62 for ; Thu, 17 Nov 2022 12:16:44 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4B1EB240499 for ; Thu, 17 Nov 2022 11:16:44 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id aUPlq6ijqaFi for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 49786240591 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0D0373A0520 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:33 +0100 Message-Id: <20221117101640.6789-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/10] fftools/ffmpeg: stop inventing fake source information 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: /fjuvd+e1e+s This code was supposed to affect copying stream dispositions, but it does not achieve that after bd55552d69, since dispositions are set earlier. --- fftools/ffmpeg.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2c4dc83f03..08fdd6e98f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3170,21 +3170,6 @@ static int transcode_init(void) InputStream *ist; char error[1024] = {0}; - for (i = 0; i < nb_filtergraphs; i++) { - FilterGraph *fg = filtergraphs[i]; - for (j = 0; j < fg->nb_outputs; j++) { - OutputFilter *ofilter = fg->outputs[j]; - if (!ofilter->ost || ofilter->ost->source_index >= 0) - continue; - if (fg->nb_inputs != 1) - continue; - for (k = nb_input_streams-1; k >= 0 ; k--) - if (fg->inputs[0]->ist == input_streams[k]) - break; - ofilter->ost->source_index = k; - } - } - /* init framerate emulation */ for (i = 0; i < nb_input_files; i++) { InputFile *ifile = input_files[i]; From patchwork Thu Nov 17 10:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39316 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997529pzb; Thu, 17 Nov 2022 02:17:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7n7NtwSuLK/TO7iQP1immzKsSqk79PiITY35RMoJZfGzGHbaTJPn1WUMA79GV0zTo//RsH X-Received: by 2002:a17:907:8b13:b0:781:541:6599 with SMTP id sz19-20020a1709078b1300b0078105416599mr1574747ejc.45.1668680268697; Thu, 17 Nov 2022 02:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680268; cv=none; d=google.com; s=arc-20160816; b=ERUOZP7DxSms6kn45WWH8HCaspsR6f4VwBY0lDY4GqVr0hg0EVDm9EzQbD4Tod+yGD OD6ZhxOpg97Uumz0RkZ2PbmgtNJBSiVR27SeezHKjI+zM7fqC9K4z89t4gPn8vUV0Eh5 8Zo+wSQDmrA82BneGZMLPUHcAwzXuFfHODMnx48ey84cyKPi0ovblx/k1ioLL9RjAkmb Io8uaw2z7Wgc9NU2d9A2NfAs4QR//i5wRcizI1RcLcNAVmRd08KMYI/gzq3UwWZoKdJy 4Pc8LBfVarMXU1913a/hL+qrUAdNEQ/K3vjhPDv3BUlpgar+aWwpwBIrInOfts/XJBFr gbvg== 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:delivered-to; bh=TaJo+dmPOauQGSvjSyqACkZ6IjgHGz/+NpypSv9lZ6o=; b=UjDp3h8agMgSXkwoDfTWbqoQ4Q1dnULdXv2FlC4+ZtxGBGD0sG/lZHjZpuS704esbF 2T3/6PCI/gSwwfQLzcexXeLTEPriC2YX2jQykbUJtiMSmRl3H+ieX4LnUvIeWfp1FT+5 z8vNRn7VaXVt19latcVABBM0PrqoZwfllh4On+uAK+CFsC5f6amCaihTPKkYIKX4uxY1 wRtK7Nfeuq1vRsuAisjLqj9hkXtX+OrlDviEw4H4ovuZnXJiufN5A0thpcVmwxtufbQf uWKswLy86AsFzgHNNOePXU51x/RPujGB5cEIHjEkvQEvWfSVlRhLQC4Xr4yG/eu45zys xXng== ARC-Authentication-Results: i=1; mx.google.com; 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 nb4-20020a1709071c8400b007ae2dfe020bsi250684ejc.783.2022.11.17.02.17.48; Thu, 17 Nov 2022 02:17:48 -0800 (PST) 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; 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 8218168BDC9; Thu, 17 Nov 2022 12:16:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D6B868BD36 for ; Thu, 17 Nov 2022 12:16:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 936642405F9 for ; Thu, 17 Nov 2022 11:16:46 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QvaDIiljf51E for ; Thu, 17 Nov 2022 11:16:45 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 5326C2405EC for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 189693A054D for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:34 +0100 Message-Id: <20221117101640.6789-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/10] fftools/ffmpeg: replace OutputStream.source_index with a pointer to InputStream 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: kZWWGcdUH8/k This is simpler. The indirection via an index exists for historical reasons that longer apply. --- fftools/ffmpeg.c | 42 ++++++++++++++------------------------- fftools/ffmpeg.h | 7 ++++++- fftools/ffmpeg_mux_init.c | 37 ++++++++++++++++------------------ 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 08fdd6e98f..0be2715687 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1122,15 +1122,12 @@ static void do_video_out(OutputFile *of, double delta, delta0; double duration = 0; double sync_ipts = AV_NOPTS_VALUE; - InputStream *ist = NULL; + InputStream *ist = ost->ist; AVFilterContext *filter = ost->filter->filter; init_output_stream_wrapper(ost, next_picture, 1); sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture); - if (ost->source_index >= 0) - ist = input_streams[ost->source_index]; - frame_rate = av_buffersink_get_frame_rate(filter); if (frame_rate.num > 0 && frame_rate.den > 0) duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); @@ -1764,9 +1761,8 @@ static void flush_encoders(void) static int check_output_constraints(InputStream *ist, OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; - int ist_index = input_files[ist->file_index]->ist_index + ist->st->index; - if (ost->source_index != ist_index) + if (ost->ist != ist) return 0; if (ost->finished & MUXER_FINISHED) @@ -2610,13 +2606,6 @@ static int init_input_stream(int ist_index, char *error, int error_len) return 0; } -static InputStream *get_input_stream(OutputStream *ost) -{ - if (ost->source_index >= 0) - return input_streams[ost->source_index]; - return NULL; -} - static int compare_int64(const void *a, const void *b) { return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); @@ -2625,7 +2614,7 @@ static int compare_int64(const void *a, const void *b) static int init_output_stream_streamcopy(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; - InputStream *ist = get_input_stream(ost); + InputStream *ist = ost->ist; InputFile *ifile = input_files[ist->file_index]; AVCodecParameters *par = ost->st->codecpar; AVCodecContext *codec_ctx; @@ -2838,7 +2827,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base) { - InputStream *ist = get_input_stream(ost); + InputStream *ist = ost->ist; AVCodecContext *enc_ctx = ost->enc_ctx; if (ost->enc_timebase.num > 0) { @@ -2862,7 +2851,7 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) { - InputStream *ist = get_input_stream(ost); + InputStream *ist = ost->ist; AVCodecContext *enc_ctx = ost->enc_ctx; AVCodecContext *dec_ctx = NULL; OutputFile *of = output_files[ost->file_index]; @@ -3006,8 +2995,8 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_SUBTITLE: enc_ctx->time_base = AV_TIME_BASE_Q; if (!enc_ctx->width) { - enc_ctx->width = input_streams[ost->source_index]->par->width; - enc_ctx->height = input_streams[ost->source_index]->par->height; + enc_ctx->width = ost->ist->par->width; + enc_ctx->height = ost->ist->par->height; } if (dec_ctx && dec_ctx->subtitle_header) { /* ASS code assumes this buffer is null terminated so add extra byte. */ @@ -3063,13 +3052,12 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, if (ost->enc_ctx) { const AVCodec *codec = ost->enc_ctx->codec; - InputStream *ist; + InputStream *ist = ost->ist; ret = init_output_stream_encode(ost, frame); if (ret < 0) return ret; - ist = get_input_stream(ost); if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) av_dict_set(&ost->encoder_opts, "threads", "auto", 0); @@ -3150,7 +3138,7 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, // copy estimated duration as a hint to the muxer if (ost->st->duration <= 0 && ist && ist->st->duration > 0) ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - } else if (ost->source_index >= 0) { + } else if (ost->ist) { ret = init_output_stream_streamcopy(ost); if (ret < 0) return ret; @@ -3257,12 +3245,12 @@ static int transcode_init(void) } av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", - input_streams[ost->source_index]->file_index, - input_streams[ost->source_index]->st->index, + ost->ist->file_index, + ost->ist->st->index, ost->file_index, ost->index); if (ost->enc_ctx) { - const AVCodec *in_codec = input_streams[ost->source_index]->dec; + const AVCodec *in_codec = ost->ist->dec; const AVCodec *out_codec = ost->enc_ctx->codec; const char *decoder_name = "?"; const char *in_codec_name = "?"; @@ -3648,7 +3636,7 @@ static int process_input(int file_index) /* mark all outputs that don't go through lavfi as finished */ for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - if (ost->source_index == ifile->ist_index + i && + if (ost->ist == ist && (!ost->enc_ctx || ost->enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE)) { OutputFile *of = output_files[ost->file_index]; of_output_packet(of, ost->pkt, ost, 1); @@ -3837,8 +3825,8 @@ static int transcode_step(void) return 0; } } else { - av_assert0(ost->source_index >= 0); - ist = input_streams[ost->source_index]; + ist = ost->ist; + av_assert0(ist); } ret = process_input(ist->file_index); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index a96ff0d723..b1e466406d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -486,7 +486,12 @@ typedef enum { typedef struct OutputStream { int file_index; /* file index */ int index; /* stream index in the output file */ - int source_index; /* InputStream index */ + + /* input stream that is the source for this output stream; + * may be NULL for streams with no well-defined source, e.g. + * attachments or outputs from complex filtergraphs */ + InputStream *ist; + AVStream *st; /* stream in the output file */ /* number of frames emitted by the video-encoding sync code */ int64_t vsync_frame_number; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index db45fa09fa..e460e7603f 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -354,10 +354,10 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - ost->source_index = source_index; if (source_index >= 0) { - input_streams[source_index]->discard = 0; - input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard; + ost->ist = input_streams[source_index]; + ost->ist->discard = 0; + ost->ist->st->discard = ost->ist->user_set_discard; } ost->last_mux_dts = AV_NOPTS_VALUE; ost->last_filter_pts = AV_NOPTS_VALUE; @@ -631,9 +631,8 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, int s VSYNC_CFR; } - if (ost->source_index >= 0 && ost->vsync_method == VSYNC_CFR) { - const InputStream *ist = input_streams[ost->source_index]; - const InputFile *ifile = input_files[ist->file_index]; + if (ost->ist && ost->vsync_method == VSYNC_CFR) { + const InputFile *ifile = input_files[ost->ist->file_index]; if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0) ost->vsync_method = VSYNC_VSCFR; @@ -730,12 +729,12 @@ static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, int s if (map->channel_idx == -1) { ist = NULL; - } else if (ost->source_index < 0) { + } else if (!ost->ist) { av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n", ost->file_index, ost->st->index); continue; } else { - ist = input_streams[ost->source_index]; + ist = ost->ist; } if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) { @@ -1648,11 +1647,10 @@ static void copy_meta(Muxer *mux, const OptionsContext *o) if (!metadata_streams_manual) for (int i = 0; i < of->nb_streams; i++) { OutputStream *ost = of->streams[i]; - InputStream *ist; - if (ost->source_index < 0) /* this is true e.g. for attached files */ + + if (!ost->ist) /* this is true e.g. for attached files */ continue; - ist = input_streams[ost->source_index]; - av_dict_copy(&ost->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); + av_dict_copy(&ost->st->metadata, ost->ist->st->metadata, AV_DICT_DONT_OVERWRITE); if (ost->enc_ctx) { av_dict_set(&ost->st->metadata, "encoder", NULL, 0); } @@ -1673,8 +1671,8 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) have_manual |= !!ost->disposition; - if (ost->source_index >= 0) { - ost->st->disposition = input_streams[ost->source_index]->st->disposition; + if (ost->ist) { + ost->st->disposition = ost->ist->st->disposition; if (ost->st->disposition & AV_DISPOSITION_DEFAULT) have_default[ost->st->codecpar->codec_type] = 1; @@ -1846,8 +1844,8 @@ int of_open(const OptionsContext *o, const char *filename) for (int i = 0; i < of->nb_streams; i++) { OutputStream *ost = of->streams[i]; - if (ost->enc_ctx && ost->source_index >= 0) { - InputStream *ist = input_streams[ost->source_index]; + if (ost->enc_ctx && ost->ist) { + InputStream *ist = ost->ist; ist->decoding_needed |= DECODING_FOR_OST; ist->processing_needed = 1; @@ -1857,14 +1855,13 @@ int of_open(const OptionsContext *o, const char *filename) if (err < 0) { av_log(NULL, AV_LOG_ERROR, "Error initializing a simple filtergraph between streams " - "%d:%d->%d:%d\n", ist->file_index, ost->source_index, + "%d:%d->%d:%d\n", ist->file_index, ist->st->index, nb_output_files - 1, ost->st->index); exit_program(1); } } - } else if (ost->source_index >= 0) { - InputStream *ist = input_streams[ost->source_index]; - ist->processing_needed = 1; + } else if (ost->ist) { + ost->ist->processing_needed = 1; } /* set the filter output constraints */ From patchwork Thu Nov 17 10:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39313 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997320pzb; Thu, 17 Nov 2022 02:17:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YpEev7kpD5/w1a2aKQN61V6Z5osJJRM7mKgXU+KFe2cFpjWcL+iUM8/OuTMRTaFWCi49C X-Received: by 2002:a17:906:398b:b0:7ad:b868:f096 with SMTP id h11-20020a170906398b00b007adb868f096mr1567071eje.295.1668680241044; Thu, 17 Nov 2022 02:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680241; cv=none; d=google.com; s=arc-20160816; b=BpGmmQbFFCcSdT9v8Yn4vbL1kMlaS5mFyY8jxEKheRCX0LGpGU7394/KbXwEzTZZd2 TKKDlce0ClLcusS0qjt/H2AIFu5Bwv/LyadXy1ZVFRRuPV5CFGQQVOHwHEUFtkfxKXKY uBt8B3Q5nyhyw3gzXsrbGL9HY1jTsDEz1/HBgVuiSdtJliks1dQKFdsANQyzwVs4upe5 3HVqujy/HJv0aEE/dzmOIKuOWW8eqAxe/O4u2spVvUccCVmX507xV5/R8ZCuhadtZyRT mFcrCmpwk2dHC9kQpQz2hq+o28RAxx4IY+ReCPNGjo6WvfqiVDuh5lh/bQ0byU5wtItA FuqA== 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:delivered-to; bh=P229JHkDMWJ620qaNqsgg6KpdxIglJF3+snHP25nKqA=; b=Gl2QjCNGsxypMrLgQkaFRnISRl3JCPI4OSwJ2i7lbcqZCSFea2g8QHdARHI8fb3w5X N2PcLn648GLPfLswAHTtyAQy3crHqvqBUX3QD54IBnaqQZse3Mo3y/TDTbSWvLlfHA4d fQmFUz6tX9WTx39OU9gjnCNLI0z8r8rrOjdUfl1+5oak7IdODYvwROvOzzBHcmdsEoV7 W4CKbazhcWg5vBz2n8LgDhpHtBNMhXe+oLWoFUu1sV5S6VvtNMzuIW1wwQor1O+4Nugs 4egjuWU8CQRwi7eORR1N7OEItfankj3S8ALP0w+EFfgMm95nXLY3aaWyAzhr612MvW/8 zkKQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o3-20020a170906974300b007811ace1701si276743ejy.445.2022.11.17.02.17.20; Thu, 17 Nov 2022 02:17:21 -0800 (PST) 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; 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 7B85D68BD36; Thu, 17 Nov 2022 12:16:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D271968BCBB for ; Thu, 17 Nov 2022 12:16:45 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 95BDC2400F5 for ; Thu, 17 Nov 2022 11:16:45 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1NTzJxT-xsm9 for ; Thu, 17 Nov 2022 11:16:45 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 587A42405F9 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 242BD3A058F for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:35 +0100 Message-Id: <20221117101640.6789-5-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/10] fftools/ffmpeg_mux_init: simplify inner loop in map_auto_{video, audio} 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: 7/8aThZLPMSp Skip unusable streams early and do not compute any scores for them. --- fftools/ffmpeg_mux_init.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index e460e7603f..6db70cc852 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -869,15 +869,18 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ifile->nb_streams; i++) { int score; ist = input_streams[ifile->ist_index + i]; + + if (ist->user_set_discard == AVDISCARD_ALL || + ist->st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + score = ist->st->codecpar->width * ist->st->codecpar->height + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); - if (ist->user_set_discard == AVDISCARD_ALL) - continue; if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) score = 1; - if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - score > file_best_score) { + + if (score > file_best_score) { if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) continue; file_best_score = score; @@ -913,13 +916,15 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ifile->nb_streams; i++) { int score; ist = input_streams[ifile->ist_index + i]; + + if (ist->user_set_discard == AVDISCARD_ALL || + ist->st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) + continue; + score = ist->st->codecpar->ch_layout.nb_channels + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS) + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); - if (ist->user_set_discard == AVDISCARD_ALL) - continue; - if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - score > file_best_score) { + if (score > file_best_score) { file_best_score = score; file_best_idx = ifile->ist_index + i; } From patchwork Thu Nov 17 10:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39314 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997402pzb; Thu, 17 Nov 2022 02:17:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf6F/i0NfmsQb2BSWiJk215QYzNhtk/PC1mzzffP9iOatGU0xT9fbIAzWH3lovMnqXRz3X3a X-Received: by 2002:a17:906:cb90:b0:772:e95f:cdce with SMTP id mf16-20020a170906cb9000b00772e95fcdcemr1585450ejb.78.1668680251371; Thu, 17 Nov 2022 02:17:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680251; cv=none; d=google.com; s=arc-20160816; b=WTP2rakDIsqooZnE4/k48fJjye6VtHgVfQ9LmWRVcNKHJZwNjbM6txS2rKQ8Pi9fE3 zqrSeaGIbgPPeTjPgy5V8Vp/BFXaMm6o7biUYXI+amxiUFapvZO+VJNc1f76aO9jqltS R9ET+j7tVes6+b390+kslJS0tHLRb05jQKjgewu5P87vpKxCZdxiZL7MpzMS2tL7s/UO YnlH9ydUXPAWAxcxBIPO+z8jQlu/TDzL2QMJj04yW8Dt/FUYIeU0OKPlO2NY4oYaaEUJ oRUAdryRQ6+fwffM1djgzv6aSG6GMr54Vrxt2XbY0/2/kL7LL5zv9yc3F1CW1bhRNzr+ Ik3g== 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:delivered-to; bh=To3AmOYdPxlZlMKEFcWOyT4ah4gW/cNh1qxTfBKHBxU=; b=rHU7xAcUJd8+YRxYvW/7mi4+UJZ7GWhymgSLaEUCmvqVE/a3zkZDST1dfZj5/yUZuN ETM96mCR2yiNAT5LQh2D38VpVHEMRonl1gzbcjQtmq4LTeKP/8h/MbmQ1fOjRMH+sH80 77X2+m9BZp3L6UKhXP2DMZZyQLHalzoYkBUK97AAfRcAA4/lk3VZb8SUddNJx3Xa7Nwe /8GCY28Xeve1/s2WilalFo2DdN5FmOOd4xkcbFmiH0tQ5hh5rckukPoRNeAGsMx5A/wb REjNMD0nJgwjx7Wi2nSi8mq5Nn+bvMx/THQF7sIF/GDUG5Lhgu1qsq23NiQs/5pWV8hW dU8g== ARC-Authentication-Results: i=1; mx.google.com; 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 du17-20020a17090772d100b007ae83c7b8desi336813ejc.59.2022.11.17.02.17.30; Thu, 17 Nov 2022 02:17:31 -0800 (PST) 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; 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 789F368BD85; Thu, 17 Nov 2022 12:16:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9E0368BC53 for ; Thu, 17 Nov 2022 12:16:46 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 845762404F8 for ; Thu, 17 Nov 2022 11:16:46 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Qq5BZkIJ7h-5 for ; Thu, 17 Nov 2022 11:16:44 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 4638F2404F7 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2F9993A05F9 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:36 +0100 Message-Id: <20221117101640.6789-6-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/10] fftools/ffmpeg: remove the input_streams global 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: 67zCYes+BuBX Replace it with an array of streams in each InputFile. This is a more accurate reflection of the actual relationship between InputStream and InputFile. Analogous to what was previously done to output streams in 7ef7a22251b852faab9404c85399ba8ac5dfbdc3. --- fftools/ffmpeg.c | 86 +++++++++++---------------- fftools/ffmpeg.h | 16 +++-- fftools/ffmpeg_demux.c | 71 ++++++++++++++-------- fftools/ffmpeg_filter.c | 7 +-- fftools/ffmpeg_mux_init.c | 121 ++++++++++++++++++++------------------ fftools/ffmpeg_opt.c | 4 +- 6 files changed, 161 insertions(+), 144 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0be2715687..0944f56b80 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -141,8 +141,6 @@ unsigned nb_output_dumped = 0; static BenchmarkTimeStamps current_time; AVIOContext *progress_avio = NULL; -InputStream **input_streams = NULL; -int nb_input_streams = 0; InputFile **input_files = NULL; int nb_input_files = 0; @@ -279,7 +277,7 @@ static void sub2video_heartbeat(InputStream *ist, int64_t pts) video frames could be accumulating in the filter graph while a filter (possibly overlay) is desperately waiting for a subtitle frame. */ for (i = 0; i < infile->nb_streams; i++) { - InputStream *ist2 = input_streams[infile->ist_index + i]; + InputStream *ist2 = infile->streams[i]; if (!ist2->sub2video.frame) continue; /* subtitles seem to be usually muxed ahead of other streams; @@ -502,28 +500,6 @@ static int decode_interrupt_cb(void *ctx) const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; -static void ist_free(InputStream **pist) -{ - InputStream *ist = *pist; - - if (!ist) - return; - - av_frame_free(&ist->decoded_frame); - av_packet_free(&ist->pkt); - av_dict_free(&ist->decoder_opts); - avsubtitle_free(&ist->prev_sub.subtitle); - av_frame_free(&ist->sub2video.frame); - av_freep(&ist->filters); - av_freep(&ist->hwaccel_device); - av_freep(&ist->dts_buffer); - - avcodec_free_context(&ist->dec_ctx); - avcodec_parameters_free(&ist->par); - - av_freep(pist); -} - static void ffmpeg_cleanup(int ret) { int i, j; @@ -580,9 +556,6 @@ static void ffmpeg_cleanup(int ret) for (i = 0; i < nb_input_files; i++) ifile_close(&input_files[i]); - for (i = 0; i < nb_input_streams; i++) - ist_free(&input_streams[i]); - if (vstats_file) { if (fclose(vstats_file)) av_log(NULL, AV_LOG_ERROR, @@ -592,7 +565,6 @@ static void ffmpeg_cleanup(int ret) av_freep(&vstats_filename); av_freep(&filter_nbthreads); - av_freep(&input_streams); av_freep(&input_files); av_freep(&output_files); @@ -628,6 +600,22 @@ static OutputStream *ost_iter(OutputStream *prev) return NULL; } +InputStream *ist_iter(InputStream *prev) +{ + int if_idx = prev ? prev->file_index : 0; + int ist_idx = prev ? prev->st->index + 1 : 0; + + for (; if_idx < nb_input_files; if_idx++) { + InputFile *f = input_files[if_idx]; + if (ist_idx < f->nb_streams) + return f->streams[ist_idx]; + + ist_idx = 0; + } + + return NULL; +} + void remove_avoptions(AVDictionary **a, AVDictionary *b) { const AVDictionaryEntry *t = NULL; @@ -1410,7 +1398,7 @@ static void print_final_stats(int64_t total_size) i, f->ctx->url); for (j = 0; j < f->nb_streams; j++) { - InputStream *ist = input_streams[f->ist_index + j]; + InputStream *ist = f->streams[j]; enum AVMediaType type = ist->par->codec_type; total_size += ist->data_size; @@ -2541,10 +2529,9 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat return *p; } -static int init_input_stream(int ist_index, char *error, int error_len) +static int init_input_stream(InputStream *ist, char *error, int error_len) { int ret; - InputStream *ist = input_streams[ist_index]; if (ist->decoding_needed) { const AVCodec *codec = ist->dec; @@ -3163,12 +3150,12 @@ static int transcode_init(void) InputFile *ifile = input_files[i]; if (ifile->readrate || ifile->rate_emu) for (j = 0; j < ifile->nb_streams; j++) - input_streams[j + ifile->ist_index]->start = av_gettime_relative(); + ifile->streams[j]->start = av_gettime_relative(); } /* init input streams */ - for (i = 0; i < nb_input_streams; i++) - if ((ret = init_input_stream(i, error, sizeof(error))) < 0) + for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) + if ((ret = init_input_stream(ist, error, sizeof(error))) < 0) goto dump_format; /* @@ -3199,7 +3186,7 @@ static int transcode_init(void) int discard = AVDISCARD_ALL; for (k = 0; k < p->nb_stream_indexes; k++) - if (!input_streams[ifile->ist_index + p->stream_index[k]]->discard) { + if (!ifile->streams[p->stream_index[k]]->discard) { discard = AVDISCARD_DEFAULT; break; } @@ -3210,9 +3197,7 @@ static int transcode_init(void) dump_format: /* dump the stream mapping */ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); - for (i = 0; i < nb_input_streams; i++) { - ist = input_streams[i]; - + for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { for (j = 0; j < ist->nb_filters; j++) { if (!filtergraph_is_simple(ist->filters[j]->graph)) { av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", @@ -3416,7 +3401,7 @@ static int check_keyboard_interaction(int64_t cur_time) if (key == 'd' || key == 'D'){ int debug=0; if(key == 'D') { - debug = input_streams[0]->dec_ctx->debug << 1; + debug = ist_iter(NULL)->dec_ctx->debug << 1; if(!debug) debug = 1; while (debug & FF_DEBUG_DCT_COEFF) //unsupported, would just crash debug += debug; @@ -3434,9 +3419,8 @@ static int check_keyboard_interaction(int64_t cur_time) if (k <= 0 || sscanf(buf, "%d", &debug)!=1) fprintf(stderr,"error parsing debug value\n"); } - for(i=0;idec_ctx->debug = debug; - } + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) + ist->dec_ctx->debug = debug; for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { if (ost->enc_ctx) ost->enc_ctx->debug = debug; @@ -3480,7 +3464,7 @@ static void reset_eagain(void) static void decode_flush(InputFile *ifile) { for (int i = 0; i < ifile->nb_streams; i++) { - InputStream *ist = input_streams[ifile->ist_index + i]; + InputStream *ist = ifile->streams[i]; int ret; if (!ist->processing_needed) @@ -3627,7 +3611,7 @@ static int process_input(int file_index) } for (i = 0; i < ifile->nb_streams; i++) { - ist = input_streams[ifile->ist_index + i]; + ist = ifile->streams[i]; if (ist->processing_needed) { ret = process_input_packet(ist, NULL, 0); if (ret>0) @@ -3650,7 +3634,7 @@ static int process_input(int file_index) reset_eagain(); - ist = input_streams[ifile->ist_index + pkt->stream_index]; + ist = ifile->streams[pkt->stream_index]; ist->data_size += pkt->size; ist->nb_packets++; @@ -3682,8 +3666,8 @@ static int process_input(int file_index) ts_discontinuity_process(ifile, ist, pkt); if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt->stream_index, + av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n", + ifile->index, pkt->stream_index, av_get_media_type_string(ist->par->codec_type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), @@ -3887,8 +3871,7 @@ static int transcode(void) } /* at the end of stream, we must flush the decoder buffers */ - for (i = 0; i < nb_input_streams; i++) { - ist = input_streams[i]; + for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { if (!input_files[ist->file_index]->eof_reached) { process_input_packet(ist, NULL, 0); } @@ -3924,8 +3907,7 @@ static int transcode(void) } /* close each decoder */ - for (i = 0; i < nb_input_streams; i++) { - ist = input_streams[i]; + for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { if (ist->decoding_needed) { avcodec_close(ist->dec_ctx); } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b1e466406d..5fc3b2d3d4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -437,7 +437,6 @@ typedef struct InputFile { AVFormatContext *ctx; int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ - int ist_index; /* index of first stream in input_streams */ int64_t input_ts_offset; int input_sync_ref; /** @@ -452,8 +451,13 @@ typedef struct InputFile { int64_t last_ts; int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ int64_t recording_time; - int nb_streams; /* number of stream that ffmpeg is aware of; may be different - from ctx.nb_streams if new streams appear during av_read_frame() */ + + /* streams that ffmpeg is aware of; + * there may be extra streams in ctx that are not mapped to an InputStream + * if new streams appear dynamically during demuxing */ + InputStream **streams; + int nb_streams; + int rate_emu; float readrate; int accurate_seek; @@ -629,8 +633,6 @@ typedef struct OutputFile { int bitexact; } OutputFile; -extern InputStream **input_streams; -extern int nb_input_streams; extern InputFile **input_files; extern int nb_input_files; @@ -766,6 +768,10 @@ void ifile_close(InputFile **f); */ int ifile_get_packet(InputFile *f, AVPacket **pkt); +/* iterate over all input streams in all input files; + * pass NULL to start iteration */ +InputStream *ist_iter(InputStream *prev); + #define SPECIFIER_OPT_FMT_str "%s" #define SPECIFIER_OPT_FMT_i "%i" #define SPECIFIER_OPT_FMT_i64 "%"PRId64 diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 76778d774d..33035cd4d5 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -140,13 +140,13 @@ static int seek_to_start(Demuxer *d) return ret; got_durations++; - ist = input_streams[ifile->ist_index + dur.stream_idx]; + ist = ifile->streams[dur.stream_idx]; ifile_duration_update(d, ist, dur.duration); } } else { for (int i = 0; i < ifile->nb_streams; i++) { int64_t duration = 0; - ist = input_streams[ifile->ist_index + i]; + ist = ifile->streams[i]; if (ist->framerate.num) { duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base); @@ -169,14 +169,14 @@ static int seek_to_start(Demuxer *d) static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict) { InputFile *ifile = &d->f; - InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index]; + InputStream *ist = ifile->streams[pkt->stream_index]; const int64_t start_time = ifile->start_time_effective; int64_t duration; if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " + av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d:%d type:%s " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", - ifile->ist_index + pkt->stream_index, + ifile->index, pkt->stream_index, av_get_media_type_string(ist->st->codecpar->codec_type), av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), @@ -381,7 +381,7 @@ static int thread_start(Demuxer *d) int nb_audio_dec = 0; for (int i = 0; i < f->nb_streams; i++) { - InputStream *ist = input_streams[f->ist_index + i]; + InputStream *ist = f->streams[i]; nb_audio_dec += !!(ist->decoding_needed && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); } @@ -428,7 +428,7 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) ); float scale = f->rate_emu ? 1.0 : f->readrate; for (i = 0; i < f->nb_streams; i++) { - InputStream *ist = input_streams[f->ist_index + i]; + InputStream *ist = f->streams[i]; int64_t stream_ts_offset, pts, now; if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue; stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start); @@ -447,13 +447,35 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) if (msg.looping) return 1; - ist = input_streams[f->ist_index + msg.pkt->stream_index]; + ist = f->streams[msg.pkt->stream_index]; ist->last_pkt_repeat_pict = msg.repeat_pict; *pkt = msg.pkt; return 0; } +static void ist_free(InputStream **pist) +{ + InputStream *ist = *pist; + + if (!ist) + return; + + av_frame_free(&ist->decoded_frame); + av_packet_free(&ist->pkt); + av_dict_free(&ist->decoder_opts); + avsubtitle_free(&ist->prev_sub.subtitle); + av_frame_free(&ist->sub2video.frame); + av_freep(&ist->filters); + av_freep(&ist->hwaccel_device); + av_freep(&ist->dts_buffer); + + avcodec_free_context(&ist->dec_ctx); + avcodec_parameters_free(&ist->par); + + av_freep(pist); +} + void ifile_close(InputFile **pf) { InputFile *f = *pf; @@ -464,6 +486,10 @@ void ifile_close(InputFile **pf) thread_stop(d); + for (int i = 0; i < f->nb_streams; i++) + ist_free(&f->streams[i]); + av_freep(&f->streams); + avformat_close_input(&f->ctx); av_freep(pf); @@ -562,10 +588,11 @@ static void add_display_matrix_to_stream(const OptionsContext *o, vflip_set ? vflip : 0); } -/* Add all the streams from the given input file to the global - * list of input streams. */ -static void add_input_streams(const OptionsContext *o, AVFormatContext *ic) +/* Add all the streams from the given input file to the demuxer */ +static void add_input_streams(const OptionsContext *o, Demuxer *d) { + InputFile *f = &d->f; + AVFormatContext *ic = f->ctx; int i, ret; for (i = 0; i < ic->nb_streams; i++) { @@ -582,9 +609,9 @@ static void add_input_streams(const OptionsContext *o, AVFormatContext *ic) const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); - ist = ALLOC_ARRAY_ELEM(input_streams, nb_input_streams); + ist = ALLOC_ARRAY_ELEM(f->streams, f->nb_streams); ist->st = st; - ist->file_index = nb_input_files; + ist->file_index = f->index; ist->discard = 1; st->discard = AVDISCARD_ALL; ist->nb_samples = 0; @@ -1013,24 +1040,16 @@ int ifile_open(const OptionsContext *o, const char *filename) } } - /* update the current parameters so that they match the one of the input stream */ - add_input_streams(o, ic); - - /* dump the file content */ - av_dump_format(ic, nb_input_files, filename, 0); - d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files); f = &d->f; f->ctx = ic; f->index = nb_input_files - 1; - f->ist_index = nb_input_streams - ic->nb_streams; f->start_time = start_time; f->recording_time = recording_time; f->input_sync_ref = o->input_sync_ref; f->input_ts_offset = o->input_ts_offset; f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp); - f->nb_streams = ic->nb_streams; f->rate_emu = o->rate_emu; f->accurate_seek = o->accurate_seek; d->loop = o->loop; @@ -1049,11 +1068,17 @@ int ifile_open(const OptionsContext *o, const char *filename) d->thread_queue_size = o->thread_queue_size; + /* update the current parameters so that they match the one of the input stream */ + add_input_streams(o, d); + + /* dump the file content */ + av_dump_format(ic, f->index, filename, 0); + /* check if all codec options have been used */ unused_opts = strip_specifiers(o->g->codec_opts); - for (i = f->ist_index; i < nb_input_streams; i++) { + for (i = 0; i < f->nb_streams; i++) { e = NULL; - while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e, + while ((e = av_dict_get(f->streams[i]->decoder_opts, "", e, AV_DICT_IGNORE_SUFFIX))) av_dict_set(&unused_opts, e->key, NULL, 0); } diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 718826a485..5d50092b72 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -271,7 +271,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) "matches no streams.\n", p, fg->graph_desc); exit_program(1); } - ist = input_streams[input_files[file_idx]->ist_index + st->index]; + ist = input_files[file_idx]->streams[st->index]; if (ist->user_set_discard == AVDISCARD_ALL) { av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s " "matches a disabled input stream.\n", p, fg->graph_desc); @@ -279,14 +279,13 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) } } else { /* find the first unused stream of corresponding type */ - for (i = 0; i < nb_input_streams; i++) { - ist = input_streams[i]; + for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { if (ist->user_set_discard == AVDISCARD_ALL) continue; if (ist->dec_ctx->codec_type == type && ist->discard) break; } - if (i == nb_input_streams) { + if (!ist) { av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for " "unlabeled input pad %d on filter %s\n", in->pad_idx, in->filter_ctx->name); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6db70cc852..b6782b49aa 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -171,7 +171,7 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV } static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, int source_index) + enum AVMediaType type, InputStream *ist) { AVFormatContext *oc = mux->fc; MuxStream *ms; @@ -354,8 +354,8 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - if (source_index >= 0) { - ost->ist = input_streams[source_index]; + if (ist) { + ost->ist = ist; ost->ist->discard = 0; ost->ist->st->discard = ost->ist->user_set_discard; } @@ -419,14 +419,14 @@ static void parse_matrix_coeffs(uint16_t *dest, const char *str) } } -static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { AVFormatContext *oc = mux->fc; AVStream *st; OutputStream *ost; char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_VIDEO, source_index); + ost = new_output_stream(mux, o, AVMEDIA_TYPE_VIDEO, ist); st = ost->st; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -657,13 +657,13 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, int s return ost; } -static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { AVFormatContext *oc = mux->fc; AVStream *st; OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_AUDIO, source_index); + ost = new_output_stream(mux, o, AVMEDIA_TYPE_AUDIO, ist); st = ost->st; @@ -755,11 +755,11 @@ static OutputStream *new_audio_stream(Muxer *mux, const OptionsContext *o, int s return ost; } -static OutputStream *new_data_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_data_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_DATA, source_index); + ost = new_output_stream(mux, o, AVMEDIA_TYPE_DATA, ist); if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n"); exit_program(1); @@ -768,11 +768,11 @@ static OutputStream *new_data_stream(Muxer *mux, const OptionsContext *o, int so return ost; } -static OutputStream *new_unknown_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_unknown_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_UNKNOWN, source_index); + ost = new_output_stream(mux, o, AVMEDIA_TYPE_UNKNOWN, ist); if (ost->enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n"); exit_program(1); @@ -781,19 +781,19 @@ static OutputStream *new_unknown_stream(Muxer *mux, const OptionsContext *o, int return ost; } -static OutputStream *new_attachment_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_attachment_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { - OutputStream *ost = new_output_stream(mux, o, AVMEDIA_TYPE_ATTACHMENT, source_index); + OutputStream *ost = new_output_stream(mux, o, AVMEDIA_TYPE_ATTACHMENT, ist); ost->finished = 1; return ost; } -static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, int source_index) +static OutputStream *new_subtitle_stream(Muxer *mux, const OptionsContext *o, InputStream *ist) { AVStream *st; OutputStream *ost; - ost = new_output_stream(mux, o, AVMEDIA_TYPE_SUBTITLE, source_index); + ost = new_output_stream(mux, o, AVMEDIA_TYPE_SUBTITLE, ist); st = ost->st; if (ost->enc_ctx) { @@ -816,8 +816,8 @@ static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, OutputStream *ost; switch (ofilter->type) { - case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(mux, o, -1); break; - case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(mux, o, -1); break; + case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(mux, o, NULL); break; + case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(mux, o, NULL); break; default: av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported " "currently.\n"); @@ -854,8 +854,8 @@ static void init_output_filter(OutputFilter *ofilter, const OptionsContext *o, static void map_auto_video(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; - InputStream *ist; - int best_score = 0, idx = -1; + InputStream *best_ist = NULL; + int best_score = 0; int qcr; /* video: highest resolution */ @@ -865,10 +865,11 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0); for (int j = 0; j < nb_input_files; j++) { InputFile *ifile = input_files[j]; - int file_best_score = 0, file_best_idx = -1; + InputStream *file_best_ist = NULL; + int file_best_score = 0; for (int i = 0; i < ifile->nb_streams; i++) { + InputStream *ist = ifile->streams[i]; int score; - ist = input_streams[ifile->ist_index + i]; if (ist->user_set_discard == AVDISCARD_ALL || ist->st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) @@ -884,27 +885,28 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) continue; file_best_score = score; - file_best_idx = ifile->ist_index + i; + file_best_ist = ist; } } - if (file_best_idx >= 0) { - if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) - file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT); + if (file_best_ist) { + if((qcr == MKTAG('A', 'P', 'I', 'C')) || + !(file_best_ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)) + file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT); if (file_best_score > best_score) { best_score = file_best_score; - idx = file_best_idx; + best_ist = file_best_ist; } } } - if (idx >= 0) - new_video_stream(mux, o, idx); + if (best_ist) + new_video_stream(mux, o, best_ist); } static void map_auto_audio(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; - InputStream *ist; - int best_score = 0, idx = -1; + InputStream *best_ist = NULL; + int best_score = 0; /* audio: most channels */ if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_AUDIO) == AV_CODEC_ID_NONE) @@ -912,10 +914,11 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) for (int j = 0; j < nb_input_files; j++) { InputFile *ifile = input_files[j]; - int file_best_score = 0, file_best_idx = -1; + InputStream *file_best_ist = NULL; + int file_best_score = 0; for (int i = 0; i < ifile->nb_streams; i++) { + InputStream *ist = ifile->streams[i]; int score; - ist = input_streams[ifile->ist_index + i]; if (ist->user_set_discard == AVDISCARD_ALL || ist->st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) @@ -926,19 +929,19 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT); if (score > file_best_score) { file_best_score = score; - file_best_idx = ifile->ist_index + i; + file_best_ist = ist; } } - if (file_best_idx >= 0) { - file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT); + if (file_best_ist) { + file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT); if (file_best_score > best_score) { best_score = file_best_score; - idx = file_best_idx; + best_ist = file_best_ist; } } } - if (idx >= 0) - new_audio_stream(mux, o, idx); + if (best_ist) + new_audio_stream(mux, o, best_ist); } static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) @@ -951,15 +954,15 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name) return; - for (int i = 0; i < nb_input_streams; i++) - if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { AVCodecDescriptor const *input_descriptor = - avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id); + avcodec_descriptor_get(ist->st->codecpar->codec_id); AVCodecDescriptor const *output_descriptor = NULL; AVCodec const *output_codec = avcodec_find_encoder(oc->oformat->subtitle_codec); int input_props = 0, output_props = 0; - if (input_streams[i]->user_set_discard == AVDISCARD_ALL) + if (ist->user_set_discard == AVDISCARD_ALL) continue; if (output_codec) output_descriptor = avcodec_descriptor_get(output_codec->id); @@ -973,7 +976,7 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) input_descriptor && output_descriptor && (!input_descriptor->props || !output_descriptor->props)) { - new_subtitle_stream(mux, o, i); + new_subtitle_stream(mux, o, ist); break; } } @@ -984,12 +987,16 @@ static void map_auto_data(Muxer *mux, const OptionsContext *o) AVFormatContext *oc = mux->fc; /* Data only if codec id match */ enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_DATA); - for (int i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) { - if (input_streams[i]->user_set_discard == AVDISCARD_ALL) + + if (codec_id == AV_CODEC_ID_NONE) + return; + + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { + if (ist->user_set_discard == AVDISCARD_ALL) continue; - if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA - && input_streams[i]->st->codecpar->codec_id == codec_id ) - new_data_stream(mux, o, i); + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA && + ist->st->codecpar->codec_id == codec_id ) + new_data_stream(mux, o, ist); } } @@ -1023,9 +1030,7 @@ loop_end: } init_output_filter(ofilter, o, mux); } else { - int src_idx = input_files[map->file_index]->ist_index + map->stream_index; - - ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index]; + ist = input_files[map->file_index]->streams[map->stream_index]; if (ist->user_set_discard == AVDISCARD_ALL) { av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n", map->file_index, map->stream_index); @@ -1041,14 +1046,14 @@ loop_end: return; switch (ist->st->codecpar->codec_type) { - case AVMEDIA_TYPE_VIDEO: new_video_stream (mux, o, src_idx); break; - case AVMEDIA_TYPE_AUDIO: new_audio_stream (mux, o, src_idx); break; - case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (mux, o, src_idx); break; - case AVMEDIA_TYPE_DATA: new_data_stream (mux, o, src_idx); break; - case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(mux, o, src_idx); break; + case AVMEDIA_TYPE_VIDEO: new_video_stream (mux, o, ist); break; + case AVMEDIA_TYPE_AUDIO: new_audio_stream (mux, o, ist); break; + case AVMEDIA_TYPE_SUBTITLE: new_subtitle_stream (mux, o, ist); break; + case AVMEDIA_TYPE_DATA: new_data_stream (mux, o, ist); break; + case AVMEDIA_TYPE_ATTACHMENT: new_attachment_stream(mux, o, ist); break; case AVMEDIA_TYPE_UNKNOWN: if (copy_unknown_streams) { - new_unknown_stream (mux, o, src_idx); + new_unknown_stream (mux, o, ist); break; } default: @@ -1096,7 +1101,7 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o) avio_read(pb, attachment, len); memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); - ost = new_attachment_stream(mux, o, -1); + ost = new_attachment_stream(mux, o, NULL); ost->attachment_filename = o->attachments[i]; ost->st->codecpar->extradata = attachment; ost->st->codecpar->extradata_size = len; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 61aa0be0ab..a9dcf0e088 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -417,7 +417,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i], *p == ':' ? p + 1 : p) <= 0) continue; - if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) { + if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) { disabled = 1; continue; } @@ -523,7 +523,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) if (allow_unused = strchr(mapchan, '?')) *allow_unused = 0; if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels || - input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) { + input_files[m->file_idx]->streams[m->stream_idx]->user_set_discard == AVDISCARD_ALL) { if (allow_unused) { av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n", m->file_idx, m->stream_idx, m->channel_idx); From patchwork Thu Nov 17 10:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39318 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997652pzb; Thu, 17 Nov 2022 02:18:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZzA1BDaVVzVSYuuHcdj4fWxEvddoddPEQg+R0owlI72kkSpp9RqMBYD3Ur93qQrXTlyvv X-Received: by 2002:a05:6402:2987:b0:45c:a9d3:d535 with SMTP id eq7-20020a056402298700b0045ca9d3d535mr1595590edb.0.1668680286403; Thu, 17 Nov 2022 02:18:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680286; cv=none; d=google.com; s=arc-20160816; b=qHnCMIH4VrxVayOmhFTGOuDo3ZYOXOEJmSqJo+l4iSsE213htrQ56iZs775DXbm3Q3 jlxTSTgNQGsKtzz5cdXd4c6wP5z7G1QsegyCx5Kx7kmCm0GAe9n9IW+wzVBv8/XYm5Kd SESSvOGqj07TnEhaeRHc1BB3FscjDWjTBkZ5xaS7dC5ByyuOmjvyAb6rxwpPcWRV1Yje NFgYMNZQcFFvUMdY+kftIGENkFlZ5+ZnBVtZoaqLV91vNCWiZzsFYitvqaVDxaYS1u2V pn1mzRMnHQeu4DYntRv4963lt6+up1IOYaJUVFoRGHD5mm3gyNx/jh41Ouef7x/9ecXA ClWw== 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:delivered-to; bh=OIkxyKuAZf9kwRRcOjLYApGDnBOOv3daghxmk7FHiaQ=; b=gXhsRO7+++u+tIGoq/up/kbuCdndMP3D9VDcuJPDzbWWLsWHKt9WuzrEpFsGTc/Dr5 JOJof3MBc8GkT00IvSsC8LJHAwzEC98yzCAq/6DJiUHIbZTHm5EN8nu4C+fKCIQAQnwH Lj8LpKzYunMNpKMNFYQTBL0UuPHxU0Ajfom21qhBG0D33KzW/459bS3f3SJM0bPMBNJA I8sVmtnPSTh/Ku6uzI1qpMKL6kbdsKPYiV2qenGQcK07ob3T9bJEIXmzYft0r7IDDA+H 1Gi4ZcftKH8GZo0FX9gyIF4sBv2AND1M9/3WZwcb215Is9s/Z0QzgQM1gckCnN75pDv3 UydQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o10-20020a056402038a00b00467c3cbab04si524848edv.66.2022.11.17.02.18.05; Thu, 17 Nov 2022 02:18:06 -0800 (PST) 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; 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 7908D68BDE8; Thu, 17 Nov 2022 12:16:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CAD9F68BD8D for ; Thu, 17 Nov 2022 12:16:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 25D122406C7 for ; Thu, 17 Nov 2022 11:16:48 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ApeI_oI6KsQi for ; Thu, 17 Nov 2022 11:16:47 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 719192406CC for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3DC043A0656 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:37 +0100 Message-Id: <20221117101640.6789-7-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/10] fftools/ffmpeg: do not assume input streams exist 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: YtdpCBSt7B58 There can be zero input streams, with input provided by lavfi complex filtergraphs. --- fftools/ffmpeg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0944f56b80..c43c3ca3bc 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3401,7 +3401,11 @@ static int check_keyboard_interaction(int64_t cur_time) if (key == 'd' || key == 'D'){ int debug=0; if(key == 'D') { - debug = ist_iter(NULL)->dec_ctx->debug << 1; + InputStream *ist = ist_iter(NULL); + + if (ist) + debug = ist->dec_ctx->debug << 1; + if(!debug) debug = 1; while (debug & FF_DEBUG_DCT_COEFF) //unsupported, would just crash debug += debug; From patchwork Thu Nov 17 10:16:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39317 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997593pzb; Thu, 17 Nov 2022 02:17:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XjQ0Ginov3zkSLWkxWckuPqttKP7G+GNz9TdNBwFfPFDbyROLnMp5KcVGrlLW+rT0XMoq X-Received: by 2002:a05:6402:d6a:b0:467:6dbf:e3e8 with SMTP id ec42-20020a0564020d6a00b004676dbfe3e8mr1543669edb.291.1668680277674; Thu, 17 Nov 2022 02:17:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680277; cv=none; d=google.com; s=arc-20160816; b=m636X2eeOdsZIaw/UeXsQya399t5IUFiEMNMgReNWRv8/Rxdx6JmL8knBlwRM6maIy Y2TVRHHyUkYJBo+tO+HLcj4GmzSq+Wjjl35PKoVRHbcmb5hU5mp2mtDWCqxXJVEx5lMu wl2mjJ/39+cL8eESawV2P04a+5Zv9ToUHUwzsbkoX3BAAmsUh7YTHRoJJ30Z8Zdc0Jnp DDU48FRQnyP3vBGHcN3HqR/1TSTNchSbjnmd7gD+fuI4mS6hSUwoKkzNSvz4fek/2D5K XkMR18XAsH77RbfODEPkgt3JdBUMGC/K2TZLYKNxc8uDR+pozXSN2ci8GYuJ9l+919wd UkCQ== 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:delivered-to; bh=n+vQAUrZYdXe8X6/08r6Kk8ZFMG7eTRnedzRNjfGVD8=; b=bqwVMCYz+huV64wttyf94YiOeNHFp1VZUsqOFm2FrQjsaAMRjQWHJHxoI42U74uOkl q+try4gm0uDQnvdeNCAkdiJws7xg5jw5mpPnCeW0zPKl41R+yW5+VuTZv6M8WcuDT+eL 7K0mgW2astzJcoNxNUF6cybibOtoamD3kZHl0tLCsU69JmygNfVk6O1iMsY20SDeYdUW nVKgsFqr0PH4X8uKdr64ePcAU14ZOqPmffRp3g4AguXtM8fXG07d/DG9Xh1lBGAya1fx ZtR7vx0S8cQeHrEH+il2l4woOTTcyeMSvQ8oM3VWhwu8KJkXcAp2pBNpuBRdNZr6bMZC dN1Q== ARC-Authentication-Results: i=1; mx.google.com; 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 n18-20020aa7c692000000b00453b9f11b56si503126edq.261.2022.11.17.02.17.57; Thu, 17 Nov 2022 02:17:57 -0800 (PST) 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; 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 7D17668BCE2; Thu, 17 Nov 2022 12:16:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C310068BD58 for ; Thu, 17 Nov 2022 12:16:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C900F2405EC for ; Thu, 17 Nov 2022 11:16:47 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lVTn-5KzDXdH for ; Thu, 17 Nov 2022 11:16:46 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 5929D2406C7 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 497EA3A02FD for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:38 +0100 Message-Id: <20221117101640.6789-8-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/10] fftools/ffmpeg: declare loop variables inside loops in transcode_init() 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: vb0bi3H9wJtD --- fftools/ffmpeg.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c43c3ca3bc..3767ab444b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3140,21 +3140,19 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, static int transcode_init(void) { - int ret = 0, i, j, k; - OutputStream *ost; - InputStream *ist; + int ret = 0; char error[1024] = {0}; /* init framerate emulation */ - for (i = 0; i < nb_input_files; i++) { + for (int i = 0; i < nb_input_files; i++) { InputFile *ifile = input_files[i]; if (ifile->readrate || ifile->rate_emu) - for (j = 0; j < ifile->nb_streams; j++) + for (int j = 0; j < ifile->nb_streams; j++) ifile->streams[j]->start = av_gettime_relative(); } /* init input streams */ - for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) if ((ret = init_input_stream(ist, error, sizeof(error))) < 0) goto dump_format; @@ -3167,7 +3165,7 @@ static int transcode_init(void) * to be configured with the correct audio frame size, which is only * known after the encoder is initialized. */ - for (ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { + for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { if (ost->enc_ctx && (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) @@ -3179,13 +3177,13 @@ static int transcode_init(void) } /* discard unused programs */ - for (i = 0; i < nb_input_files; i++) { + for (int i = 0; i < nb_input_files; i++) { InputFile *ifile = input_files[i]; - for (j = 0; j < ifile->ctx->nb_programs; j++) { + for (int j = 0; j < ifile->ctx->nb_programs; j++) { AVProgram *p = ifile->ctx->programs[j]; int discard = AVDISCARD_ALL; - for (k = 0; k < p->nb_stream_indexes; k++) + for (int k = 0; k < p->nb_stream_indexes; k++) if (!ifile->streams[p->stream_index[k]]->discard) { discard = AVDISCARD_DEFAULT; break; @@ -3197,8 +3195,8 @@ static int transcode_init(void) dump_format: /* dump the stream mapping */ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); - for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { - for (j = 0; j < ist->nb_filters; j++) { + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { + for (int j = 0; j < ist->nb_filters; j++) { if (!filtergraph_is_simple(ist->filters[j]->graph)) { av_log(NULL, AV_LOG_INFO, " Stream #%d:%d (%s) -> %s", ist->file_index, ist->st->index, ist->dec ? ist->dec->name : "?", @@ -3210,7 +3208,7 @@ static int transcode_init(void) } } - for (ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { + for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { if (ost->attachment_filename) { /* an attached file */ av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n", From patchwork Thu Nov 17 10:16:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39315 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997465pzb; Thu, 17 Nov 2022 02:17:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7G9q1b2cBwQz81Dwc3Fc7bX8TNYgQXoWZURD/rfYP3ojfRR0B22yDn8CZ0hsrkIeuJgNKQ X-Received: by 2002:a17:906:2804:b0:78d:e7c0:a2b with SMTP id r4-20020a170906280400b0078de7c00a2bmr1586662ejc.273.1668680259891; Thu, 17 Nov 2022 02:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680259; cv=none; d=google.com; s=arc-20160816; b=EERsnS+zWXgZ/TrE9XjZcs55UYWlEhb3atpFmtQpuff1ZnRvaomoijVfSeS7CGYQOp AqYikzv+7nBTlVsNXwzISehCbeUH3Z3mwlBDRJ4FraRvjgFSDKImClritD3mJuqb64c4 HS76J+t4VCZ7KRTrpmR+LHYhDSRD1T1p0+fOve6t41PN4r6G9JcbhQDgW1GCQp7keSfk n7L60vWqEQkeZTYq+u808PzE6pgAgxL89L26Hta8P8YNFOt5UIRd4Ka9psXDqNhjBoND 3OOuW74wse2XxNAoS82EOp4F7Y2Ilo5foZ9owXPnIHsLUbZxR5XAirBCeXC4xJEvzmUO efPQ== 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:delivered-to; bh=XU0bsJ3N5rSi5ERTZG39sZ9eohBcDYtowXvaiYpXrhI=; b=ZhwyuYz4R67OrLsNh8TtSvWjbdRSg8+UEl4ra8lj0ko6xXMHkn3i3H3AVjOSu+PYsM OFXyOzo1ZiMaJvZ9wSnxpcd3JHSLgsfvMaD1N1hP8qXcVrdKqa062oqpvbqGEwQ+xjlO cCI4n37qhVrZquMXvFkIEV2buft9ce52RhXmJzSBPVOvPlmVX+kqwXRWVclOnNbUCuA6 soza0SPv8kRnYDltgXFO8/rKNc5Bsgw2qOuXvVV2VAqfa0RUo637JbKzrYbl7yEsAtrA /5DY+SdnG7Nx5oBvFrWPO0wh3eLou+QE4wxTzW3aAqVU95mdFLv8K+w3Fm/Vzqcnf3o3 V14w== ARC-Authentication-Results: i=1; mx.google.com; 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 qc24-20020a170906d8b800b007ae8a4b03d7si186738ejb.973.2022.11.17.02.17.39; Thu, 17 Nov 2022 02:17:39 -0800 (PST) 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; 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 8385268BD07; Thu, 17 Nov 2022 12:16:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44D1568BD58 for ; Thu, 17 Nov 2022 12:16:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2C7CF2404F7 for ; Thu, 17 Nov 2022 11:16:47 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id a_63r-PJvr1a for ; Thu, 17 Nov 2022 11:16:46 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 629BD2406CA for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5505C3A01E5 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:39 +0100 Message-Id: <20221117101640.6789-9-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg: _-prefix variables in MATCH_PER_STREAM_OPT() 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: SNzG0MgA6vHU Avoids conflicts, e.g. when 'i' is used in the outvar expression. --- fftools/ffmpeg.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5fc3b2d3d4..5cae266600 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -783,26 +783,26 @@ InputStream *ist_iter(InputStream *prev); {\ char namestr[128] = "";\ const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\ - for (i = 0; opt_name_##name[i]; i++)\ - av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\ + for (int _i = 0; opt_name_##name[_i]; _i++)\ + av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[_i], opt_name_##name[_i+1] ? (opt_name_##name[_i+2] ? ", " : " or ") : "");\ av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\ namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\ } #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ {\ - int i, ret, matches = 0;\ + int _ret, _matches = 0;\ SpecifierOpt *so;\ - for (i = 0; i < o->nb_ ## name; i++) {\ - char *spec = o->name[i].specifier;\ - if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\ - outvar = o->name[i].u.type;\ - so = &o->name[i];\ - matches++;\ - } else if (ret < 0)\ + for (int _i = 0; _i < o->nb_ ## name; _i++) {\ + char *spec = o->name[_i].specifier;\ + if ((_ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\ + outvar = o->name[_i].u.type;\ + so = &o->name[_i];\ + _matches++;\ + } else if (_ret < 0)\ exit_program(1);\ }\ - if (matches > 1)\ + if (_matches > 1)\ WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\ } From patchwork Thu Nov 17 10:16:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39319 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp997703pzb; Thu, 17 Nov 2022 02:18:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gmKrrRUl10qG4wqSKAFLaEv3P7idjd9wDa+GVvvCrYirWE9hPHlNtjalSvk3NAgJ1Ghfa X-Received: by 2002:aa7:cc08:0:b0:461:8a43:e93 with SMTP id q8-20020aa7cc08000000b004618a430e93mr1440033edt.275.1668680294603; Thu, 17 Nov 2022 02:18:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668680294; cv=none; d=google.com; s=arc-20160816; b=X9qBJAyjPtqVV96YDJadlJO8H/MJVU+GJUHbrJsu+or8qdItfUTuinXCuwAFHqU136 FaxkiBtYedJPJQEO5Kl4J8olaHPcLo1toxvQ3OQJph4VrSu68YVL3KCIuE/xewe8D9a3 sKPx54g2N3zASnLfxDnzi8AWmImasT2HzXmE9TrpTEjZ5o085yUOWsnAe9CiBU2O+sEO mgWhJwjYbPWHCbT5yiFCXBZzSotd85wE4jEz0bO6JRPNg4FRNYeeNqo5NL4znaP4z+r6 5Cy70SR+T4bNfC1czeD+9DISfbz/TQuE8LwcVK2thUve1wWpVD5+QcKq/Sx1jaDN4sv/ UMDQ== 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:delivered-to; bh=fPQi812QD9bSrl/2b19M0l0lIrrmxQ0sYrHwdgkGomk=; b=qnKzOLidFcn1Tq4NfpVD9lyD8TO6+oYcVu2hOdBnXXZ7B+Z5bmu/FIHjOXmU0KEs0O fYwHwkEcrrlP7sJAMAunQWs8/Y8p9KfwMnyWnnCqEiX3VPLwbCVS7qLQmtWelZ1eYMK5 lnbudJ5y52w9lf1QaoP6o1P2OOfqDW2Hossq/Sg8TT02eewT4QgKeW9sHw76bOwBL3rr efwBHeKj1QEZVtXyDxA3/2q3RLn4SeGJIQK08sZr3idpLUrE63WmWxdYAbEXzrhHl+65 QquCooT0g/4G0TO+t7h0Mcfn1vcXzTYOGMjLRGg8jOal7Q00ftWANLJz2XRcsc6HRGe7 vqRw== ARC-Authentication-Results: i=1; mx.google.com; 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 17-20020a170906059100b0078df19995e4si189057ejn.241.2022.11.17.02.18.14; Thu, 17 Nov 2022 02:18:14 -0800 (PST) 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; 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 5223368BDFF; Thu, 17 Nov 2022 12:17:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 579B368BDA1 for ; Thu, 17 Nov 2022 12:16:50 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EC2E92406CA for ; Thu, 17 Nov 2022 11:16:48 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id gfM4JURM9T-U for ; Thu, 17 Nov 2022 11:16:47 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id 6E14D2406CB for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5FFA43A0520 for ; Thu, 17 Nov 2022 11:16:43 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Nov 2022 11:16:40 +0100 Message-Id: <20221117101640.6789-10-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221117101640.6789-1-anton@khirnov.net> References: <20221117101640.6789-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/10] fftools/ffmpeg_mux_init: postpone matching -disposition to streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HCx2U06r+CKQ Do it in set_dispositions() rather than during stream creation. Since at this point all other stream information is known, this allows setting disposition based on metadata, which implements #10015. This also avoids an extra allocated string in OutputStream that was unused after of_open(). --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 1 - fftools/ffmpeg_mux_init.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5cae266600..4b76b1d0d7 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -585,7 +585,6 @@ typedef struct OutputStream { int streamcopy_started; int copy_initial_nonkeyframes; int copy_prior_start; - char *disposition; int keep_pix_fmt; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index ad04f5049d..2b885f7ab0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -673,7 +673,6 @@ static void ost_free(OutputStream **post) av_freep(&ost->logfile_prefix); av_freep(&ost->forced_kf_pts); av_freep(&ost->apad); - av_freep(&ost->disposition); #if FFMPEG_OPT_MAP_CHANNEL av_freep(&ost->audio_channels_map); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b6782b49aa..7aa2e030d8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -333,9 +333,6 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } - MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st); - ost->disposition = av_strdup(ost->disposition); - ms->max_muxing_queue_size = 128; MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ms->max_muxing_queue_size, oc, st); @@ -1667,11 +1664,21 @@ static void copy_meta(Muxer *mux, const OptionsContext *o) } } -static int set_dispositions(OutputFile *of, AVFormatContext *ctx) +static int set_dispositions(Muxer *mux, const OptionsContext *o) { + OutputFile *of = &mux->of; + AVFormatContext *ctx = mux->fc; + int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; int have_default[AVMEDIA_TYPE_NB] = { 0 }; int have_manual = 0; + int ret = 0; + + const char **dispositions; + + dispositions = av_calloc(ctx->nb_streams, sizeof(*dispositions)); + if (!dispositions) + return AVERROR(ENOMEM); // first, copy the input dispositions for (int i = 0; i < ctx->nb_streams; i++) { @@ -1679,7 +1686,9 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) nb_streams[ost->st->codecpar->codec_type]++; - have_manual |= !!ost->disposition; + MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); + + have_manual |= !!dispositions[i]; if (ost->ist) { ost->st->disposition = ost->ist->st->disposition; @@ -1693,25 +1702,25 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) // process manually set dispositions - they override the above copy for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - int ret; + const char *disp = dispositions[i]; - if (!ost->disposition) + if (!disp) continue; #if LIBAVFORMAT_VERSION_MAJOR >= 60 - ret = av_opt_set(ost->st, "disposition", ost->disposition, 0); + ret = av_opt_set(ost->st, "disposition", disp, 0); #else { const AVClass *class = av_stream_get_class(); const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); av_assert0(o); - ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition); + ret = av_opt_eval_flags(&class, o, disp, &ost->st->disposition); } #endif if (ret < 0) - return ret; + goto finish; } } else { // For each media type with more than one stream, find a suitable stream to @@ -1730,7 +1739,10 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx) } } - return 0; +finish: + av_freep(&dispositions); + + return ret; } static void validate_enc_avopt(const Muxer *mux, const AVDictionary *codec_avopt) @@ -1943,7 +1955,7 @@ int of_open(const OptionsContext *o, const char *filename) of_add_programs(oc, o); of_add_metadata(of, oc, o); - err = set_dispositions(of, oc); + err = set_dispositions(mux, o); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error setting output stream dispositions\n"); exit_program(1);