From patchwork Sun May 28 09:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41854 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987291pzb; Sun, 28 May 2023 02:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YrEiRFj85OMMmDZKjmFdol57rqJvV8D/n1icH+24iWTkhrsMz8J7BNblQkpsX8EonTjO9 X-Received: by 2002:a17:907:7f0c:b0:96f:44b0:b3b7 with SMTP id qf12-20020a1709077f0c00b0096f44b0b3b7mr9374326ejc.7.1685265344648; Sun, 28 May 2023 02:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265344; cv=none; d=google.com; s=arc-20160816; b=Uoi1plTaaMIwQZUZi8L//FArCw87xVQd4nDjvUVRluNeHJq4rBFF/tjxCGw1IfpY72 sS7ZDUqcdUCm2p4NR9w/0d1Dhjot8qnwbshbjjW0hbas4Mf1edn2P8w2jOCx6YSAJADL n9sf4DcA4ROMseEjKKUE2w/Sq8p8c39fVi9udtIy15A203kGrYTwTkehZP2z03FrsX8J iUGyrzuLsQnY1o8O3tFbt97LVBR7YfTo2szfLrIePYiPcK4pzlsIEahUC0mEMkC0a67o bjCgjqRHZpNXJlqiISlcbnNntoZEhdare2KPICw9LW+qyYsPCAKEd9nW5BLUzZUW0cNB REnQ== 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=1xWBu8g0QoLWrt30F0rYvqr8XFkBDKkXew525IF3q9Y=; b=PA8TlNqhbr5CsbrTnj5AE9JrSU4VHq6fdeORDiwz5oN8ri2I/BmtrnvMeLSEZ1MvfR vaTeVUVRYHfmsBYFx5rPYd3DCTld5HvMeiK+zxRK2zKZMnc/rgUEwEJv9ScAONs8zY8s begtnVrKIj529MBoswCef66dJJbqepmWecX9QEa6JF1m8npjbEHOnZeRtgJ0hs5hJ+4u loUuLB5NegffgUF9jivMax9o9DrPugfqQ1/lmEctbleQYaDk+kglwNfLbtrJMkoJjetW N+N2PdUGxyS6FBi2T0owc79GLcuFQiuhwof/fpI59uC4en+MgaPjgk61jg3KbVDmGGv4 mEPg== 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 ku5-20020a170907788500b0094ed5083927si1274140ejc.426.2023.05.28.02.15.44; Sun, 28 May 2023 02:15:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 8F6DF68C230; Sun, 28 May 2023 12:15:00 +0300 (EEST) 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 7970E68C1E6 for ; Sun, 28 May 2023 12:14:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3F53F2404EC for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zhNb0JchKMRf for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) 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 71E03240177 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 112BE3A01C0 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:53 +0200 Message-Id: <20230528091416.17927-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/24] fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: j5opB//vDxfx This way ost_add() knows about the complex filtergraph it is fed from, which will become useful in future commits. --- fftools/ffmpeg_mux_init.c | 71 ++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 7878789bb4..de39b360af 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -985,7 +985,8 @@ fail: } static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, - enum AVMediaType type, InputStream *ist) + enum AVMediaType type, InputStream *ist, + OutputFilter *ofilter) { AVFormatContext *oc = mux->fc; MuxStream *ms; @@ -1040,6 +1041,14 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, av_strlcat(ms->log_name, "/", sizeof(ms->log_name)); av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name)); } else { + if (ofilter) { + av_log(ost, AV_LOG_ERROR, + "Streamcopy requested for output stream fed " + "from a complex filtergraph. Filtering and streamcopy " + "cannot be used together.\n"); + exit_program(1); + } + av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name)); } @@ -1233,22 +1242,26 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, exit_program(1); } - if (ost->ist) { - if (ost->enc && - (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + if (ost->enc && + (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { + if (ofilter) { + ost->filter = ofilter; + ofilter->ost = ost; + avfilter_inout_free(&ofilter->out_tmp); + } else { ret = init_simple_filtergraph(ost->ist, ost); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error initializing a simple filtergraph\n"); exit_program(1); } - } else { - ret = ist_output_add(ost->ist, ost); - if (ret < 0) { - av_log(ost, AV_LOG_ERROR, - "Error binding an input stream\n"); - exit_program(1); - } + } + } else if (ost->ist) { + ret = ist_output_add(ost->ist, ost); + if (ret < 0) { + av_log(ost, AV_LOG_ERROR, + "Error binding an input stream\n"); + exit_program(1); } } @@ -1261,26 +1274,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, return ost; } -// add a new output stream fed by the provided filtergraph output -static void ost_add_from_filter(OutputFilter *ofilter, const OptionsContext *o, - Muxer *mux) -{ - OutputStream *ost = ost_add(mux, o, ofilter->type, NULL); - - ost->filter = ofilter; - - ofilter->ost = ost; - - if (!ost->enc_ctx) { - av_log(ost, AV_LOG_ERROR, "Streamcopy requested for output stream fed " - "from a complex filtergraph. Filtering and streamcopy " - "cannot be used together.\n"); - exit_program(1); - } - - avfilter_inout_free(&ofilter->out_tmp); -} - static void map_auto_video(Muxer *mux, const OptionsContext *o) { AVFormatContext *oc = mux->fc; @@ -1329,7 +1322,7 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o) } } if (best_ist) - ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL); } static void map_auto_audio(Muxer *mux, const OptionsContext *o) @@ -1371,7 +1364,7 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o) } } if (best_ist) - ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist); + ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL); } static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) @@ -1406,7 +1399,7 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o) input_descriptor && output_descriptor && (!input_descriptor->props || !output_descriptor->props)) { - ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist); + ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist, NULL); break; } } @@ -1426,7 +1419,7 @@ static void map_auto_data(Muxer *mux, const OptionsContext *o) continue; if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA && ist->st->codecpar->codec_id == codec_id ) - ost_add(mux, o, AVMEDIA_TYPE_DATA, ist); + ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL); } } @@ -1458,7 +1451,7 @@ loop_end: "in any defined filter graph, or was already used elsewhere.\n", map->linklabel); exit_program(1); } - ost_add_from_filter(ofilter, o, mux); + ost_add(mux, o, ofilter->type, NULL, ofilter); } else { ist = input_files[map->file_index]->streams[map->stream_index]; if (ist->user_set_discard == AVDISCARD_ALL) { @@ -1490,7 +1483,7 @@ loop_end: return; } - ost_add(mux, o, ist->st->codecpar->codec_type, ist); + ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL); } } @@ -1524,7 +1517,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 = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL); + ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL); ost->attachment_filename = o->attachments[i]; ost->par_in->extradata = attachment; ost->par_in->extradata_size = len; @@ -1557,7 +1550,7 @@ static void create_streams(Muxer *mux, const OptionsContext *o) case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break; case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break; } - ost_add_from_filter(ofilter, o, mux); + ost_add(mux, o, ofilter->type, NULL, ofilter); } } From patchwork Sun May 28 09:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41853 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987186pzb; Sun, 28 May 2023 02:15:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pFsqqSZDgs7pF1chFDuIOMrvAcZWcWzM1hTILZJG6/nvtrwcwhjZ1GJ+Kx4ULfPHp3WgE X-Received: by 2002:a17:907:8a22:b0:94a:5819:5a2b with SMTP id sc34-20020a1709078a2200b0094a58195a2bmr9488750ejc.33.1685265334917; Sun, 28 May 2023 02:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265334; cv=none; d=google.com; s=arc-20160816; b=Yp5e/mQUOa9OkBXn6Gfc4UmOkNzX1Iu1q7G7/EEUCOuPhnHKPJMOeNMcGrwNvTz2By VnIKxEkr5m736jqjAREsxT9nD6/0D1xV3PxoUaoTCHhm/WWubXgRYVUdxq/XL4qLtL7r hXJk2cftORlbNsMyN+WYhkhSqZ6bMFt1ouw1JRpkJ/lN4xzfh7cRX8HEJSe4tsKRPpTN 40/NyC0PMu63TnwO5gO/FglglGz40bKdY0dkDdHnJiLgTK8Lrb+xCd2DhzB1fmN368Eq 9Ezh8/0x+App22OMCSEJHLTyNqxl4VlAANvDMpZ/bmt97rOBa72XQKfbgJ5Zg9+DxydI nRDA== 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=2dVYnru5W/X3FQWEfn4KL06XOqIcnnk4Smmxmg0F84Q=; b=n5W1MilxYvJOAzvKq04BpdXKC8vmuw6NhRWN0P6aRI0G76DkA2cuYHtBtLa9pUCSqR fGQFBcwbirVRUgILuC+WIC8pjk7z5KTSWw/PtgzWjxkAyM029GxlwhtC1R56STac9NYd wIKDV1vPvaoq9G7IvRrd2xnG5Cjdul8dapwtzmdbKy+3YXSvFIstKDGiza7AYgw30U/+ G2Ih5ML/hjeoxXrka5dy3Qxj5IHBo15L86M7G4hAXkxu8WuzdDMuwlK7BDU9NbeIU+OE n8OBzSNZDZEp7pWs+9G5ila3RJARvqQuurYXy4X27QJFK7wlNWSMDyw3pMgXBKt3D54W QiOQ== 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 tc1-20020a1709078d0100b00965cb6510f5si2197277ejc.6.2023.05.28.02.15.34; Sun, 28 May 2023 02:15:34 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 7BA9468C226; Sun, 28 May 2023 12:14:59 +0300 (EEST) 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 3F89E68C1E6 for ; Sun, 28 May 2023 12:14:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 041262404F5 for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 8EhrpgB2Hr8J for ; Sun, 28 May 2023 11:14:49 +0200 (CEST) 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 798C42404EC for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1E3F83A03F3 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:54 +0200 Message-Id: <20230528091416.17927-2-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/24] fftools/ffmpeg: add logging for creating output streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: G6eomrOHbK++ --- fftools/ffmpeg_mux_init.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index de39b360af..033e55d76e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1052,6 +1052,19 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name)); } + av_log(ost, AV_LOG_VERBOSE, "Created %s stream from ", + av_get_media_type_string(type)); + if (ist) + av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d", + ist->file_index, ist->index); + else if (ofilter) + av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n", + ofilter->graph->index, ofilter->name); + else if (type == AVMEDIA_TYPE_ATTACHMENT) + av_log(ost, AV_LOG_VERBOSE, "attached file"); + else av_assert0(0); + av_log(ost, AV_LOG_VERBOSE, "\n"); + ost->pkt = av_packet_alloc(); if (!ost->pkt) report_and_exit(AVERROR(ENOMEM)); @@ -1451,6 +1464,10 @@ loop_end: "in any defined filter graph, or was already used elsewhere.\n", map->linklabel); exit_program(1); } + + av_log(mux, AV_LOG_VERBOSE, "Creating output stream from an explicitly " + "mapped complex filtergraph %d, output [%s]\n", fg->index, map->linklabel); + ost_add(mux, o, ofilter->type, NULL, ofilter); } else { ist = input_files[map->file_index]->streams[map->stream_index]; @@ -1517,6 +1534,9 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o) avio_read(pb, attachment, len); memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE); + av_log(mux, AV_LOG_VERBOSE, "Creating attachment stream from file %s\n", + o->attachments[i]); + ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL); ost->attachment_filename = o->attachments[i]; ost->par_in->extradata = attachment; @@ -1550,11 +1570,21 @@ static void create_streams(Muxer *mux, const OptionsContext *o) case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break; case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break; } + + av_log(mux, AV_LOG_VERBOSE, "Creating output stream from unlabeled " + "output of complex filtergraph %d.", fg->index); + if (!o->nb_stream_maps) + av_log(mux, AV_LOG_VERBOSE, " This overrides automatic %s mapping.", + av_get_media_type_string(ofilter->type)); + av_log(mux, AV_LOG_VERBOSE, "\n"); + ost_add(mux, o, ofilter->type, NULL, ofilter); } } if (!o->nb_stream_maps) { + av_log(mux, AV_LOG_VERBOSE, "No explicit maps, mapping streams automatically...\n"); + /* pick the "best" stream of each type */ if (!auto_disable_v) map_auto_video(mux, o); @@ -1565,6 +1595,8 @@ static void create_streams(Muxer *mux, const OptionsContext *o) if (!auto_disable_d) map_auto_data(mux, o); } else { + av_log(mux, AV_LOG_VERBOSE, "Adding streams from explicit maps...\n"); + for (int i = 0; i < o->nb_stream_maps; i++) map_manual(mux, o, &o->stream_maps[i]); } From patchwork Sun May 28 09:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41850 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp986698pzb; Sun, 28 May 2023 02:15:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rgdBfqF3AwirgIU787f+M16t1X8wMY1BChtcu0CrNee0lDwfSRuD563NVNqIO3Tq5MICs X-Received: by 2002:aa7:c495:0:b0:510:ef30:b593 with SMTP id m21-20020aa7c495000000b00510ef30b593mr5589872edq.11.1685265301142; Sun, 28 May 2023 02:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265301; cv=none; d=google.com; s=arc-20160816; b=enYfZF+LysuY3nu7v3p9rOZ3WVJ/eA7mkvhqHSgvHBz999pKTymLc1xUxCJjyJOxnf DwdtMRL8eb4dbRJxOwABfhVUoFFQAw49unCZ0K5+5VZQjjY8CdOp/h2+a7gxn5xR46Ud L1WdT5YjGe+/s/usIKbFpTRNBnERm0aIaqu+Vdk/YwBAN4Yp7YNtV5BkwRThwi4cKSdY wj+2sP7jjRXHKjArho+nTWLjYfJVJAbdZJk6YoTNGgsThKesSyIsh16MlgZN+A3B4Z7t trMngw4KEhk68kouEUx5vO+VQXqFq53vOMnXfawaeHceRhURgj8sEFayhMHl4XKOnvbP EEMw== 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=5//evQcQIinBH7iohRH6ocSEmbjA2Ht5DsBG57QbyHc=; b=K/8TE5/Witqg0WO3Yybr4qf1PkDra+p7SH3skHFOUfutiVP6i8sELgRDkBNz9jHo09 79Blp9Y+g9V699xU6M0I+U+77st9BVb5AmmOfDH020MRVJYMYIUfMpx0Yd8A0wZGDobp p3y010WDtIwSFCbuL3YiURxC7GcbtzJdMz6Ncw5gkvKQpw2WK+sAF+f0EVygI4QuVPoh ehXopDTgmmUkTaK2ZS3mobqpbTmGDaHG5Ete27dHFgj2lW2V0+cwiP1Cjs2v8lT9J9hi MDu90ng+waszfsIsv/NcTD3+A/ZDXYHErcqBqkoqoHh09lyf57Xq3Dqx+BW9K+5lf1Wh wi4Q== 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 t18-20020aa7d4d2000000b0050bc27dd649si2798393edr.616.2023.05.28.02.15.00; Sun, 28 May 2023 02:15:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 2CE3268C1E5; Sun, 28 May 2023 12:14:55 +0300 (EEST) 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 C502D68B947 for ; Sun, 28 May 2023 12:14:48 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 17A10240D1E for ; Sun, 28 May 2023 11:14:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id kNqK6YxJOYAG for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) 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 7B1D82404EE for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 294753A04D0 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:55 +0200 Message-Id: <20230528091416.17927-3-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/24] fftools/ffmpeg_filter: use a dedicated variable for marking simple filtergraphs 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: fR7ejatyU/vZ Do not use an unrelated graph property, which will change in future commits. --- fftools/ffmpeg_filter.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index f37b867b31..e11ae2e9bf 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -41,6 +41,8 @@ typedef struct FilterGraphPriv { FilterGraph fg; + int is_simple; + const char *graph_desc; // frame for temporarily holding output from the filtergraph @@ -353,6 +355,7 @@ FilterGraph *fg_create(char *graph_desc) int init_simple_filtergraph(InputStream *ist, OutputStream *ost) { FilterGraph *fg; + FilterGraphPriv *fgp; OutputFilter *ofilter; InputFilter *ifilter; int ret; @@ -360,6 +363,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) fg = fg_create(NULL); if (!fg) report_and_exit(AVERROR(ENOMEM)); + fgp = fgp_from_fg(fg); + + fgp->is_simple = 1; ofilter = ofilter_alloc(fg); ofilter->ost = ost; @@ -1474,7 +1480,7 @@ int ifilter_has_all_input_formats(FilterGraph *fg) int filtergraph_is_simple(FilterGraph *fg) { FilterGraphPriv *fgp = fgp_from_fg(fg); - return !fgp->graph_desc; + return fgp->is_simple; } int reap_filters(int flush) From patchwork Sun May 28 09:13:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41852 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987074pzb; Sun, 28 May 2023 02:15:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5k9jjR12GUkaQcM6J4dmH3jMenTl3H10LNNRjPobd3I+XKCwwMeSQkFUm/+tzw4rbTPPr4 X-Received: by 2002:a17:907:26c3:b0:969:e9ec:9a0 with SMTP id bp3-20020a17090726c300b00969e9ec09a0mr6802606ejc.77.1685265324311; Sun, 28 May 2023 02:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265324; cv=none; d=google.com; s=arc-20160816; b=BOparcvHm/Z4/5RGui6QEx91UOZPFwQ4fSUHMkslbVW31fVACncP0COmZB6lzWqJKY dyI+bAIQFvTRZE2cr2J7QgOWct4snnLnQkBVtDsw5I4iqNCbMIWWTB9I3x2vbAxh7tPu df5YG5nAY8YFB9xPjNcjxgwOQjOnYC9OuHegvk8wbAsbktXz2DKLsfM+wNxBnXtS69DU IeBZorJM9l8ppStSm2GXALvmumHNIV7Vdo6aMHt7I8M74hsT5LuROIfIeipH9QOKzM4K YBgyf0cwIxXEVN21datmOptvMIgXUqEWuusoJahna6FRq+ndeojPO/FeiLqz4fu2vZcL mRGQ== 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=PuPZzwKXi6vFzIOI/43mV/yoyWmIDfhXQbigz6Wp64k=; b=t1CVPUG9g3gwP1pEJanW6+h+oDslpFpiz17paB/Tq+ubODYFAANzpHAqfnOfjMXEy/ koR+rHOukm0w9545zp/ZieaXo2cf01pbzHztVlpgTvRLRQ3lo95aikLNmrlZD5Iu5qBD V92HH/h8bypvnnlrQW4CYrGnz6kl4JUvUgBdWA9i+8xX1PUWCMwZLbwJdpBwmWU+FLUI 6jZBjRtp4BKsf1zWtBZrpvOfcA9yLayBb7Hvm3V67Acw0vcBlYjwVcgGSpjNIkFe0j64 YsGhfnnmFdBqh0Ij+mcyE7CwzewN0cKPzGjQlmOCgMbZ8Da2FN31JBczfJRnhab2TLte 1MXw== 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 w18-20020a170906131200b009537f63f002si3813093ejb.779.2023.05.28.02.15.23; Sun, 28 May 2023 02:15:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 5F32168C212; Sun, 28 May 2023 12:14:58 +0300 (EEST) 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 9279868C1DE for ; Sun, 28 May 2023 12:14:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5B4EE240591 for ; Sun, 28 May 2023 11:14:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id OhJQYJhwyMUl for ; Sun, 28 May 2023 11:14:48 +0200 (CEST) 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 7CECE2404F5 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 34C123A0570 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:56 +0200 Message-Id: <20230528091416.17927-4-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/24] fftools/ffmpeg_filter: always pass graph description to fg_create() 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: /pn1aTlpifYU Currently NULL would be passed for simple filtergraphs, which would make the filter code extract the graph description from the output stream when needed. This is unnecessarily convoluted. --- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_filter.c | 8 ++++---- fftools/ffmpeg_mux.c | 1 - fftools/ffmpeg_mux_init.c | 16 ++++++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 95334825ef..1bb9125bf2 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -590,7 +590,6 @@ typedef struct OutputStream { FILE *logfile; OutputFilter *filter; - char *avfilter; AVDictionary *encoder_opts; AVDictionary *sws_dict; @@ -737,7 +736,8 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id int configure_filtergraph(FilterGraph *fg); void check_filter_outputs(void); int filtergraph_is_simple(FilterGraph *fg); -int init_simple_filtergraph(InputStream *ist, OutputStream *ost); +int init_simple_filtergraph(InputStream *ist, OutputStream *ost, + char *graph_desc); int init_complex_filtergraph(FilterGraph *fg); void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e11ae2e9bf..75317139ba 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -352,7 +352,8 @@ FilterGraph *fg_create(char *graph_desc) return fg; } -int init_simple_filtergraph(InputStream *ist, OutputStream *ost) +int init_simple_filtergraph(InputStream *ist, OutputStream *ost, + char *graph_desc) { FilterGraph *fg; FilterGraphPriv *fgp; @@ -360,7 +361,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) InputFilter *ifilter; int ret; - fg = fg_create(NULL); + fg = fg_create(graph_desc); if (!fg) report_and_exit(AVERROR(ENOMEM)); fgp = fgp_from_fg(fg); @@ -1263,8 +1264,7 @@ int configure_filtergraph(FilterGraph *fg) AVBufferRef *hw_device; AVFilterInOut *inputs, *outputs, *cur; int ret, i, simple = filtergraph_is_simple(fg); - const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter : - fgp->graph_desc; + const char *graph_desc = fgp->graph_desc; cleanup_filtergraph(fg); if (!(fg->graph = avfilter_graph_alloc())) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 36ed482072..3da3c04d7f 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -853,7 +853,6 @@ static void ost_free(OutputStream **post) av_freep(&ost->kf.pts); av_expr_free(ost->kf.pexpr); - av_freep(&ost->avfilter); av_freep(&ost->logfile_prefix); av_freep(&ost->apad); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 033e55d76e..1c97804ec8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -432,7 +432,7 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) } static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, - OutputStream *ost) + OutputStream *ost, char **dst) { const char *filters = NULL, *filters_script = NULL; @@ -470,12 +470,12 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, } if (filters_script) - ost->avfilter = file_read(filters_script); + *dst = file_read(filters_script); else if (filters) - ost->avfilter = av_strdup(filters); + *dst = av_strdup(filters); else - ost->avfilter = av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull"); - return ost->avfilter ? 0 : AVERROR(ENOMEM); + *dst = av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull"); + return *dst ? 0 : AVERROR(ENOMEM); } static void parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str) @@ -995,7 +995,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, AVStream *st = avformat_new_stream(oc, NULL); int ret = 0; const char *bsfs = NULL, *time_base = NULL; - char *next, *codec_tag = NULL; + char *filters = NULL, *next, *codec_tag = NULL; double qscale = -1; int i; @@ -1250,7 +1250,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, } if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) { - ret = ost_get_filters(o, oc, ost); + ret = ost_get_filters(o, oc, ost, &filters); if (ret < 0) exit_program(1); } @@ -1262,7 +1262,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, ofilter->ost = ost; avfilter_inout_free(&ofilter->out_tmp); } else { - ret = init_simple_filtergraph(ost->ist, ost); + ret = init_simple_filtergraph(ost->ist, ost, filters); if (ret < 0) { av_log(ost, AV_LOG_ERROR, "Error initializing a simple filtergraph\n"); From patchwork Sun May 28 09:13:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41864 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988113pzb; Sun, 28 May 2023 02:17:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kzHs+N70iLAQ+sno/s7Hurc3M6s6v2mefFp35tKYXvhg/UJ71mhkolid6pc46/uFS52bH X-Received: by 2002:a05:6402:b31:b0:510:dae0:2c3f with SMTP id bo17-20020a0564020b3100b00510dae02c3fmr4987191edb.37.1685265437553; Sun, 28 May 2023 02:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265437; cv=none; d=google.com; s=arc-20160816; b=KnRRIG9TIJa6A7WvBuMpAt1J5XCiuTBnJr1uSvmD+8LeV5947rmU8BjFxn8ENO7RUD dKYlIz4KTi+q0PLPp91fvLh1YGTrqqIKYhcDo1rTyax5NBWJtji4U/neYJueR7/K4mJp EYwSoq+fRz9RA2Tvd027cBR6gL+WAisCAkiDSQmeb9oK3WXI4RWZlctVPPdkupiseJlZ esfFzqJlJONIP2tGE3x8gBL48gj6YYbUa8dJsaTxXLHW1SAq7p/Nzn3cRPh6qWd6dbeQ afnSYrhNxwB5rI8Z4/uxYaGhy1OfTqir/IY59vgqSxHxpdoWqq0uwphAoNCQg//1r3qC 0W5A== 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=UHGlTC4ax9IpZdkI6iU46DMPbTT/hku3HVk2mLorpVs=; b=oREgF7UlAmkV3VoTHHYYdsfZhvv/S04fPRejAbJ88BGVylm1aPmyoZAJ8vrPxZy+rg D11m+pAtK5/vTDzkGHmLxfGJyLPS/IwCM+W0gVTuZWylLLDKr1NNKK0tz0CimTogrgMv H9h5jSGQ4DZGXiUGJQl/SuF9rECbN3w5oNT/QFiFjsQzDhojbpn4QQksCzazR4QnUnOs 2MP6R5JVGzZVQC6e+J15SgPh2memY2hJI2Q/0o9uBMzi075bHxgK2Se/bUtVEJAfeHZ+ cHxewCoplKn0MZ6f8TDhqrVdrmnjW4Tu4/xk5ccf+X7PEBJDfL9xdRWgHtwjnS1itghK t8EA== 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 m3-20020a50ef03000000b005060bdc3b1dsi2892863eds.83.2023.05.28.02.17.17; Sun, 28 May 2023 02:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 0564768C20F; Sun, 28 May 2023 12:15:11 +0300 (EEST) 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 0A1E668C20C for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 95B78240177 for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id MG7zbMQnxJlo for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) 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 810B72404F8 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3FB1C3A0586 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:57 +0200 Message-Id: <20230528091416.17927-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/24] fftools/ffmpeg_filter: store just the link label in OutputFilter 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: urfNBtrpx+Jj Not the entire AVFilterInOut. This is simpler. --- fftools/ffmpeg.h | 6 ++++-- fftools/ffmpeg_filter.c | 8 +++++--- fftools/ffmpeg_mux_init.c | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1bb9125bf2..3aa19c7f5f 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -289,8 +289,10 @@ typedef struct OutputFilter { struct FilterGraph *graph; uint8_t *name; - /* temporary storage until stream maps are processed */ - AVFilterInOut *out_tmp; + /* for filters that are not yet bound to an output stream, + * this stores the output linklabel, if any */ + uint8_t *linklabel; + enum AVMediaType type; /* desired output stream properties */ diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 75317139ba..323e63b829 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -324,7 +324,7 @@ void fg_free(FilterGraph **pfg) for (int j = 0; j < fg->nb_outputs; j++) { OutputFilter *ofilter = fg->outputs[j]; - avfilter_inout_free(&ofilter->out_tmp); + av_freep(&ofilter->linklabel); av_freep(&ofilter->name); av_channel_layout_uninit(&ofilter->ch_layout); av_freep(&fg->outputs[j]); @@ -661,16 +661,18 @@ int init_complex_filtergraph(FilterGraph *fg) for (cur = outputs; cur;) { OutputFilter *const ofilter = ofilter_alloc(fg); - ofilter->out_tmp = cur; + ofilter->linklabel = cur->name; + cur->name = NULL; + ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, cur->pad_idx); ofilter->name = describe_filter_link(fg, cur, 0); cur = cur->next; - ofilter->out_tmp->next = NULL; } fail: avfilter_inout_free(&inputs); + avfilter_inout_free(&outputs); avfilter_graph_free(&graph); return ret; } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 1c97804ec8..f7a24feec7 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1260,7 +1260,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, if (ofilter) { ost->filter = ofilter; ofilter->ost = ost; - avfilter_inout_free(&ofilter->out_tmp); + av_freep(&ofilter->linklabel); } else { ret = init_simple_filtergraph(ost->ist, ost, filters); if (ret < 0) { @@ -1451,8 +1451,8 @@ static void map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map for (j = 0; j < nb_filtergraphs; j++) { fg = filtergraphs[j]; for (k = 0; k < fg->nb_outputs; k++) { - AVFilterInOut *out = fg->outputs[k]->out_tmp; - if (out && !strcmp(out->name, map->linklabel)) { + const char *linklabel = fg->outputs[k]->linklabel; + if (linklabel && !strcmp(linklabel, map->linklabel)) { ofilter = fg->outputs[k]; goto loop_end; } @@ -1562,7 +1562,7 @@ static void create_streams(Muxer *mux, const OptionsContext *o) for (int j = 0; j < fg->nb_outputs; j++) { OutputFilter *ofilter = fg->outputs[j]; - if (!ofilter->out_tmp || ofilter->out_tmp->name) + if (ofilter->linklabel || ofilter->ost) continue; switch (ofilter->type) { From patchwork Sun May 28 09:13:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41851 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp986958pzb; Sun, 28 May 2023 02:15:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VNDy5jYp1b6b4Wysv0v9uurE/54mOJBzVlLpJuJvG2UQECvJ/fectCCp1WNUWYPRA/diU X-Received: by 2002:a17:907:ea7:b0:966:eb8:2f12 with SMTP id ho39-20020a1709070ea700b009660eb82f12mr7826296ejc.11.1685265314233; Sun, 28 May 2023 02:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265314; cv=none; d=google.com; s=arc-20160816; b=kafDUtl62OkgwF6dy0u1ry8fvc0FaQ+cybd8w7w+BAlWW1h9fhV2XCctqrn+IU6xAx 0wfI3tKiQ5XiH6hV27aCpj9ypLpkapTK2Nh4JuMiwvL/9pmCKVZk2+f+w7QsdqXMommY sBriUaovQCLiy3e53MCTsW1JUYeQQp4nNaMHTDmImkolqtB7inY9+dRuYI6QuZ7tIiXl 2DSeINH1QmEcpAPQfQZBZecZunkYgTagiwKsT6TopTYdGmfZIwJfAAp4/oq37c2zVgVg Qqx4dj5iRxCXkptffnwZ6WyGmW2SDM30wvi+n352UBRZ03B+AYUWjUhdgIFzBGlysKlk pxUw== 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=6qbBISLDavPLuQoFiXdPMs5GsY0TbFoDSKS4o3yX9zk=; b=Cor5aFrK2Glq1JjchlBW0itzUOlmAUgbmuGiOfM7kVHQz1UGOA383SYPFiJSpNjSvz cEuaazpiq+vuJYLeWy2X3Uinnrkgi+UpHQ/bi8KDhaM/3xkztPHvAqZn73GNSu30we2d 1ytYn6DUYFLoVvc1USQxsPYOma3f1Qmpx1/KGBBQkm7tWqF/Sa2z/IN0ba4bU5hF3Qj0 /lZc27fzoeZz1xdwRyPuCt2oJ1nA7wLhwhpJnsA0fQpRGtjJ8/jwxTaBv+YiuYgODqSN q4qk8tFl8dCOW5add6rbl2tFEybvCP3FwCJwIE6Pok9qnV82ZtGloIy1BRhbaTxt743t Q7qg== 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 tb18-20020a1709078b9200b0094ee8363c98si2470441ejc.427.2023.05.28.02.15.13; Sun, 28 May 2023 02:15:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 6AF2568C1DC; Sun, 28 May 2023 12:14:56 +0300 (EEST) 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 E247368BFEB for ; Sun, 28 May 2023 12:14:48 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id AB2282404EE for ; Sun, 28 May 2023 11:14:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id qw5ebllcNNTn for ; Sun, 28 May 2023 11:14:48 +0200 (CEST) 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 84955240591 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4B82E3A058B for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:58 +0200 Message-Id: <20230528091416.17927-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/24] fftools/ffmpeg_filter: decouple allocating InputFilter and binding it 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: LX3Z0+Gynr72 Will be useful in future commits. --- fftools/ffmpeg_filter.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 323e63b829..a8c4ef321f 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -258,7 +258,24 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg) return ofilter; } -static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist) +static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) +{ + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + int ret; + + ret = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph)); + if (ret < 0) + return ret; + + ifp->ist = ist; + ifp->type_src = ist->st->codecpar->codec_type; + ifp->type = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ? + AVMEDIA_TYPE_VIDEO : ifp->type_src; + + return 0; +} + +static InputFilter *ifilter_alloc(FilterGraph *fg) { InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), &fg->nb_inputs); @@ -272,10 +289,6 @@ static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist) ifp->format = -1; ifp->fallback.format = -1; - ifp->ist = ist; - ifp->type_src = ist->st->codecpar->codec_type; - ifp->type = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ? - AVMEDIA_TYPE_VIDEO : ifp->type_src; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -373,9 +386,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, ost->filter = ofilter; - ifilter = ifilter_alloc(fg, ist); + ifilter = ifilter_alloc(fg); - ret = ist_filter_add(ist, ifilter, 1); + ret = ifilter_bind_ist(ifilter, ist); if (ret < 0) return ret; @@ -455,10 +468,10 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) } av_assert0(ist); - ifilter = ifilter_alloc(fg, ist); + ifilter = ifilter_alloc(fg); ifilter->name = describe_filter_link(fg, in, 1); - ret = ist_filter_add(ist, ifilter, 0); + ret = ifilter_bind_ist(ifilter, ist); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error binding an input stream to complex filtergraph input %s.\n", From patchwork Sun May 28 09:13:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41857 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987566pzb; Sun, 28 May 2023 02:16:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jfbjgT5+hIf+DCNycQpH/E86nQA4lX7v7MaG4/v4ifceDfxdmLDIPOpYoAR8uIkBj9dkZ X-Received: by 2002:a17:907:843:b0:965:a72a:b2ae with SMTP id ww3-20020a170907084300b00965a72ab2aemr6835312ejb.60.1685265373671; Sun, 28 May 2023 02:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265373; cv=none; d=google.com; s=arc-20160816; b=ut8JwZVBtT2f1Ap8MdcRlYybnJ3hNkOAaUxZAZgpxfO3z3kF8k66XSJQRQtqB6Ph/Z QOJDT8Nhpfq4fLlkVWw9RtkNWzN8fnIt89NLoK8zoAvvX7v3ddjKJ4FTYtG5LaKEyw4k Sqjh6zAPcBDb6SSrV7FogAAlYz94OYRl8hLynA8htKVTYdCFf9AbuSwXoCSdAdDvWHvO GIKdsEuwlggsd2HMBvdtsp3QGsg9VVY5PvXDuve+V97/vAyxj87DOfh23uZM6C8ToM8s DXe0aUbxipcg9hH/JhVy2WTuYHKauzOyjSdIb7UTrtrx9Q48/dr4R0wvdHXHB5gvc5DH e6lA== 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=zsORcgjGTEee7/O9ohU6jMTlkzg27llffBFRa+jXBHU=; b=TixDkm8QOywEoNQrzmCEpppS1CbhNtHi36/AmFvsv2+2BTbhziFoevOKbATR9EEQSu U7vSrDGMDtTBIkK/9PLoKJqIb9OO9N8ChxyMKWseVozL6upt+mi219C55fvfduQg3AlA D/rE6zLgvd1W+WFNWwY5+nUCutapGCQZNZTSKbEJThvKrveVriDIHcgTtoc3ozpiY+V6 WlkjnLYbYhPUrFW4TNr0F0DqFXHF0BBCqTkLSNzK/5b/FJDFaynDTUPoBoqOxjpVqz/l uvkwiKJSFp5wRarDyOBz/iTC+Tkefb8Ri2Zz4ztkndxZlv2RlyEutSqpXAsd8+brvpm1 f8GQ== 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 p19-20020a17090653d300b00973839f677csi681100ejo.514.2023.05.28.02.16.13; Sun, 28 May 2023 02:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 9609268C23C; Sun, 28 May 2023 12:15:03 +0300 (EEST) 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 2A62968C1ED for ; Sun, 28 May 2023 12:14:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D3D4C2404F5 for ; Sun, 28 May 2023 11:14:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id VTlIrjLzUsFf for ; Sun, 28 May 2023 11:14:53 +0200 (CEST) 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 A91252406CB for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 570033A05CB for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:13:59 +0200 Message-Id: <20230528091416.17927-7-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/24] fftools/ffmpeg_filter: move some functions higher up 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: yIYPpSqK9WIK Needed by the following commit. --- fftools/ffmpeg_filter.c | 374 ++++++++++++++++++++-------------------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index a8c4ef321f..5169a3ca82 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -246,6 +246,193 @@ static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint) av_bprint_chars(bprint, ':', 1); } +static int read_binary(const char *path, uint8_t **data, int *len) +{ + AVIOContext *io = NULL; + int64_t fsize; + int ret; + + *data = NULL; + *len = 0; + + ret = avio_open2(&io, path, AVIO_FLAG_READ, &int_cb, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Cannot open file '%s': %s\n", + path, av_err2str(ret)); + return ret; + } + + fsize = avio_size(io); + if (fsize < 0 || fsize > INT_MAX) { + av_log(NULL, AV_LOG_ERROR, "Cannot obtain size of file %s\n", path); + ret = AVERROR(EIO); + goto fail; + } + + *data = av_malloc(fsize); + if (!*data) { + ret = AVERROR(ENOMEM); + goto fail; + } + + ret = avio_read(io, *data, fsize); + if (ret != fsize) { + av_log(NULL, AV_LOG_ERROR, "Error reading file %s\n", path); + ret = ret < 0 ? ret : AVERROR(EIO); + goto fail; + } + + *len = fsize; + + ret = 0; +fail: + avio_close(io); + if (ret < 0) { + av_freep(data); + *len = 0; + } + return ret; +} + +static int filter_opt_apply(AVFilterContext *f, const char *key, const char *val) +{ + const AVOption *o = NULL; + int ret; + + ret = av_opt_set(f, key, val, AV_OPT_SEARCH_CHILDREN); + if (ret >= 0) + return 0; + + if (ret == AVERROR_OPTION_NOT_FOUND && key[0] == '/') + o = av_opt_find(f, key + 1, NULL, 0, AV_OPT_SEARCH_CHILDREN); + if (!o) + goto err_apply; + + // key is a valid option name prefixed with '/' + // interpret value as a path from which to load the actual option value + key++; + + if (o->type == AV_OPT_TYPE_BINARY) { + uint8_t *data; + int len; + + ret = read_binary(val, &data, &len); + if (ret < 0) + goto err_load; + + ret = av_opt_set_bin(f, key, data, len, AV_OPT_SEARCH_CHILDREN); + av_freep(&data); + } else { + char *data = file_read(val); + if (!data) { + ret = AVERROR(EIO); + goto err_load; + } + + ret = av_opt_set(f, key, data, AV_OPT_SEARCH_CHILDREN); + av_freep(&data); + } + if (ret < 0) + goto err_apply; + + return 0; + +err_apply: + av_log(NULL, AV_LOG_ERROR, + "Error applying option '%s' to filter '%s': %s\n", + key, f->filter->name, av_err2str(ret)); + return ret; +err_load: + av_log(NULL, AV_LOG_ERROR, + "Error loading value for option '%s' from file '%s'\n", + key, val); + return ret; +} + +static int graph_opts_apply(AVFilterGraphSegment *seg) +{ + for (size_t i = 0; i < seg->nb_chains; i++) { + AVFilterChain *ch = seg->chains[i]; + + for (size_t j = 0; j < ch->nb_filters; j++) { + AVFilterParams *p = ch->filters[j]; + const AVDictionaryEntry *e = NULL; + + av_assert0(p->filter); + + while ((e = av_dict_iterate(p->opts, e))) { + int ret = filter_opt_apply(p->filter, e->key, e->value); + if (ret < 0) + return ret; + } + + av_dict_free(&p->opts); + } + } + + return 0; +} + +static int graph_parse(AVFilterGraph *graph, const char *desc, + AVFilterInOut **inputs, AVFilterInOut **outputs, + AVBufferRef *hw_device) +{ + AVFilterGraphSegment *seg; + int ret; + + *inputs = NULL; + *outputs = NULL; + + ret = avfilter_graph_segment_parse(graph, desc, 0, &seg); + if (ret < 0) + return ret; + + ret = avfilter_graph_segment_create_filters(seg, 0); + if (ret < 0) + goto fail; + + if (hw_device) { + for (int i = 0; i < graph->nb_filters; i++) { + AVFilterContext *f = graph->filters[i]; + + if (!(f->filter->flags & AVFILTER_FLAG_HWDEVICE)) + continue; + f->hw_device_ctx = av_buffer_ref(hw_device); + if (!f->hw_device_ctx) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + } + + ret = graph_opts_apply(seg); + if (ret < 0) + goto fail; + + ret = avfilter_graph_segment_apply(seg, 0, inputs, outputs); + +fail: + avfilter_graph_segment_free(&seg); + return ret; +} + +static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) +{ + AVFilterContext *ctx = inout->filter_ctx; + AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; + int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; + char *res; + + if (nb_pads > 1) + res = av_strdup(ctx->filter->name); + else + res = av_asprintf("%s:%s", ctx->filter->name, + avfilter_pad_get_name(pads, inout->pad_idx)); + if (!res) + report_and_exit(AVERROR(ENOMEM)); + return res; +} + static OutputFilter *ofilter_alloc(FilterGraph *fg) { OutputFilter *ofilter; @@ -395,23 +582,6 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, return 0; } -static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) -{ - AVFilterContext *ctx = inout->filter_ctx; - AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; - int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; - char *res; - - if (nb_pads > 1) - res = av_strdup(ctx->filter->name); - else - res = av_asprintf("%s:%s", ctx->filter->name, - avfilter_pad_get_name(pads, inout->pad_idx)); - if (!res) - report_and_exit(AVERROR(ENOMEM)); - return res; -} - static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) { FilterGraphPriv *fgp = fgp_from_fg(fg); @@ -480,176 +650,6 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) } } -static int read_binary(const char *path, uint8_t **data, int *len) -{ - AVIOContext *io = NULL; - int64_t fsize; - int ret; - - *data = NULL; - *len = 0; - - ret = avio_open2(&io, path, AVIO_FLAG_READ, &int_cb, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Cannot open file '%s': %s\n", - path, av_err2str(ret)); - return ret; - } - - fsize = avio_size(io); - if (fsize < 0 || fsize > INT_MAX) { - av_log(NULL, AV_LOG_ERROR, "Cannot obtain size of file %s\n", path); - ret = AVERROR(EIO); - goto fail; - } - - *data = av_malloc(fsize); - if (!*data) { - ret = AVERROR(ENOMEM); - goto fail; - } - - ret = avio_read(io, *data, fsize); - if (ret != fsize) { - av_log(NULL, AV_LOG_ERROR, "Error reading file %s\n", path); - ret = ret < 0 ? ret : AVERROR(EIO); - goto fail; - } - - *len = fsize; - - ret = 0; -fail: - avio_close(io); - if (ret < 0) { - av_freep(data); - *len = 0; - } - return ret; -} - -static int filter_opt_apply(AVFilterContext *f, const char *key, const char *val) -{ - const AVOption *o = NULL; - int ret; - - ret = av_opt_set(f, key, val, AV_OPT_SEARCH_CHILDREN); - if (ret >= 0) - return 0; - - if (ret == AVERROR_OPTION_NOT_FOUND && key[0] == '/') - o = av_opt_find(f, key + 1, NULL, 0, AV_OPT_SEARCH_CHILDREN); - if (!o) - goto err_apply; - - // key is a valid option name prefixed with '/' - // interpret value as a path from which to load the actual option value - key++; - - if (o->type == AV_OPT_TYPE_BINARY) { - uint8_t *data; - int len; - - ret = read_binary(val, &data, &len); - if (ret < 0) - goto err_load; - - ret = av_opt_set_bin(f, key, data, len, AV_OPT_SEARCH_CHILDREN); - av_freep(&data); - } else { - char *data = file_read(val); - if (!data) { - ret = AVERROR(EIO); - goto err_load; - } - - ret = av_opt_set(f, key, data, AV_OPT_SEARCH_CHILDREN); - av_freep(&data); - } - if (ret < 0) - goto err_apply; - - return 0; - -err_apply: - av_log(NULL, AV_LOG_ERROR, - "Error applying option '%s' to filter '%s': %s\n", - key, f->filter->name, av_err2str(ret)); - return ret; -err_load: - av_log(NULL, AV_LOG_ERROR, - "Error loading value for option '%s' from file '%s'\n", - key, val); - return ret; -} - -static int graph_opts_apply(AVFilterGraphSegment *seg) -{ - for (size_t i = 0; i < seg->nb_chains; i++) { - AVFilterChain *ch = seg->chains[i]; - - for (size_t j = 0; j < ch->nb_filters; j++) { - AVFilterParams *p = ch->filters[j]; - const AVDictionaryEntry *e = NULL; - - av_assert0(p->filter); - - while ((e = av_dict_iterate(p->opts, e))) { - int ret = filter_opt_apply(p->filter, e->key, e->value); - if (ret < 0) - return ret; - } - - av_dict_free(&p->opts); - } - } - - return 0; -} - -static int graph_parse(AVFilterGraph *graph, const char *desc, - AVFilterInOut **inputs, AVFilterInOut **outputs, - AVBufferRef *hw_device) -{ - AVFilterGraphSegment *seg; - int ret; - - *inputs = NULL; - *outputs = NULL; - - ret = avfilter_graph_segment_parse(graph, desc, 0, &seg); - if (ret < 0) - return ret; - - ret = avfilter_graph_segment_create_filters(seg, 0); - if (ret < 0) - goto fail; - - if (hw_device) { - for (int i = 0; i < graph->nb_filters; i++) { - AVFilterContext *f = graph->filters[i]; - - if (!(f->filter->flags & AVFILTER_FLAG_HWDEVICE)) - continue; - f->hw_device_ctx = av_buffer_ref(hw_device); - if (!f->hw_device_ctx) { - ret = AVERROR(ENOMEM); - goto fail; - } - } - } - - ret = graph_opts_apply(seg); - if (ret < 0) - goto fail; - - ret = avfilter_graph_segment_apply(seg, 0, inputs, outputs); - -fail: - avfilter_graph_segment_free(&seg); - return ret; -} - int init_complex_filtergraph(FilterGraph *fg) { FilterGraphPriv *fgp = fgp_from_fg(fg); From patchwork Sun May 28 09:14:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41871 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988583pzb; Sun, 28 May 2023 02:18:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6J5ejeYLIh77JaxD5ef4x+Ln3DRBHIrOp/8D4qLjelvMrA3A0Z8NzkbTgJ9cC5kpVKhs6Y X-Received: by 2002:aa7:d5d7:0:b0:504:9349:7901 with SMTP id d23-20020aa7d5d7000000b0050493497901mr4472521eds.38.1685265498015; Sun, 28 May 2023 02:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265498; cv=none; d=google.com; s=arc-20160816; b=p5M10jdPAxuiH8eh4x3in3+wFAY2YaQYPVt7eQmXPeGRAqFI5WhIQ/qTf7xVjrXh17 pqp+/Ybw0SRQbGZENdG1I/fmiscb/A/cKP89lLCjHRSg9dC/VAwyzpyMGRlKlR2ssm9s 6IDCdcZTRRv4zws0/NRD3M4sdcXahFi8stpi1tMCldPUAqnDZjm3ITu8e3S5rrbak8WV lg/PpCQ4eSK6rFI9qjrnOTtJ0O3yRGj6BbRrnr/87OFRNXNeq2AUXldW8iE6T5jmvE0x vzORP9MXRf3WFw6VKJ5yht0wRL1i++o0ScpBmWIijQgJc2AEQob9v9+3qBiazR23oNcl +Njg== 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=u6JT75+9fkuNknJi4U1awuetxeSpX7Ac/dG3/X6Nsaw=; b=GDX8LgRtK/vC+1OMixIE9It1cz5af0LKJ/9Gu4fkgPNjbPUK8dS7RhDlLwbYjJAwH8 VWkr5psrnq7+Owdw3wCPU9ntSUVKTNVBAcoundevtsy//Q2RXdSz7dCHNj4WBUaY+JBt 8cRINjzt1QaQLYuHRSD1rf1lnRcvKo/jlvhRLaGxStGEii8/Jm0C9JQZQT9QUqg12Vk1 xKC+2h5AHTyf6o0QnYQ82274NLD5UJv3uStLnwiQIyPgbUDvgH+s/EWzjV41eyV8ONTr f6szqpKmG5yVR0UuH4gKc17ffAGfXCwsIxTJbEWGYltd4GA6azLzOc64X91YrOq/F6rJ bDpQ== 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 s10-20020aa7c54a000000b005149c0dbb07si461136edr.450.2023.05.28.02.18.17; Sun, 28 May 2023 02:18:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B888468C28B; Sun, 28 May 2023 12:15:17 +0300 (EEST) 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 D248768C22C for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0B1CD2404EE for ; Sun, 28 May 2023 11:14:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 525e_9z0nfLK for ; Sun, 28 May 2023 11:14:51 +0200 (CEST) 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 906562405B5 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 61B3A3A0664 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:00 +0200 Message-Id: <20230528091416.17927-8-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/24] fftools/ffmpeg_filter: create Input/OutputFilters together with FilterGraph 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: l7C0NPUlSTaj This way the list of filtergraph inputs/outputs is always known after FilterGraph creation. This will allow treating simple and complex filtergraphs in a more uniform manner. --- fftools/ffmpeg_filter.c | 157 +++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 83 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 5169a3ca82..d74eeef52a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -62,6 +62,10 @@ typedef struct InputFilterPriv { // used to hold submitted input AVFrame *frame; + /* for filters that are not yet bound to an input stream, + * this stores the input linklabel, if any */ + uint8_t *linklabel; + // filter data type enum AVMediaType type; // source data type: AVMEDIA_TYPE_SUBTITLE for sub2video, @@ -456,8 +460,6 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) ifp->ist = ist; ifp->type_src = ist->st->codecpar->codec_type; - ifp->type = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ? - AVMEDIA_TYPE_VIDEO : ifp->type_src; return 0; } @@ -505,7 +507,7 @@ void fg_free(FilterGraph **pfg) av_frame_free(&frame); av_fifo_freep2(&ifp->frame_queue); } - if (ist->sub2video.sub_queue) { + if (ist && ist->sub2video.sub_queue) { AVSubtitle sub; while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0) avsubtitle_free(&sub); @@ -517,6 +519,7 @@ void fg_free(FilterGraph **pfg) av_frame_free(&ifp->frame); av_buffer_unref(&ifp->hw_frames_ctx); + av_freep(&ifp->linklabel); av_freep(&ifilter->name); av_freep(&fg->inputs[j]); } @@ -542,6 +545,10 @@ FilterGraph *fg_create(char *graph_desc) FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); FilterGraph *fg = &fgp->fg; + AVFilterInOut *inputs, *outputs; + AVFilterGraph *graph; + int ret = 0; + fg->index = nb_filtergraphs - 1; fgp->graph_desc = graph_desc; @@ -549,6 +556,48 @@ FilterGraph *fg_create(char *graph_desc) if (!fgp->frame) report_and_exit(AVERROR(ENOMEM)); + /* this graph is only used for determining the kinds of inputs + * and outputs we have, and is discarded on exit from this function */ + graph = avfilter_graph_alloc(); + if (!graph) + report_and_exit(AVERROR(ENOMEM)); + graph->nb_threads = 1; + + ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL); + if (ret < 0) + goto fail; + + for (AVFilterInOut *cur = inputs; cur; cur = cur->next) { + InputFilter *const ifilter = ifilter_alloc(fg); + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + + ifp->linklabel = cur->name; + cur->name = NULL; + + ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads, + cur->pad_idx); + ifilter->name = describe_filter_link(fg, cur, 1); + } + + for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { + OutputFilter *const ofilter = ofilter_alloc(fg); + + ofilter->linklabel = cur->name; + cur->name = NULL; + + ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, + cur->pad_idx); + ofilter->name = describe_filter_link(fg, cur, 0); + } + +fail: + avfilter_inout_free(&inputs); + avfilter_inout_free(&outputs); + avfilter_graph_free(&graph); + + if (ret < 0) + report_and_exit(ret); + return fg; } @@ -557,8 +606,6 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, { FilterGraph *fg; FilterGraphPriv *fgp; - OutputFilter *ofilter; - InputFilter *ifilter; int ret; fg = fg_create(graph_desc); @@ -568,26 +615,32 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, fgp->is_simple = 1; - ofilter = ofilter_alloc(fg); - ofilter->ost = ost; + if (fg->nb_inputs != 1 || fg->nb_outputs != 1) { + av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected " + "to have exactly 1 input and 1 output. " + "However, it had %d input(s) and %d output(s). Please adjust, " + "or use a complex filtergraph (-filter_complex) instead.\n", + graph_desc, fg->nb_inputs, fg->nb_outputs); + return AVERROR(EINVAL); + } - ost->filter = ofilter; + fg->outputs[0]->ost = ost; - ifilter = ifilter_alloc(fg); + ost->filter = fg->outputs[0]; - ret = ifilter_bind_ist(ifilter, ist); + ret = ifilter_bind_ist(fg->inputs[0], ist); if (ret < 0) return ret; return 0; } -static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) +static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) { FilterGraphPriv *fgp = fgp_from_fg(fg); + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); InputStream *ist = NULL; - enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx); - InputFilter *ifilter; + enum AVMediaType type = ifp->type; int i, ret; // TODO: support other filter types @@ -597,11 +650,11 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) exit_program(1); } - if (in->name) { + if (ifp->linklabel) { AVFormatContext *s; AVStream *st = NULL; char *p; - int file_idx = strtol(in->name, &p, 0); + int file_idx = strtol(ifp->linklabel, &p, 0); if (file_idx < 0 || file_idx >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n", @@ -631,63 +684,27 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist = ist_find_unused(type); 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); + "unlabeled input pad %s\n", ifilter->name); exit_program(1); } } av_assert0(ist); - ifilter = ifilter_alloc(fg); - ifilter->name = describe_filter_link(fg, in, 1); - ret = ifilter_bind_ist(ifilter, ist); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error binding an input stream to complex filtergraph input %s.\n", - in->name ? in->name : ""); + ifilter->name); exit_program(1); } } int init_complex_filtergraph(FilterGraph *fg) { - FilterGraphPriv *fgp = fgp_from_fg(fg); - AVFilterInOut *inputs, *outputs, *cur; - AVFilterGraph *graph; - int ret = 0; - - /* this graph is only used for determining the kinds of inputs - * and outputs we have, and is discarded on exit from this function */ - graph = avfilter_graph_alloc(); - if (!graph) - return AVERROR(ENOMEM); - graph->nb_threads = 1; - - ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL); - if (ret < 0) - goto fail; - - for (cur = inputs; cur; cur = cur->next) - init_input_filter(fg, cur); - - for (cur = outputs; cur;) { - OutputFilter *const ofilter = ofilter_alloc(fg); - - ofilter->linklabel = cur->name; - cur->name = NULL; - - ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, - cur->pad_idx); - ofilter->name = describe_filter_link(fg, cur, 0); - cur = cur->next; - } - -fail: - avfilter_inout_free(&inputs); - avfilter_inout_free(&outputs); - avfilter_graph_free(&graph); - return ret; + // bind filtergraph inputs to input streams + for (int i = 0; i < fg->nb_inputs; i++) + init_input_filter(fg, fg->inputs[i]); + return 0; } static int insert_trim(int64_t start_time, int64_t duration, @@ -1324,32 +1341,6 @@ int configure_filtergraph(FilterGraph *fg) if ((ret = graph_parse(fg->graph, graph_desc, &inputs, &outputs, hw_device)) < 0) goto fail; - if (simple && (!inputs || inputs->next || !outputs || outputs->next)) { - const char *num_inputs; - const char *num_outputs; - if (!outputs) { - num_outputs = "0"; - } else if (outputs->next) { - num_outputs = ">1"; - } else { - num_outputs = "1"; - } - if (!inputs) { - num_inputs = "0"; - } else if (inputs->next) { - num_inputs = ">1"; - } else { - num_inputs = "1"; - } - av_log(NULL, AV_LOG_ERROR, "Simple filtergraph '%s' was expected " - "to have exactly 1 input and 1 output." - " However, it had %s input(s) and %s output(s)." - " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n", - graph_desc, num_inputs, num_outputs); - ret = AVERROR(EINVAL); - goto fail; - } - for (cur = inputs, i = 0; cur; cur = cur->next, i++) if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) { avfilter_inout_free(&inputs); From patchwork Sun May 28 09:14:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41856 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987462pzb; Sun, 28 May 2023 02:16:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ii7Qj6QEPj9SlFQLN+h8Xaj2CXwlj/gB/WYz8hBkEh1SPrDHHU+Xe8WkbhgGV9Y1Bw/y0 X-Received: by 2002:a17:906:9b85:b0:965:9edf:f0d0 with SMTP id dd5-20020a1709069b8500b009659edff0d0mr3722115ejc.13.1685265364202; Sun, 28 May 2023 02:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265364; cv=none; d=google.com; s=arc-20160816; b=SToHFA4C5F1wxOniVQx8GIMipK2r1luVtpd43L+Nygns/5A8L9IpzKJ/Wcgc6aV6i8 QNegRYCzDj70d62S4uBVJYebVTMv8lhHq/kenGjjdC390YoWUFeQuljPJvwaAe+hVUxX o2djentDYL0wayKEvk89Yz2ieXEpEEnHtZzWn5UmwfGGRhKIY0czxo8xDvOo9ltLFiEy 7nFhnTpZW0ieYs3At+HRrRdSzvA2idLj9oUp18DDlsxWa7BI5HY4fhGp61UWZR9Du4SE /ea+qIr6uHkYJ5OkB92v9V2CmfYefuxcQ39OQUmzCahwE8+0pzK11lxQu/dFSbBr0a+E 5pjg== 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=qFcyUdMvD6+43VNN2lJfKFW9m1K4qBbr/oMT4gD5iIk=; b=o5huEf+RRy4Q+ufi8TwbBdyUbX/KJVeFLq+l+OU4pjMl2KL13jJFRU45wc0xo3fkFH Y9/OeVkJPNJCTM2PkTkLuECZxWNv5MXj+DxBvNeUlMg5WdNmwjieBEQ98PvQRmYbPV8P t7lo2sQ0D59N6TG3p/BpclfVe2tHlQZjhpRonrSzD326RnffowSzc9yXFwHWEvrABf3W 1tnrPbm1eSIeymBGb0yegxKtg/al05TfV+iZOH1E4PBXkVOCWl3CIuSvyDoKlmmN/nyg 2PlgqXetkGWKXN/nUl3R0H5Ot9C7WR9Rw8BEzN87CZUGbXLTLud8EUU749Bq12o6mrDT LpRA== 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 k7-20020a17090632c700b0096f655876aasi140201ejk.879.2023.05.28.02.16.03; Sun, 28 May 2023 02:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 72FF168C23A; Sun, 28 May 2023 12:15:02 +0300 (EEST) 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 9B6FE68C1ED for ; Sun, 28 May 2023 12:14:55 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 593092404F5 for ; Sun, 28 May 2023 11:14:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dVfo7CSn26Yp for ; Sun, 28 May 2023 11:14:54 +0200 (CEST) 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 B2A582406CE for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6C7553A07D2 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:01 +0200 Message-Id: <20230528091416.17927-9-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/24] fftools/ffmpeg_filter: factor out binding an output stream to OutputFilter 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: PPoYqOx7zS4l While the new function is trivial for now, it will become more useful in future commits. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_filter.c | 10 ++++++++-- fftools/ffmpeg_mux_init.c | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3aa19c7f5f..8c149f1f95 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -756,6 +756,8 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) int ifilter_has_all_input_formats(FilterGraph *fg); +void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); + /** * Create a new filtergraph in the global filtergraph list. * diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d74eeef52a..5f77f1e00f 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -464,6 +464,12 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) return 0; } +void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) +{ + ofilter->ost = ost; + av_freep(&ofilter->linklabel); +} + static InputFilter *ifilter_alloc(FilterGraph *fg) { InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), @@ -624,14 +630,14 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, return AVERROR(EINVAL); } - fg->outputs[0]->ost = ost; - ost->filter = fg->outputs[0]; ret = ifilter_bind_ist(fg->inputs[0], ist); if (ret < 0) return ret; + ofilter_bind_ost(fg->outputs[0], ost); + return 0; } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index f7a24feec7..99708b9621 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1259,8 +1259,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { if (ofilter) { ost->filter = ofilter; - ofilter->ost = ost; - av_freep(&ofilter->linklabel); + ofilter_bind_ost(ofilter, ost); } else { ret = init_simple_filtergraph(ost->ist, ost, filters); if (ret < 0) { From patchwork Sun May 28 09:14:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41865 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988186pzb; Sun, 28 May 2023 02:17:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HTG+OPkA+mkptBxseBk8wNsJdn95gxfOORnUe+NyTqPXyIM6Iyw2gKvNIn0Vl1Wqaoq/7 X-Received: by 2002:a17:907:d23:b0:96f:c0b0:f137 with SMTP id gn35-20020a1709070d2300b0096fc0b0f137mr7865423ejc.16.1685265446448; Sun, 28 May 2023 02:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265446; cv=none; d=google.com; s=arc-20160816; b=CUb01WpKsjEF25n5w9LMqawezpZEBFjdJx7VuLdxaA9v7Epsdtpu/yHjxTARoyako8 nggxA2fmwEpAKbu2fLG6PEHa88kbgIHbUj81AywDVrZOMiXS/yVqmO8FQomPoFy0bJ+A asJo5kw2CBpyRzhBtx3Sbvdc65LoGuaNlT1XGpjVMCMp1OTYLZAK7fRxaCERfLE45Pdu XuHSVwHDWndue6Xw6osJlCVuyDaFiUit65GnGIEEiiMwlUnsyY14HWVuKmeUZLFu3V+O E75cOeOJ+0VK/q6gapx3rKw0pOYbu0Fz6rCLVf0RRbdSh/BH6qTtPY+ahAGLxhV89qVr cDJA== 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=uJMrA+s8YCBdedXRLfBWLeWeQGm3YYtsv7NGe0cZUfI=; b=k6likpba7n3/YYlAK+NHx9AcvaMiIQNfcQRBd5cGfbVUj6vVP8mxcvEs3g5+qCE2Mq 6e8RZnc/Lb9rTYI8PMshcZslY0Hl/wSj51vwvC+n6iVbBMuJHw1YfDaBSWZC57IuOMPJ OwMz4R95OFrERZKmLrlLBFXVhcwc76rhLcFL50Lry7e2DQVCIV2AfrVm9M/HAI2C0Jcz Zo7yRpgSPfaLO6BSVWBBZl7ECUHVlWd+O390pdbHBD18Cy33Qc/iji4aPNfXtFFs7MT2 VSibQGA+vZJwpX38oUx80Wt40jIyvChnZAVv/HTIEu1QzoOYQKDzivmDqNkozIcNrqbX GPfA== 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 hq11-20020a1709073f0b00b0096597c66573si5499619ejc.353.2023.05.28.02.17.26; Sun, 28 May 2023 02:17:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 E9E1968C22A; Sun, 28 May 2023 12:15:11 +0300 (EEST) 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 0FA9368C21C for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0DEE62404F8 for ; Sun, 28 May 2023 11:14:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id v8Guqgdpvv98 for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) 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 975322405F9 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7775E3A07F4 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:02 +0200 Message-Id: <20230528091416.17927-10-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/24] fftools/ffmpeg_mux_init: move OutputFilter setup code to ffmpeg_filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Yg4SyNQkhXQ1 That is a more appropriate place for it. --- fftools/ffmpeg_filter.c | 70 +++++++++++++++++++++++++++++++++++ fftools/ffmpeg_mux_init.c | 77 --------------------------------------- 2 files changed, 70 insertions(+), 77 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 5f77f1e00f..3f6b906468 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -464,10 +464,80 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) return 0; } +static void set_channel_layout(OutputFilter *f, OutputStream *ost) +{ + const AVCodec *c = ost->enc_ctx->codec; + int i, err; + + if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { + /* Pass the layout through for all orders but UNSPEC */ + err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout); + if (err < 0) + report_and_exit(AVERROR(ENOMEM)); + return; + } + + /* Requested layout is of order UNSPEC */ + if (!c->ch_layouts) { + /* Use the default native layout for the requested amount of channels when the + encoder doesn't have a list of supported layouts */ + av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); + return; + } + /* Encoder has a list of supported layouts. Pick the first layout in it with the + same amount of channels as the requested layout */ + for (i = 0; c->ch_layouts[i].nb_channels; i++) { + if (c->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels) + break; + } + if (c->ch_layouts[i].nb_channels) { + /* Use it if one is found */ + err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]); + if (err < 0) + report_and_exit(AVERROR(ENOMEM)); + return; + } + /* If no layout for the amount of channels requested was found, use the default + native layout for it. */ + av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); +} + void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) { + const AVCodec *c = ost->enc_ctx->codec; + ofilter->ost = ost; av_freep(&ofilter->linklabel); + + switch (ost->enc_ctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + ofilter->frame_rate = ost->frame_rate; + ofilter->width = ost->enc_ctx->width; + ofilter->height = ost->enc_ctx->height; + if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { + ofilter->format = ost->enc_ctx->pix_fmt; + } else { + ofilter->formats = c->pix_fmts; + } + break; + case AVMEDIA_TYPE_AUDIO: + if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { + ofilter->format = ost->enc_ctx->sample_fmt; + } else { + ofilter->formats = c->sample_fmts; + } + if (ost->enc_ctx->sample_rate) { + ofilter->sample_rate = ost->enc_ctx->sample_rate; + } else { + ofilter->sample_rates = c->supported_samplerates; + } + if (ost->enc_ctx->ch_layout.nb_channels) { + set_channel_layout(ofilter, ost); + } else if (c->ch_layouts) { + ofilter->ch_layouts = c->ch_layouts; + } + break; + } } static InputFilter *ifilter_alloc(FilterGraph *fg) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 99708b9621..4fc6f0fb46 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1886,44 +1886,6 @@ static void of_add_metadata(OutputFile *of, AVFormatContext *oc, } } -static void set_channel_layout(OutputFilter *f, OutputStream *ost) -{ - const AVCodec *c = ost->enc_ctx->codec; - int i, err; - - if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { - /* Pass the layout through for all orders but UNSPEC */ - err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout); - if (err < 0) - report_and_exit(AVERROR(ENOMEM)); - return; - } - - /* Requested layout is of order UNSPEC */ - if (!c->ch_layouts) { - /* Use the default native layout for the requested amount of channels when the - encoder doesn't have a list of supported layouts */ - av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); - return; - } - /* Encoder has a list of supported layouts. Pick the first layout in it with the - same amount of channels as the requested layout */ - for (i = 0; c->ch_layouts[i].nb_channels; i++) { - if (c->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels) - break; - } - if (c->ch_layouts[i].nb_channels) { - /* Use it if one is found */ - err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]); - if (err < 0) - report_and_exit(AVERROR(ENOMEM)); - return; - } - /* If no layout for the amount of channels requested was found, use the default - native layout for it. */ - av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); -} - static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, int copy_metadata) { @@ -2458,45 +2420,6 @@ int of_open(const OptionsContext *o, const char *filename) /* check if all codec options have been used */ validate_enc_avopt(mux, o->g->codec_opts); - for (int i = 0; i < of->nb_streams; i++) { - OutputStream *ost = of->streams[i]; - - /* set the filter output constraints */ - if (ost->filter) { - const AVCodec *c = ost->enc_ctx->codec; - OutputFilter *f = ost->filter; - switch (ost->enc_ctx->codec_type) { - case AVMEDIA_TYPE_VIDEO: - f->frame_rate = ost->frame_rate; - f->width = ost->enc_ctx->width; - f->height = ost->enc_ctx->height; - if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { - f->format = ost->enc_ctx->pix_fmt; - } else { - f->formats = c->pix_fmts; - } - break; - case AVMEDIA_TYPE_AUDIO: - if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { - f->format = ost->enc_ctx->sample_fmt; - } else { - f->formats = c->sample_fmts; - } - if (ost->enc_ctx->sample_rate) { - f->sample_rate = ost->enc_ctx->sample_rate; - } else { - f->sample_rates = c->supported_samplerates; - } - if (ost->enc_ctx->ch_layout.nb_channels) { - set_channel_layout(f, ost); - } else if (c->ch_layouts) { - f->ch_layouts = c->ch_layouts; - } - break; - } - } - } - /* check filename in case of an image number is expected */ if (oc->oformat->flags & AVFMT_NEEDNUMBER && !av_filename_number_test(oc->url)) { av_log(mux, AV_LOG_FATAL, From patchwork Sun May 28 09:14:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41873 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988712pzb; Sun, 28 May 2023 02:18:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48ORl3z6sq2IYKeV4bI/zWXRC10o047KGIpLAOLd3bvpQ63s2SLcV20EiveFLYg88AzsLk X-Received: by 2002:aa7:d44f:0:b0:50d:b92e:d1dc with SMTP id q15-20020aa7d44f000000b0050db92ed1dcmr5427672edr.14.1685265514918; Sun, 28 May 2023 02:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265514; cv=none; d=google.com; s=arc-20160816; b=kW9t4JqpjDXPDFaxUrkVpUy+c0ytBaIUfiw8fhilsZ07HNlVT+rChptM7HncyEMyEv x+4QwHyDOtDiPRuoqFGGD9P8MH0k21yItp8RbwbpByFZ5N5tvzQfDK4hmLyV33R/dpAF 371R2xZvbNnmfzylO5Po5Bfp8++4dlGaKxKFsOSkEY4e7NpzQ/bCi1RJ5cfYzhvHNcYa j81iGLf+FzeZllYRxn21CFUYPe0/SINHFeYe7hJBaRq8YPLSo8FG4d7ZoAoLYZqU+Sma EIkyPKOlfGb+rYtnI84unjczTcS3IUNai6nXrWkEPlLnkPN6oF+KqT+xtix/gdwgY6mQ x/3A== 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=UMaFpI0qev8wW2byvTueyaQOutBq2VFtDOT/YpR4sPo=; b=cuDwPWZaiHPJHPF82Eub323O7ARBsZ08Zs1IKwXdj6Ypx9BZi6s6JQc+znuHH1F9UM aWflCZ/ol3Tlt9Q9fLTzi+a68HWt68q4bAIw5CAgTPtx+nu8tUv901SICAKFlTokKmdu ahDIKHEgIFzGWjbKxR9TBfl1ufXfV8qOj3bZFzixVtnPhqlqWG7wu4y8+buHvCemEO+r 5Nd5oJgtN7d6RqAehHWnxAAkj4zLzXvh+zpJzcIDGHACZ9PlXRbzS9iv7u/JCNtpQSQc YUMu6yGFH5L3bHSiiTnfssch48TizhDhwxy9O9fs6eo8BRizF/jhlQYjk1+opcc1AWZI plww== 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 o6-20020a056402038600b0051478d4ec4csi3155982edv.342.2023.05.28.02.18.34; Sun, 28 May 2023 02:18:34 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 AA5BC68C294; Sun, 28 May 2023 12:15:19 +0300 (EEST) 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 1A6DE68C229 for ; Sun, 28 May 2023 12:15:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CD26E240177 for ; Sun, 28 May 2023 11:15:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LFnVowO0CvIC for ; Sun, 28 May 2023 11:14:57 +0200 (CEST) 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 D0357240D03 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 833173A082C for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:03 +0200 Message-Id: <20230528091416.17927-11-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/24] fftools/ffmpeg_filter: try to configure filtergraphs earlier 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: j2DqLjOycksg When the filtergraph has no inputs, it can be configured immediately when all its outputs are bound to output streams. This will simplify treating some corner cases. --- fftools/ffmpeg_filter.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 3f6b906468..3bf1862ab6 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -504,6 +504,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost) void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) { + FilterGraph *fg = ofilter->graph; const AVCodec *c = ost->enc_ctx->codec; ofilter->ost = ost; @@ -538,6 +539,23 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) } break; } + + // if we have all input parameters and all outputs are bound, + // the graph can now be configured + if (ifilter_has_all_input_formats(fg)) { + int ret; + + for (int i = 0; i < fg->nb_outputs; i++) + if (!fg->outputs[i]->ost) + return; + + ret = configure_filtergraph(fg); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error configuring filter graph: %s\n", + av_err2str(ret)); + exit_program(1); + } + } } static InputFilter *ifilter_alloc(FilterGraph *fg) From patchwork Sun May 28 09:14:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41861 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987850pzb; Sun, 28 May 2023 02:16:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CeLp4+ggPYhAm1kib/7FYVPU4SwcYIyVKDSjGOoWNQuFiENBkxLMWIJggybJE396SVl96 X-Received: by 2002:aa7:ce13:0:b0:510:8f8d:967e with SMTP id d19-20020aa7ce13000000b005108f8d967emr6247933edv.5.1685265410233; Sun, 28 May 2023 02:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265410; cv=none; d=google.com; s=arc-20160816; b=hqEuKfz1UWhjNdbVYFg3CPk6xl4KcQ94sEE84gum5Nbxn3fdcFe5uNiKtO8nb6dg58 6VXpA0DJgHdvzU5f2uNJ6/2LI9fkKtlXZzaadOICFfs6LoS5JCGnCiQTGHsb79h2EqN6 EowWM9cQHXb4gjLMRnfPKYwC12uDfK8i6kxG47quZCk3THiAZbs5yiI63ErCPrkMbjXP VSSHeE6EQk1ICFvgsiayv+4Vr52Ce+VyDja2+NxuQ+wgRx43WO9XNLlaJWHx6+KR2thT UfoUyKQVbh0bey2WKOLtYudIf9pjTKvDjbq21T6GSZBlh760orE2DUDcD9rlqKzzpvOL WOmQ== 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=QpokVCGumwokwuKO4KD/741acc3DqI7G4NsUrHAvk4Q=; b=lPXE1GtsAKxpRqpld8EKNZ1jBiQownMWgIjYngahVm3q70TcpUhs4mESLEwh+JDACq xDyCKQH0yXqXYMXkAB+Ly6YJOh5+HBrxLD9EfuCkIh8aOZ/TGi0g4UtbsxEynn/wjMMU KnA+roV657fNQllMWlFh3z7L0DhDmjNOFFnLj6IEOg9IegfbRxbVLIJfsVlDKorroc3L wcvd6DHnHQBUvM6XI3uaPGeepyr0WochXNRfm5C4QQ6Xn4v8oJULU4o22MhUaQc07og1 nrXIhjIDYQxpEaqxiNouEE0U5hdEbLA0UOcrXVvhPdf+2ajrsdIArWtnvRFNxybJQGiO tdtg== 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 x16-20020aa7d6d0000000b0050508e6cf5asi2991489edr.79.2023.05.28.02.16.49; Sun, 28 May 2023 02:16:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 0A3FE68C25A; Sun, 28 May 2023 12:15:08 +0300 (EEST) 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 BA09768C1F1 for ; Sun, 28 May 2023 12:14:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 87A632404F5 for ; Sun, 28 May 2023 11:14:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id roBAoruuWiTs for ; Sun, 28 May 2023 11:14:57 +0200 (CEST) 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 D0C0F240D0E for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8EE523A08D4 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:04 +0200 Message-Id: <20230528091416.17927-12-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/24] fftools/ffmpeg: constify AVSubtitle parameters as appropriate 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: AKZR9QyYpf6p --- fftools/ffmpeg.c | 5 +++-- fftools/ffmpeg.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0539a45856..9c68add0a4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -211,7 +211,8 @@ static void sub2video_push_ref(InputStream *ist, int64_t pts) } } -void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub) +void sub2video_update(InputStream *ist, int64_t heartbeat_pts, + const AVSubtitle *sub) { AVFrame *frame = ist->sub2video.frame; int8_t *dst; @@ -754,7 +755,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti first_report = 0; } -static int copy_av_subtitle(AVSubtitle *dst, AVSubtitle *src) +static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) { int ret = AVERROR_BUG; AVSubtitle tmp = { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8c149f1f95..451d18db6f 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -742,7 +742,8 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc); int init_complex_filtergraph(FilterGraph *fg); -void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub); +void sub2video_update(InputStream *ist, int64_t heartbeat_pts, + const AVSubtitle *sub); int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference); int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb); From patchwork Sun May 28 09:14:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41872 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988658pzb; Sun, 28 May 2023 02:18:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RUElezVmyhwyTrSr+7rvMPRRXyfzC3u2cqR3oL3uLVh3wM4Erwd3TMgmjA1DH5DXQMYQ0 X-Received: by 2002:a17:907:7d8f:b0:96b:e93:3aa8 with SMTP id oz15-20020a1709077d8f00b0096b0e933aa8mr8044863ejc.21.1685265506498; Sun, 28 May 2023 02:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265506; cv=none; d=google.com; s=arc-20160816; b=mpdPIsELdbngZx6E14bA8W43G4SWKPbj94cGRcG/Mx2Lgde/MvY7YRVSQcs35tvkUE 6mXFjtlnN0PCEALHQxI7QtGx/VpCr57EYHhYk6lJCKIhNgy9jw10hi/JJsaKtYmrmlIa dORMCMtcqDVDcrv3QkhaXDNl+VIsqAOtAvmtMZuVWJ8+POBxM3d/i4wX8bJT+5kznKQE P6NHGrdiW4QDW8aAaDKYZpKc7HDNs56ubjkfeR89wKsic3oTWHQsdGM/lnuhaeCWyOVa 9O352j7xm4SCBhi8Wvas63juC4qHpsiPwnRwGq70y2nHw55I6orsEkRbKef8HoxOAuQq 73aQ== 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=cw6z8JATPdB7PjNRhO4uu2ZxO3+76eiUP4/nLFMM1WM=; b=vMwp+xQ+L3lifGrXw+LqpsesWzMElPNXBPKs+IdsUcmq9mvCd7jDzHBUKfJYinAneC fVAkddss1CtNIKONpMtHfVGUobb4rM6LXj9xb/JHcSjEhVskRPBEXCjdb63t/1VLHfJ1 Rzo78uwzPeK8fAXS9WS7EPRrqvHFFx7RFgjWGPvvc9jNJ6L0NiSqk+dgjeuGvmM+sYUb H4iGBbH18Jm3tnxu7e+7z6iI+9iy5zR5s8IN4YtRmKFV1wqVZ2vJjYKxqUIno6oGTG54 ISM1kJwAjG+NVa1wlnpBuMI2WlhsVY7bwxFBFyE2kDbLOvDhH/vVC9XT46uAISNyyGNP ciCw== 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 lb25-20020a170907785900b00969dc13d0b0si3709787ejc.247.2023.05.28.02.18.26; Sun, 28 May 2023 02:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B531A68C28C; Sun, 28 May 2023 12:15:18 +0300 (EEST) 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 7A3E268C22E for ; Sun, 28 May 2023 12:15:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 364C7240177 for ; Sun, 28 May 2023 11:15:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id faxPudDZ95rI for ; Sun, 28 May 2023 11:14:59 +0200 (CEST) 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 D2F3A240D1A for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9AAFD3A09B3 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:05 +0200 Message-Id: <20230528091416.17927-13-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/24] fftools/ffmpeg_dec: move sub2video submission to ffmpeg_filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LVNKIO/S1T4m This code is analogous to ifilter_send_frame() for normal video frame, so it properly belongs to the filtering code. Note that using sub2video with more than one target for a given input subtitle stream is currently broken and this commit does not change that. It will be addressed in following commits. --- fftools/ffmpeg.c | 2 +- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_dec.c | 23 ++++++++--------------- fftools/ffmpeg_filter.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9c68add0a4..9ee16ee8e0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -755,7 +755,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti first_report = 0; } -static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) +int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) { int ret = AVERROR_BUG; AVSubtitle tmp = { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 451d18db6f..fa5824ee7b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -744,9 +744,11 @@ int init_complex_filtergraph(FilterGraph *fg); void sub2video_update(InputStream *ist, int64_t heartbeat_pts, const AVSubtitle *sub); +int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src); int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference); int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb); +int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub); /** * Set up fallback filtering parameters from a decoder context. They will only diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index c89630512a..a7acaf67c2 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -336,7 +336,6 @@ static void sub2video_flush(InputStream *ist) int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) { int ret = 0; - int free_sub = 1; if (ist->fix_sub_duration) { int end = 1; @@ -361,18 +360,13 @@ int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) if (!*got_output) return ret; - if (ist->sub2video.frame) { - sub2video_update(ist, INT64_MIN, subtitle); - } else if (ist->nb_filters) { - if (!ist->sub2video.sub_queue) - ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); - if (!ist->sub2video.sub_queue) - report_and_exit(AVERROR(ENOMEM)); - - ret = av_fifo_write(ist->sub2video.sub_queue, subtitle, 1); - if (ret < 0) - exit_program(1); - free_sub = 0; + for (int i = 0; i < ist->nb_filters; i++) { + ret = ifilter_sub2video(ist->filters[i], subtitle); + if (ret < 0) { + av_log(ist, AV_LOG_ERROR, "Error sending a subtitle for filtering: %s\n", + av_err2str(ret)); + goto out; + } } if (!subtitle->num_rects) @@ -387,8 +381,7 @@ int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) } out: - if (free_sub) - avsubtitle_free(subtitle); + avsubtitle_free(subtitle); return ret; } diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 3bf1862ab6..acfd83244b 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1638,6 +1638,36 @@ int reap_filters(int flush) return 0; } +int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle) +{ + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + InputStream *ist = ifp->ist; + int ret; + + if (ist->sub2video.frame) { + sub2video_update(ist, INT64_MIN, subtitle); + } else { + AVSubtitle sub; + + if (!ist->sub2video.sub_queue) + ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); + if (!ist->sub2video.sub_queue) + return AVERROR(ENOMEM); + + ret = copy_av_subtitle(&sub, subtitle); + if (ret < 0) + return ret; + + ret = av_fifo_write(ist->sub2video.sub_queue, &sub, 1); + if (ret < 0) { + avsubtitle_free(&sub); + return ret; + } + } + + return 0; +} + int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); From patchwork Sun May 28 09:14:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41866 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988256pzb; Sun, 28 May 2023 02:17:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60MQXRhvyh+F3HsybouOLQLlamnl7gxuSA7yWxJlRj6YuBPhTxfy8T9zKPk0OfOTRbYZNu X-Received: by 2002:a17:907:6e1f:b0:94f:36a0:da45 with SMTP id sd31-20020a1709076e1f00b0094f36a0da45mr9027621ejc.29.1685265454725; Sun, 28 May 2023 02:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265454; cv=none; d=google.com; s=arc-20160816; b=g5biW32KQG4QnxOYJajiavtXC+22xUmcUwTYg01qp+lXNCCQKoKuwqHLUSKkpa6dNb x5ZeGynNYu7Usk63Y47ODFQKrxGC4eHTMRyFIx2nKqtdJMu1hp4SXsDmFfnWbLCtO+2Z zREwtAdGOMRH9OaD5CmTShg0TTSrVxg67nFib/ZhgTO0wBnKHmtQIr+xVXqaR5IqPB/6 nVRU2pylC7CjzhcUwbYXL+qwmCB9F0ebBtVblTM52iZ6WxQ3UkVKW64gZv7HmH6tSCgb MEr/pWeZfM1RWoTqrL75jbvP2ER/5BeDvQgKZNmIeJb61Z8affrNlJ2f1gQiOAeCTERV iYQA== 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=uqlE7/4lCqK81c8SofDgI8bBcb7OCnvl0QQh2uJSgXs=; b=fS+LP3M9mrvWbhmS+wF5t/deX+R0DLOWdrL9u7YvJ7i6aPmk2/qVcE5z8aqBCEvqDI RnVQdVMYLescANoEAIkpPOBmuwou3jfWM0qp7f/TuWPu8/K7M4fTHze0o48fhvszB3Kf so1LYDYL3gig4qU7kzQlH6+EMBtdpAfrnoBbGig4LQtoqfJMHACoOwMsbe3orV7V6L21 9a3W2C2xQjCN5Vyn4uS6NhY5WondLIDRdn9Lng1O+XLnRblA41X+fwtFDLtPDRBXxRMf pGFKWUtbbwvzksKLYVmjVqbXm5phkG/F60z8VHsKw4WVyFwIsdUwyb7WtC+QcPtbzI9U QP2g== 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 gg38-20020a17090689a600b0094f70e98f95si5316682ejc.757.2023.05.28.02.17.34; Sun, 28 May 2023 02:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 EC72268C26C; Sun, 28 May 2023 12:15:12 +0300 (EEST) 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 276D368C223 for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A65762405F9 for ; Sun, 28 May 2023 11:14:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id BMv7fzFkbzM7 for ; Sun, 28 May 2023 11:14:51 +0200 (CEST) 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 93A632405EC for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A64053A0BC6 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:06 +0200 Message-Id: <20230528091416.17927-14-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/24] fftools/ffmpeg_filter: move sub2video subtitle queue to InputFilterPriv 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: foyQ+czCts5z This queue should be associated with a specific filtergraph input - if a subtitle stream is sent to multiple filters then each should have its own queue. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_filter.c | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index fa5824ee7b..d4aff5cc7c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -374,7 +374,6 @@ typedef struct InputStream { struct sub2video { int64_t last_pts; int64_t end_pts; - AVFifo *sub_queue; ///< queue of AVSubtitle* before filter init AVFrame *frame; int w, h; unsigned int initialize; ///< marks if sub2video_update should force an initialization diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index acfd83244b..2a73e3a3e3 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -104,6 +104,10 @@ typedef struct InputFilterPriv { AVChannelLayout ch_layout; } fallback; + struct { + ///< queue of AVSubtitle* before filter init + AVFifo *queue; + } sub2video; } InputFilterPriv; static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter) @@ -593,7 +597,6 @@ void fg_free(FilterGraph **pfg) for (int j = 0; j < fg->nb_inputs; j++) { InputFilter *ifilter = fg->inputs[j]; InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - InputStream *ist = ifp->ist; if (ifp->frame_queue) { AVFrame *frame; @@ -601,11 +604,11 @@ void fg_free(FilterGraph **pfg) av_frame_free(&frame); av_fifo_freep2(&ifp->frame_queue); } - if (ist && ist->sub2video.sub_queue) { + if (ifp->sub2video.queue) { AVSubtitle sub; - while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0) + while (av_fifo_read(ifp->sub2video.queue, &sub, 1) >= 0) avsubtitle_free(&sub); - av_fifo_freep2(&ist->sub2video.sub_queue); + av_fifo_freep2(&ifp->sub2video.queue); } av_channel_layout_uninit(&ifp->fallback.ch_layout); @@ -1495,10 +1498,11 @@ int configure_filtergraph(FilterGraph *fg) /* process queued up subtitle packets */ for (i = 0; i < fg->nb_inputs; i++) { - InputStream *ist = ifp_from_ifilter(fg->inputs[i])->ist; - if (ist->sub2video.sub_queue && ist->sub2video.frame) { + InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); + InputStream *ist = ifp->ist; + if (ifp->sub2video.queue && ist->sub2video.frame) { AVSubtitle tmp; - while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) { + while (av_fifo_read(ifp->sub2video.queue, &tmp, 1) >= 0) { sub2video_update(ist, INT64_MIN, &tmp); avsubtitle_free(&tmp); } @@ -1649,16 +1653,16 @@ int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle) } else { AVSubtitle sub; - if (!ist->sub2video.sub_queue) - ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); - if (!ist->sub2video.sub_queue) + if (!ifp->sub2video.queue) + ifp->sub2video.queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); + if (!ifp->sub2video.queue) return AVERROR(ENOMEM); ret = copy_av_subtitle(&sub, subtitle); if (ret < 0) return ret; - ret = av_fifo_write(ist->sub2video.sub_queue, &sub, 1); + ret = av_fifo_write(ifp->sub2video.queue, &sub, 1); if (ret < 0) { avsubtitle_free(&sub); return ret; From patchwork Sun May 28 09:14:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41867 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988320pzb; Sun, 28 May 2023 02:17:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4c0lIDdjP746q8wbHJnozLmCwu6jadsfIgOwmkRwL8+JIYKb8eK84NiqJwWvf2k1kJBmPn X-Received: by 2002:a17:907:3d87:b0:973:e4c2:2be9 with SMTP id he7-20020a1709073d8700b00973e4c22be9mr4012319ejc.33.1685265463382; Sun, 28 May 2023 02:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265463; cv=none; d=google.com; s=arc-20160816; b=X7MywwPKG9c+OeXQVo9dO/fiDupXOfc6TmBUWAU/uDDMmCrnjm6JeX0H9yCQezkxlX LpBTJFB3Y0B9z6xPyPtTf6sPGPZmSTL+e4vk7z5a9TbzjatZVJSL5co2nVngpl353gSH dFQEWW2pASiRXwSBapEcHk53yfIAYeVaJFt7VkCQpq9fjNqGei5LOrGXiY7uyJEW9pkC 72FmOq+epGNZ++ISuNUj1KlVEvBMKNdaXd82fqoZH9MjUjwyPuJWl+/MKlx3wVwlBAZ0 NT37xI7V1xMCAxfkTxm+3XKpaOMdh8gvjP2t+jiynm/mL595dVT4g/wVj/hDEd+Dm4TZ 4esA== 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=WlnJYlvwqzZ8vK8xRoCO8VNO1OsRw6q7wN82uEvUU64=; b=nmfIDIUtvkQnE81APsO5k1zEWtE8hPQ8VbC97Y+6rfRvQky8PIwuEMUdKkK3Ceac8V fcf8+LPRzFJkWFjA6PD9iqIG+nEdxNwS7S8vuOArvdvv7V5OKjcuLKRdo+SltKUipC/a Sn1ycOveSgsh0pI08o9d+IwJSQ7TIJdmmNqsxZ1N5JspS3BeyyiRV9sHvPwlNEgVb85o VrXIQGwIFZHj/DeYksG9LjussdUYiV69eIMlb5VoUgbBcP/c1Q2h7EAUaLwjMY/fFnOL wp2Imjx5Fy9zIXVGaiq5SknkbT2E3ysE/P9Zn1Hv+HK1phjfu8US8QG690IbHiuZK5Ej peow== 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 ez24-20020a1709070bd800b00965be3494fcsi2683979ejc.60.2023.05.28.02.17.43; Sun, 28 May 2023 02:17:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 C663C68C272; Sun, 28 May 2023 12:15:13 +0300 (EEST) 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 30A7968C225 for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 970272405EC for ; Sun, 28 May 2023 11:14:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id BNlbm6tAaJoT for ; Sun, 28 May 2023 11:14:50 +0200 (CEST) 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 A421A2406CA for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B206B3A0BDC for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:07 +0200 Message-Id: <20230528091416.17927-15-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/24] fftools/ffmpeg: tweak sub2video_heartbeat() arguments 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: pc57vlf/BCel This function should not take an InputStream, as it only uses it to get the InputFile and the timebase. Pass those directly instead and avoid confusion over dealing with multiple InputStreams. --- fftools/ffmpeg.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9ee16ee8e0..4624960c17 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -252,9 +252,8 @@ void sub2video_update(InputStream *ist, int64_t heartbeat_pts, ist->sub2video.initialize = 0; } -static void sub2video_heartbeat(InputStream *ist, int64_t pts) +static void sub2video_heartbeat(InputFile *infile, int64_t pts, AVRational tb) { - InputFile *infile = input_files[ist->file_index]; int i, j, nb_reqs; int64_t pts2; @@ -268,7 +267,7 @@ static void sub2video_heartbeat(InputStream *ist, int64_t pts) continue; /* subtitles seem to be usually muxed ahead of other streams; if not, subtracting a larger time here is necessary */ - pts2 = av_rescale_q(pts, ist->st->time_base, ist2->st->time_base) - 1; + pts2 = av_rescale_q(pts, tb, ist2->st->time_base) - 1; /* do not send the heartbeat frame if the subtitle is already ahead */ if (pts2 <= ist2->sub2video.last_pts) continue; @@ -1231,7 +1230,7 @@ static int process_input(int file_index) ist = ifile->streams[pkt->stream_index]; - sub2video_heartbeat(ist, pkt->pts); + sub2video_heartbeat(ifile, pkt->pts, pkt->time_base); process_input_packet(ist, pkt, 0); From patchwork Sun May 28 09:14:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41855 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987385pzb; Sun, 28 May 2023 02:15:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BmGn9qfq+VdZo71YTm/3us98NjMUOzhzvTgv0P9yzhDRYAmi4X33bwV9NLehK7V4yXnMp X-Received: by 2002:a17:907:980f:b0:973:d619:b5d4 with SMTP id ji15-20020a170907980f00b00973d619b5d4mr6153960ejc.15.1685265354983; Sun, 28 May 2023 02:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265354; cv=none; d=google.com; s=arc-20160816; b=vXI8AUMwO4tBVG+FShJcpTocZP488HVple1WX/USs6P+XK+1u9892jM61heXVpUBHc icZP3DRvTpf7yTNjnh4t4RFtoSmgQpgQ3LXAnOOFObYzvvSzJ86IwUwiu2InmdgYaloq 4m6l3oWhntKLGYQ9vY/NRmtmbEua86DItMj4w63Wv+6kIdObNlV9IacFeN+WcLjXgVJr wUVYnzM7ivM5pGxOWrMH/jAHbu5lZ5KfUCXyiUKc+sXi/8XhxN/HojqxQh/EluZPvHWe nUxvGTe3h+bM+uiJh+fWlUYpt1uZrnQt1m+t8rFr3idgeLOdsrm9tIDKvc52M+finSV1 PGMQ== 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=oFdaF46qABi/x2YuWN1MW3qG2G82lguvy4/dVAJR8nc=; b=IoyI9gTM+TH8/KoPD9xWW0KnL4NRvLupP+NZWmjMjPw/NwN8tSg/FSYhjrwy0788dX 8jtuZjmKDQb9+jxwZldxTVHyjdcD2AMTh9oExbC7Xhwvofu7ppdOkSQyUKqa+NAW8Gl+ SFzBJ+bNVXiRg/6fSp3Kds/w4xoQ4yD5CgaZ/KhrIF5Te/oZlnUQidMRRezuE9UVAS7V asVfH89MCAxg7wk9jf3QEq70KwighCOykcPnuo7mCggUdP8HLULhePi/6OY2cfo72TZ2 hnqXdcyDffHkCQuwBLdng2vBeGvd15/xKfshTVjvs5YeMax0tcTSVNeH8G/xLZyWqB13 PJ7Q== 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 r26-20020aa7c15a000000b0050bf8f10e12si2446391edp.233.2023.05.28.02.15.54; Sun, 28 May 2023 02:15:54 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 806E068C22D; Sun, 28 May 2023 12:15:01 +0300 (EEST) 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 95AF368C1EC for ; Sun, 28 May 2023 12:14:55 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CAC24240591 for ; Sun, 28 May 2023 11:14:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 9HeYnpLsIOQu for ; Sun, 28 May 2023 11:14:54 +0200 (CEST) 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 AA7752406CC for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BDC3C3A0C42 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:08 +0200 Message-Id: <20230528091416.17927-16-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/24] fftools/ffmpeg: rework setting sub2video parameters 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: HAZKjigOH75B Set them in ifilter_parameters_from_dec(), similarly to audio/video streams. This reduces the extent to which sub2video filters need to be treated specially. --- fftools/ffmpeg.c | 6 ++--- fftools/ffmpeg_demux.c | 21 +++++++++++++++++ fftools/ffmpeg_filter.c | 52 +++++++++++------------------------------ 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4624960c17..e9e60407d2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -153,9 +153,9 @@ static int sub2video_get_blank_frame(InputStream *ist) AVFrame *frame = ist->sub2video.frame; av_frame_unref(frame); - ist->sub2video.frame->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w; - ist->sub2video.frame->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h; - ist->sub2video.frame->format = AV_PIX_FMT_RGB32; + frame->width = ist->sub2video.w; + frame->height = ist->sub2video.h; + frame->format = AV_PIX_FMT_RGB32; if ((ret = av_frame_get_buffer(frame, 0)) < 0) return ret; memset(frame->data[0], 0, frame->height * frame->linesize[0]); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 561b4b0002..817ccbbedc 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1228,6 +1228,27 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size); exit_program(1); } + + /* Compute the size of the canvas for the subtitles stream. + If the subtitles codecpar has set a size, use it. Otherwise use the + maximum dimensions of the video streams in the same file. */ + ist->sub2video.w = ist->dec_ctx->width; + ist->sub2video.h = ist->dec_ctx->height; + if (!(ist->sub2video.w && ist->sub2video.h)) { + for (int j = 0; j < ic->nb_streams; j++) { + AVCodecParameters *par1 = ic->streams[j]->codecpar; + if (par1->codec_type == AVMEDIA_TYPE_VIDEO) { + ist->sub2video.w = FFMAX(ist->sub2video.w, par1->width); + ist->sub2video.h = FFMAX(ist->sub2video.h, par1->height); + } + } + } + + if (!(ist->sub2video.w && ist->sub2video.h)) { + ist->sub2video.w = FFMAX(ist->sub2video.w, 720); + ist->sub2video.h = FFMAX(ist->sub2video.h, 576); + } + break; } case AVMEDIA_TYPE_ATTACHMENT: diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 2a73e3a3e3..670e697f69 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1110,38 +1110,6 @@ void check_filter_outputs(void) static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) { - InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - AVFormatContext *avf = input_files[ist->file_index]->ctx; - int i, w, h; - - /* Compute the size of the canvas for the subtitles stream. - If the subtitles codecpar has set a size, use it. Otherwise use the - maximum dimensions of the video streams in the same file. */ - w = ifp->width; - h = ifp->height; - if (!(w && h)) { - for (i = 0; i < avf->nb_streams; i++) { - if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - w = FFMAX(w, avf->streams[i]->codecpar->width); - h = FFMAX(h, avf->streams[i]->codecpar->height); - } - } - if (!(w && h)) { - w = FFMAX(w, 720); - h = FFMAX(h, 576); - } - av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h); - } - ist->sub2video.w = ifp->width = w; - ist->sub2video.h = ifp->height = h; - - ifp->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w; - ifp->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h; - - /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the - palettes for all rectangles are identical or compatible */ - ifp->format = AV_PIX_FMT_RGB32; - ist->sub2video.frame = av_frame_alloc(); if (!ist->sub2video.frame) return AVERROR(ENOMEM); @@ -1525,7 +1493,7 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) ifp->fallback.width = dec->width; ifp->fallback.height = dec->height; ifp->fallback.sample_aspect_ratio = dec->sample_aspect_ratio; - } else { + } else if (dec->codec_type == AVMEDIA_TYPE_AUDIO) { int ret; ifp->fallback.format = dec->sample_fmt; @@ -1534,6 +1502,17 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) ret = av_channel_layout_copy(&ifp->fallback.ch_layout, &dec->ch_layout); if (ret < 0) return ret; + } else { + // for subtitles (i.e. sub2video) we set the actual parameters, + // rather than just fallback + ifp->width = dec->width; + ifp->height = dec->height; + + /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the + palettes for all rectangles are identical or compatible */ + ifp->format = AV_PIX_FMT_RGB32; + + av_log(NULL, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n", ifp->width, ifp->height); } return 0; @@ -1574,8 +1553,7 @@ int ifilter_has_all_input_formats(FilterGraph *fg) int i; for (i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); - if (ifp->format < 0 && (ifp->type_src == AVMEDIA_TYPE_AUDIO || - ifp->type_src == AVMEDIA_TYPE_VIDEO)) + if (ifp->format < 0) return 0; } return 1; @@ -1709,9 +1687,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) } } - if (ifp->format < 0 && - (ifp->type_src == AVMEDIA_TYPE_AUDIO || - ifp->type_src == AVMEDIA_TYPE_VIDEO)) { + if (ifp->format < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifp->ist->file_index, ifp->ist->index); From patchwork Sun May 28 09:14:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41862 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987932pzb; Sun, 28 May 2023 02:16:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4erkUYww92ODzLo/+R+aibdplwk5YMBUdD88NDAme4YFIfEiWaISO8TLkvEkvwnRwkvGB+ X-Received: by 2002:a05:6402:b2e:b0:514:945c:6cea with SMTP id bo14-20020a0564020b2e00b00514945c6ceamr1963858edb.37.1685265419426; Sun, 28 May 2023 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265419; cv=none; d=google.com; s=arc-20160816; b=GgeXuTYLwvkynfcZHMcVqeA5p0LacYnm5bweTDJmyqIk95jDhrL3kNZo8mKUvYosUY 8L6w2ugp3AF4eHRbCQrvAHvLQMkTUud/twIFvB1i4Q4Kh68JG4BY5nf4T49eRHOEyAGM ZCUhA8VG7ZQVMPG7lwNFLqJ2HJyPKEK/AFN20PfkKu223xhLvndiIyMAZXQzDk8t6dZO 3ZEhnYnD3So0wNtt+QuMZ1ferg77vUILkscDKG9QTyhOEz8J9Yx7XJHguA70WGmz09er QgY6GndT73u44irg7iHV+N5GqCB9rNDKwY+zeJfhQ3mtn9xKV0h0nTMZfIMdltlQ0/QW 4HvQ== 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=Pz9bJnzYClIWRQEezi1Ic0R1tAEoX/HUp/H+zHxThmg=; b=SEFUOHbpF4zM0rgk3JkEifJBVuhQK25KacYG2602GQHPhvXz0VRDTj3PGnme9VIV3q nIK3gVvQ+NWmXIvR1zua5yb66xsAcBx46ciSLVQKafEOG5WU7+/lR70+BbLBqVdySgth bedX90ovGiF0Go7AqNmMsQSniMImDEvLgMQIfayo6eocr+41JghvcfVxhXlisk1vj6JG +ZdCZ5MRS+AlJXGOutcsIyTGMygdM+X2UHBEHksqXLB4KvhC3FgOfdT51FNvrX/11YQV weOl5FHrfmsM0hjI00Nzjdq3E5gG+tFFWLMvsVlsJKTyzbVSalf9nVu8FgsF85WTjpIN NP3A== 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 l10-20020aa7c30a000000b00514947231c9si1488685edq.363.2023.05.28.02.16.59; Sun, 28 May 2023 02:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 EEAA268C260; Sun, 28 May 2023 12:15:08 +0300 (EEST) 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 4127C68C211 for ; Sun, 28 May 2023 12:14:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F27452404F5 for ; Sun, 28 May 2023 11:14:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Upu6xuaUylyo for ; Sun, 28 May 2023 11:14:56 +0200 (CEST) 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 CBC43240706 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C98F03A0CDD for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:09 +0200 Message-Id: <20230528091416.17927-17-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/24] fftools/ffmpeg: move sub2video handling to ffmpeg_filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zppMsWNiazQn Make all relevant state per-filtergraph input, rather than per-input stream. Refactor the code to make it work and avoid leaking memory when a single subtitle stream is sent to multiple filters. --- fftools/ffmpeg.c | 133 ++-------------------------- fftools/ffmpeg.h | 7 +- fftools/ffmpeg_dec.c | 9 +- fftools/ffmpeg_demux.c | 1 - fftools/ffmpeg_filter.c | 189 +++++++++++++++++++++++++++++++++++----- 5 files changed, 177 insertions(+), 162 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e9e60407d2..36b4becaf2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -147,139 +147,20 @@ static int restore_tty; This is a temporary solution until libavfilter gets real subtitles support. */ -static int sub2video_get_blank_frame(InputStream *ist) -{ - int ret; - AVFrame *frame = ist->sub2video.frame; - - av_frame_unref(frame); - frame->width = ist->sub2video.w; - frame->height = ist->sub2video.h; - frame->format = AV_PIX_FMT_RGB32; - if ((ret = av_frame_get_buffer(frame, 0)) < 0) - return ret; - memset(frame->data[0], 0, frame->height * frame->linesize[0]); - return 0; -} - -static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, - AVSubtitleRect *r) -{ - uint32_t *pal, *dst2; - uint8_t *src, *src2; - int x, y; - - if (r->type != SUBTITLE_BITMAP) { - av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n"); - return; - } - if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) { - av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) overflowing %d %d\n", - r->x, r->y, r->w, r->h, w, h - ); - return; - } - - dst += r->y * dst_linesize + r->x * 4; - src = r->data[0]; - pal = (uint32_t *)r->data[1]; - for (y = 0; y < r->h; y++) { - dst2 = (uint32_t *)dst; - src2 = src; - for (x = 0; x < r->w; x++) - *(dst2++) = pal[*(src2++)]; - dst += dst_linesize; - src += r->linesize[0]; - } -} - -static void sub2video_push_ref(InputStream *ist, int64_t pts) -{ - AVFrame *frame = ist->sub2video.frame; - int i; - int ret; - - av_assert1(frame->data[0]); - ist->sub2video.last_pts = frame->pts = pts; - for (i = 0; i < ist->nb_filters; i++) { - ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, frame, - AV_BUFFERSRC_FLAG_KEEP_REF | - AV_BUFFERSRC_FLAG_PUSH); - if (ret != AVERROR_EOF && ret < 0) - av_log(NULL, AV_LOG_WARNING, "Error while add the frame to buffer source(%s).\n", - av_err2str(ret)); - } -} - -void sub2video_update(InputStream *ist, int64_t heartbeat_pts, - const AVSubtitle *sub) -{ - AVFrame *frame = ist->sub2video.frame; - int8_t *dst; - int dst_linesize; - int num_rects, i; - int64_t pts, end_pts; - - if (!frame) - return; - if (sub) { - pts = av_rescale_q(sub->pts + sub->start_display_time * 1000LL, - AV_TIME_BASE_Q, ist->st->time_base); - end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000LL, - AV_TIME_BASE_Q, ist->st->time_base); - num_rects = sub->num_rects; - } else { - /* If we are initializing the system, utilize current heartbeat - PTS as the start time, and show until the following subpicture - is received. Otherwise, utilize the previous subpicture's end time - as the fall-back value. */ - pts = ist->sub2video.initialize ? - heartbeat_pts : ist->sub2video.end_pts; - end_pts = INT64_MAX; - num_rects = 0; - } - if (sub2video_get_blank_frame(ist) < 0) { - av_log(NULL, AV_LOG_ERROR, - "Impossible to get a blank canvas.\n"); - return; - } - dst = frame->data [0]; - dst_linesize = frame->linesize[0]; - for (i = 0; i < num_rects; i++) - sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]); - sub2video_push_ref(ist, pts); - ist->sub2video.end_pts = end_pts; - ist->sub2video.initialize = 0; -} - static void sub2video_heartbeat(InputFile *infile, int64_t pts, AVRational tb) { - int i, j, nb_reqs; - int64_t pts2; - /* When a frame is read from a file, examine all sub2video streams in the same file and send the sub2video frame again. Otherwise, decoded 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 = infile->streams[i]; - if (!ist2->sub2video.frame) - continue; - /* subtitles seem to be usually muxed ahead of other streams; - if not, subtracting a larger time here is necessary */ - pts2 = av_rescale_q(pts, tb, ist2->st->time_base) - 1; - /* do not send the heartbeat frame if the subtitle is already ahead */ - if (pts2 <= ist2->sub2video.last_pts) + for (int i = 0; i < infile->nb_streams; i++) { + InputStream *ist = infile->streams[i]; + + if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; - if (pts2 >= ist2->sub2video.end_pts || ist2->sub2video.initialize) - /* if we have hit the end of the current displayed subpicture, - or if we need to initialize the system, update the - overlayed subpicture and its start/end times */ - sub2video_update(ist2, pts2 + 1, NULL); - for (j = 0, nb_reqs = 0; j < ist2->nb_filters; j++) - nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->filters[j]->filter); - if (nb_reqs) - sub2video_push_ref(ist2, pts2); + + for (int j = 0; j < ist->nb_filters; j++) + ifilter_sub2video_heartbeat(ist->filters[j], pts, tb); } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d4aff5cc7c..75695d3fb5 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -372,11 +372,7 @@ typedef struct InputStream { } prev_sub; struct sub2video { - int64_t last_pts; - int64_t end_pts; - AVFrame *frame; int w, h; - unsigned int initialize; ///< marks if sub2video_update should force an initialization } sub2video; /* decoded data from this stream goes into all those filters @@ -741,13 +737,12 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc); int init_complex_filtergraph(FilterGraph *fg); -void sub2video_update(InputStream *ist, int64_t heartbeat_pts, - const AVSubtitle *sub); int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src); int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference); int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb); int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub); +void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational tb); /** * Set up fallback filtering parameters from a decoder context. They will only diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index a7acaf67c2..30959c64b7 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -321,13 +321,8 @@ static int video_frame_process(InputStream *ist, AVFrame *frame) static void sub2video_flush(InputStream *ist) { - int i; - int ret; - - if (ist->sub2video.end_pts < INT64_MAX) - sub2video_update(ist, INT64_MAX, NULL); - for (i = 0; i < ist->nb_filters; i++) { - ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL); + for (int i = 0; i < ist->nb_filters; i++) { + int ret = ifilter_sub2video(ist->filters[i], NULL); if (ret != AVERROR_EOF && ret < 0) av_log(NULL, AV_LOG_WARNING, "Flush the frame error.\n"); } diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 817ccbbedc..5c15b8bad3 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -817,7 +817,6 @@ static void ist_free(InputStream **pist) 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->outputs); av_freep(&ist->hwaccel_device); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 670e697f69..ce2a914745 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -107,6 +107,14 @@ typedef struct InputFilterPriv { struct { ///< queue of AVSubtitle* before filter init AVFifo *queue; + + AVFrame *frame; + + int64_t last_pts; + int64_t end_pts; + + ///< marks if sub2video_update should force an initialization + unsigned int initialize; } sub2video; } InputFilterPriv; @@ -115,6 +123,111 @@ static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter) return (InputFilterPriv*)ifilter; } +static int sub2video_get_blank_frame(InputFilterPriv *ifp) +{ + AVFrame *frame = ifp->sub2video.frame; + int ret; + + av_frame_unref(frame); + + frame->width = ifp->width; + frame->height = ifp->height; + frame->format = ifp->format; + + ret = av_frame_get_buffer(frame, 0); + if (ret < 0) + return ret; + + memset(frame->data[0], 0, frame->height * frame->linesize[0]); + + return 0; +} + +static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, + AVSubtitleRect *r) +{ + uint32_t *pal, *dst2; + uint8_t *src, *src2; + int x, y; + + if (r->type != SUBTITLE_BITMAP) { + av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n"); + return; + } + if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) { + av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) overflowing %d %d\n", + r->x, r->y, r->w, r->h, w, h + ); + return; + } + + dst += r->y * dst_linesize + r->x * 4; + src = r->data[0]; + pal = (uint32_t *)r->data[1]; + for (y = 0; y < r->h; y++) { + dst2 = (uint32_t *)dst; + src2 = src; + for (x = 0; x < r->w; x++) + *(dst2++) = pal[*(src2++)]; + dst += dst_linesize; + src += r->linesize[0]; + } +} + +static void sub2video_push_ref(InputFilterPriv *ifp, int64_t pts) +{ + AVFrame *frame = ifp->sub2video.frame; + int ret; + + av_assert1(frame->data[0]); + ifp->sub2video.last_pts = frame->pts = pts; + ret = av_buffersrc_add_frame_flags(ifp->ifilter.filter, frame, + AV_BUFFERSRC_FLAG_KEEP_REF | + AV_BUFFERSRC_FLAG_PUSH); + if (ret != AVERROR_EOF && ret < 0) + av_log(NULL, AV_LOG_WARNING, "Error while add the frame to buffer source(%s).\n", + av_err2str(ret)); +} + +static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, + const AVSubtitle *sub) +{ + AVFrame *frame = ifp->sub2video.frame; + int8_t *dst; + int dst_linesize; + int num_rects, i; + int64_t pts, end_pts; + + if (sub) { + pts = av_rescale_q(sub->pts + sub->start_display_time * 1000LL, + AV_TIME_BASE_Q, ifp->time_base); + end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000LL, + AV_TIME_BASE_Q, ifp->time_base); + num_rects = sub->num_rects; + } else { + /* If we are initializing the system, utilize current heartbeat + PTS as the start time, and show until the following subpicture + is received. Otherwise, utilize the previous subpicture's end time + as the fall-back value. */ + pts = ifp->sub2video.initialize ? + heartbeat_pts : ifp->sub2video.end_pts; + end_pts = INT64_MAX; + num_rects = 0; + } + if (sub2video_get_blank_frame(ifp) < 0) { + av_log(NULL, AV_LOG_ERROR, + "Impossible to get a blank canvas.\n"); + return; + } + dst = frame->data [0]; + dst_linesize = frame->linesize[0]; + for (i = 0; i < num_rects; i++) + sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]); + sub2video_push_ref(ifp, pts); + ifp->sub2video.end_pts = end_pts; + ifp->sub2video.initialize = 0; +} + // FIXME: YUV420P etc. are actually supported with full color range, // yet the latter information isn't available here. static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[]) @@ -465,6 +578,12 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) ifp->ist = ist; ifp->type_src = ist->st->codecpar->codec_type; + if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) { + ifp->sub2video.frame = av_frame_alloc(); + if (!ifp->sub2video.frame) + return AVERROR(ENOMEM); + } + return 0; } @@ -610,6 +729,7 @@ void fg_free(FilterGraph **pfg) avsubtitle_free(&sub); av_fifo_freep2(&ifp->sub2video.queue); } + av_frame_free(&ifp->sub2video.frame); av_channel_layout_uninit(&ifp->fallback.ch_layout); @@ -1108,20 +1228,15 @@ void check_filter_outputs(void) } } -static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) +static void sub2video_prepare(InputFilterPriv *ifp) { - ist->sub2video.frame = av_frame_alloc(); - if (!ist->sub2video.frame) - return AVERROR(ENOMEM); - ist->sub2video.last_pts = INT64_MIN; - ist->sub2video.end_pts = INT64_MIN; + ifp->sub2video.last_pts = INT64_MIN; + ifp->sub2video.end_pts = INT64_MIN; /* sub2video structure has been (re-)initialized. Mark it as such so that the system will be initialized with the first received heartbeat. */ - ist->sub2video.initialize = 1; - - return 0; + ifp->sub2video.initialize = 1; } static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, @@ -1156,11 +1271,8 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, if (!fr.num) fr = ist->framerate_guessed; - if (ist->dec_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { - ret = sub2video_prepare(ist, ifilter); - if (ret < 0) - goto fail; - } + if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) + sub2video_prepare(ifp); ifp->time_base = ist->framerate.num ? av_inv_q(ist->framerate) : ist->st->time_base; @@ -1466,12 +1578,13 @@ int configure_filtergraph(FilterGraph *fg) /* process queued up subtitle packets */ for (i = 0; i < fg->nb_inputs; i++) { - InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); - InputStream *ist = ifp->ist; - if (ifp->sub2video.queue && ist->sub2video.frame) { + InputFilter *ifilter = fg->inputs[i]; + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + + if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE && ifp->sub2video.queue) { AVSubtitle tmp; while (av_fifo_read(ifp->sub2video.queue, &tmp, 1) >= 0) { - sub2video_update(ist, INT64_MIN, &tmp); + sub2video_update(ifp, INT64_MIN, &tmp); avsubtitle_free(&tmp); } } @@ -1620,15 +1733,47 @@ int reap_filters(int flush) return 0; } +void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational tb) +{ + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + int64_t pts2; + + if (!ifilter->graph->graph) + return; + + /* subtitles seem to be usually muxed ahead of other streams; + if not, subtracting a larger time here is necessary */ + pts2 = av_rescale_q(pts, tb, ifp->time_base) - 1; + + /* do not send the heartbeat frame if the subtitle is already ahead */ + if (pts2 <= ifp->sub2video.last_pts) + return; + + if (pts2 >= ifp->sub2video.end_pts || ifp->sub2video.initialize) + /* if we have hit the end of the current displayed subpicture, + or if we need to initialize the system, update the + overlayed subpicture and its start/end times */ + sub2video_update(ifp, pts2 + 1, NULL); + + if (av_buffersrc_get_nb_failed_requests(ifilter->filter)) + sub2video_push_ref(ifp, pts2); +} + int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - InputStream *ist = ifp->ist; int ret; - if (ist->sub2video.frame) { - sub2video_update(ist, INT64_MIN, subtitle); - } else { + if (ifilter->graph->graph) { + if (!subtitle) { + if (ifp->sub2video.end_pts < INT64_MAX) + sub2video_update(ifp, INT64_MAX, NULL); + + return av_buffersrc_add_frame(ifilter->filter, NULL); + } + + sub2video_update(ifp, INT64_MIN, subtitle); + } else if (subtitle) { AVSubtitle sub; if (!ifp->sub2video.queue) From patchwork Sun May 28 09:14:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41870 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988528pzb; Sun, 28 May 2023 02:18:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5f2I6hVy7A6qgPUZ7qEawgkUAIfLCqld2N4pAt12UlaEUX5eRbBaw6NmCVw6eI2QvrHlte X-Received: by 2002:a17:907:7e8a:b0:94f:3980:bf91 with SMTP id qb10-20020a1709077e8a00b0094f3980bf91mr8535935ejc.19.1685265489430; Sun, 28 May 2023 02:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265489; cv=none; d=google.com; s=arc-20160816; b=PFzQrlbpA/joBR/Gza4WZZHUCJiiDi4DvgNG/zuhzgppCB05K3a5stemvB7RDLGOb4 +glw5WRdBbvTw2y2avQYWmPiJ1F6KGhvcvIMR6SFjkQ5A9f0E2HdKGYwTSwiH0fQ6Dym 5KsbxIYfySy0jESeRQeotRlx2aaoC9kuVxjQi0LXu7UbjC9YdrOgoDuN9MIqZmxoFWZY wWx8gGJ7/WhpyM+4L6N8ce5rEdUviV5zSHKLgtCOxRWeNs8GzZhbqXjBUAxMzkzHGItq e1uoMhanpvqkHXGoa+FiHVEZp+PaO8Tq/dXC0vXd0AHixsP0isBWukOD1WmfIAsk+VgD 8MSA== 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=iwCeU1wjBn6uusmDP9HjV99dXcs/p4buvJhgMrT2Ql8=; b=LhrL3p7A2qDR1wwQ/Cu/MhiwQ3w6wOQ0G/hyK713iVNTIiDdc9g0oJ+7lk4r4OgRIn GJSNhxY3SyUhg1Gmbnp/hhpSDQq//HI33MYtb22oQ7pmmWKX6GaPzd2VtQ4k6G42llQu 03zvqL+LNTpRzPekEF6rsuz7Z+Hk9fsQNLLUm60AkhMubyNhy6XZmqDwumlpoq9SN/RW i9OmaGzIMBtGJ06SOS7kkt2CPygqrWdu2QT7nWQP55bh8NG6JqYV+5VoFAX3d6gD8KYQ Dabt0GPv/uw8q45R8q7/PQq8tmBAWWi4v+3gyqLHl9zsUXUm4EQ0eFg2cExAUnKRRjvp RqfA== 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 h15-20020a170906260f00b0096f8fead185si3943760ejc.975.2023.05.28.02.18.09; Sun, 28 May 2023 02:18:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B6CCD68C27F; Sun, 28 May 2023 12:15:16 +0300 (EEST) 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 C98CF68C22A for ; Sun, 28 May 2023 12:14:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1C9032406CA for ; Sun, 28 May 2023 11:14:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id qBB8tmcLr3Vu for ; Sun, 28 May 2023 11:14:52 +0200 (CEST) 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 AE2CD2406CD for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D51843A0CE0 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:10 +0200 Message-Id: <20230528091416.17927-18-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/24] fftools/ffmpeg_enc: stop configuring filters from encoder flush 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: gHxQ2dRFDBx3 There is no way for a filtergraph to have all input parameters, yet not be configured, so this code should not be reachable. --- fftools/ffmpeg_enc.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f023657a07..6c9cce252f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1172,18 +1172,8 @@ void enc_flush(void) av_log(ost, AV_LOG_WARNING, "Finishing stream without any data written to it.\n"); - if (ost->filter && !fg->graph) { - if (!ifilter_has_all_input_formats(fg)) - continue; - - ret = configure_filtergraph(fg); - if (ret < 0) { - av_log(ost, AV_LOG_ERROR, "Error configuring filter graph\n"); - exit_program(1); - } - - of_output_packet(of, ost->pkt, ost, 1); - } + if (!fg->graph) + continue; ret = enc_open(ost, NULL); if (ret < 0) From patchwork Sun May 28 09:14:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41869 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988448pzb; Sun, 28 May 2023 02:18:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55xIDEC05PD1K01TPspHG5nrXMMoy9LkaUtYCGXFroO1PiAGxc/xsu+A6toLDqRxH4DaIm X-Received: by 2002:a17:907:7ea4:b0:973:9639:6c0 with SMTP id qb36-20020a1709077ea400b00973963906c0mr7238231ejc.29.1685265480818; Sun, 28 May 2023 02:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265480; cv=none; d=google.com; s=arc-20160816; b=mPNbX9yA/g8i5WOqluood1drJpi6FFTKbbIuniLn/XPy/rXkfGH1YKDa4OoOs43duZ C8eZoMWm361Dgid0xpLEf1ZopoG+NIr/ROA75Twhvrn2ZojhoMjNYRoOAvNgkQQpUwrM STIfnpNkR8rNIhqTiAptUXp6N6FO7Cf7WSoI4oX8Kq6jSDhV+mbeZd/1xE2apnK98nN2 EmSuB8VFDUzhaNvN1K0gx65DYpq2iLBw39H9gZ9/rpjBI3sy6cyav0iNeQuj1qMacfL+ RxnLPSfmEQYMcECpNjm/swD7MIYpONgMU6SMKEuS7d7U5HbbTEiuyDTurR4NagRfqyqZ zplg== 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=mUMBBEDGseIOeOid/vR52D4v/El1IpnqZEVPQoQZz0E=; b=ViXi/NG+xDT+UMdxYsWnbiUYAnUvtt7QPQsqDRXTZaUnVKnRvv16z6WAg8Os1PmqvS kRb2y0t797reRIpLfGjC2yZrIrl0I7LzusEf9DN2KHXOBRVWKOUjJLsOaY/gWIk9wmQ5 Kk8ee8fnaho0z8my8/Li9uHegbS4W+FkL/7JABNoW9yTlgqJHY3QGnZLY6NLrpIOar+x hiYIucUyFBfckVHY5myPRxW8Y3ktIiRQ8VaPqlmlgpviMAfPxwUQZ7rP8wOAo9JWDlG7 C/a/M0Xr8AbmZJHW+fGH8Z8EwSBlbImb9p1ATGa0LbZ2kWYm4r5hlLikBj0GaaEdGA/A 3Xgg== 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 z7-20020aa7cf87000000b0051425b17840si2975188edx.664.2023.05.28.02.18.00; Sun, 28 May 2023 02:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B86B268C1E8; Sun, 28 May 2023 12:15:15 +0300 (EEST) 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 AB20F68B947 for ; Sun, 28 May 2023 12:14:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 792EF240177 for ; Sun, 28 May 2023 11:14:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Hyf1KDFiZ8zd for ; Sun, 28 May 2023 11:14:59 +0200 (CEST) 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 D97EC240D1C for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E0B053A0D13 for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:11 +0200 Message-Id: <20230528091416.17927-19-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/24] fftools/ffmpeg_filter: drop unreachable code 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: etnejr2geVlu Filtergraphs with no inputs are initialized as soon as all their outputs are bound, so this code should not be reachable. --- fftools/ffmpeg_filter.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ce2a914745..e0843b0729 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1946,17 +1946,6 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) int nb_requests, nb_requests_max = 0; InputStream *ist; - if (!graph->graph && ifilter_has_all_input_formats(graph)) { - // graph has not been configured yet, but everything is ready; - // this can happen for graphs with no inputs, or when some input - // EOF'ed with zero frames and fallback parameters were used - ret = configure_filtergraph(graph); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n"); - return ret; - } - } - if (!graph->graph) { for (int i = 0; i < graph->nb_inputs; i++) { InputFilter *ifilter = graph->inputs[i]; From patchwork Sun May 28 09:14:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41859 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987711pzb; Sun, 28 May 2023 02:16:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4iT9aCdX3SgNy1+D/GVldiJ7ev3bCcOU2gkDMxn6LE9umVKLxFyWjA6iEwXNeZZyY31Wso X-Received: by 2002:a17:907:7252:b0:973:fd02:a41f with SMTP id ds18-20020a170907725200b00973fd02a41fmr923849ejc.40.1685265393002; Sun, 28 May 2023 02:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265392; cv=none; d=google.com; s=arc-20160816; b=VtI/lhPczjI9l+LhA0obMhLQVi3DVwfhnIzWmUXk/2c0K40WFPjWHYAXnntuyUKghP JwbdLbuTyP35UPpbucP/RjId5yj/6fGIWgtmFvhVO1sMTBwfiRvrqSTetcoa41XRecM1 fbJdTbOGYiVkxP7iw4TeJciTDshrfiT3QrZQhFR+XrNdYVje2HcxUzKHiEiDnrpk8XO7 OHoGT4ZJBIsFLH01Ils15hksGvcdx7gjb04853AG3xAH8hXGju8grDaBF2aEnBIo5oDs dVuAX95fiU6DNgWimkvku2+Wa32Rn4XYOFVlus8yqbcmDzObHQw0aO3Y5dRUTellwhl2 OhYw== 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=2CqhuvuO4maKKPAWxAamP0BOccPE+xcIptkA6hCPjMs=; b=nfWZ9vzNQHY6spFIsESJxo67dZYDMYif15p+AH0wxDXAMLf5M5jw8tXhuM8IMUnI8K v5/4GAKEWTpytMiHNXCkT5iIXbyohTlxgm4b1f6jaN/eK0PQIuUg630zvEu1ikCzu2p8 rhizAWtudqOiXwfWV+Gk4CXr9tRRjnwD7Jn+Dld+boCgyIjULh0TcS4Z2dUywOJR7cM/ fIW23rUoPGODMxXgMZP1xrXQvllfbPW7HJFUyyGlGw729ZNPGDEUNm9iR9S0vjXVR/h2 /wDpRJBzsjAt0WVBaEGg6BaHbyq7mb7HpgmZmHDAl+0OkhYz7yBjNX7G2WcWyX2MENRI gcOw== 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 vs3-20020a170907138300b00965604f0e3asi4136232ejb.808.2023.05.28.02.16.32; Sun, 28 May 2023 02:16:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 D3FE868C256; Sun, 28 May 2023 12:15:05 +0300 (EEST) 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 1410968C1F9 for ; Sun, 28 May 2023 12:14:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C74032404F5 for ; Sun, 28 May 2023 11:14:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id JgD4NPDW7YPp for ; Sun, 28 May 2023 11:14:55 +0200 (CEST) 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 BEF692406D0 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EB55A3A0D6F for ; Sun, 28 May 2023 11:14:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:12 +0200 Message-Id: <20230528091416.17927-20-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/24] fftools/ffmpeg_filter: make ifilter_has_all_input_formats() static 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: zuWAc7FeXbvw It is no longer used outside ffmpeg_filter. --- fftools/ffmpeg.h | 2 -- fftools/ffmpeg_filter.c | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 75695d3fb5..398bcc58e1 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -751,8 +751,6 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t */ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec); -int ifilter_has_all_input_formats(FilterGraph *fg); - void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); /** diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e0843b0729..9c29850a26 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -537,6 +537,18 @@ fail: return ret; } +// Filters can be configured only if the formats of all inputs are known. +static int ifilter_has_all_input_formats(FilterGraph *fg) +{ + int i; + for (i = 0; i < fg->nb_inputs; i++) { + InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); + if (ifp->format < 0) + return 0; + } + return 1; +} + static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) { AVFilterContext *ctx = inout->filter_ctx; @@ -1660,18 +1672,6 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr return 0; } -// Filters can be configured only if the formats of all inputs are known. -int ifilter_has_all_input_formats(FilterGraph *fg) -{ - int i; - for (i = 0; i < fg->nb_inputs; i++) { - InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); - if (ifp->format < 0) - return 0; - } - return 1; -} - int filtergraph_is_simple(FilterGraph *fg) { FilterGraphPriv *fgp = fgp_from_fg(fg); From patchwork Sun May 28 09:14:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41858 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987646pzb; Sun, 28 May 2023 02:16:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QvXeboEJDGvJIgUTiY/gXn//adq6dpx+aqaS4Nta83hYUY4oRPYIpdDrtVd3Kn/7e6h1W X-Received: by 2002:a17:907:96a6:b0:94b:958c:8827 with SMTP id hd38-20020a17090796a600b0094b958c8827mr7908915ejc.56.1685265384575; Sun, 28 May 2023 02:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265384; cv=none; d=google.com; s=arc-20160816; b=QHNNkQ+oC5+PkFpt2TVSHWcUPeo/s4NjExnbtSvvq6gYGR+3pbV8rPMcLk3cgyekS0 qBVw/VOW7U3u2GjCIqTPoEWsGLAXpyLLzozmaKOXwOcfRe208lGv6t3/vPg75PXowrE9 R8dDAgTfvdaA+V5WoijVeemgHJrsOdYK3kBHuj3DOHX/e5zLEFbRzr+khJFwIK8r5Szg QAP6D46z48TAX8NkIoZaCCT1yytldI4ioe9+PYqko18GAK3jTIwGfuvOUQhR13yLnHiR +FyoqN47FHQnk45dT1xIBgqJ7QQKuc4yNWjQGb48CBwoQ3mAUvMVKs+rT3Nn6rqPVyoL ISjg== 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=1EMPFYA5zgsV2FHqWWF1U9KsdZQw9OxcY+v/47O0ZBI=; b=eJmiR8n4/nNlQ4Fisi60YrIOZV0E0908XUSJO9zSj/1/9RppXVlQAq3rQrGKblZF2+ IVJTq6Ns+M5WQkv1b8tMEV5mzTGuEsJY6kdr89zLWXc1ERc8qncEDb1/YUirCi59QE81 Hauk4NK4WkaTTfbaByj6njb2K7VNsE8NyuM6PduMFsr3asaCNemH0tmv9IG19Nb0TX1L iJJZcv0au/wJHZIbhlDx6fBncyrEDGu/9GkCCxvfOo/7gVMjeRR8a6PRN94ULPwshpTV k49JJ+HuROhT6FfVEaSoQr27O96BBm2jTEcvXiTGg+SuBb28d6PvuRORacA80QLK+aHs 7XoA== 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 ne6-20020a1709077b8600b0096aa0ecdc1esi838612ejc.499.2023.05.28.02.16.23; Sun, 28 May 2023 02:16:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B7AAC68C225; Sun, 28 May 2023 12:15:04 +0300 (EEST) 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 B8B4768C1F5 for ; Sun, 28 May 2023 12:14:56 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 850272404F5 for ; Sun, 28 May 2023 11:14:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id MH8kdfeqnbN7 for ; Sun, 28 May 2023 11:14:55 +0200 (CEST) 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 BF01C240705 for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 024073A0D86 for ; Sun, 28 May 2023 11:14:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:13 +0200 Message-Id: <20230528091416.17927-21-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/24] fftools/ffmpeg_filter: make InputStream.filter private 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: 5oCWpgtMUGtV It is no longer accessed outside of ffmpeg_filter. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_filter.c | 32 +++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 398bcc58e1..655b5c7ec5 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -278,7 +278,6 @@ typedef struct OptionsContext { } OptionsContext; typedef struct InputFilter { - AVFilterContext *filter; struct FilterGraph *graph; uint8_t *name; } InputFilter; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 9c29850a26..0bd0593724 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -57,6 +57,8 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg) typedef struct InputFilterPriv { InputFilter ifilter; + AVFilterContext *filter; + InputStream *ist; // used to hold submitted input @@ -181,7 +183,7 @@ static void sub2video_push_ref(InputFilterPriv *ifp, int64_t pts) av_assert1(frame->data[0]); ifp->sub2video.last_pts = frame->pts = pts; - ret = av_buffersrc_add_frame_flags(ifp->ifilter.filter, frame, + ret = av_buffersrc_add_frame_flags(ifp->filter, frame, AV_BUFFERSRC_FLAG_KEEP_REF | AV_BUFFERSRC_FLAG_PUSH); if (ret != AVERROR_EOF && ret < 0) @@ -1304,15 +1306,15 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, ist->file_index, ist->index); - if ((ret = avfilter_graph_create_filter(&ifilter->filter, buffer_filt, name, + if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name, args.str, NULL, fg->graph)) < 0) goto fail; par->hw_frames_ctx = ifp->hw_frames_ctx; - ret = av_buffersrc_parameters_set(ifilter->filter, par); + ret = av_buffersrc_parameters_set(ifp->filter, par); if (ret < 0) goto fail; av_freep(&par); - last_filter = ifilter->filter; + last_filter = ifp->filter; desc = av_pix_fmt_desc_get(ifp->format); av_assert0(desc); @@ -1410,11 +1412,11 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, ist->file_index, ist->index); - if ((ret = avfilter_graph_create_filter(&ifilter->filter, abuffer_filt, + if ((ret = avfilter_graph_create_filter(&ifp->filter, abuffer_filt, name, args.str, NULL, fg->graph)) < 0) return ret; - last_filter = ifilter->filter; + last_filter = ifp->filter; snprintf(name, sizeof(name), "trim for input stream %d:%d", ist->file_index, ist->index); @@ -1451,7 +1453,7 @@ static void cleanup_filtergraph(FilterGraph *fg) for (i = 0; i < fg->nb_outputs; i++) fg->outputs[i]->filter = (AVFilterContext *)NULL; for (i = 0; i < fg->nb_inputs; i++) - fg->inputs[i]->filter = (AVFilterContext *)NULL; + ifp_from_ifilter(fg->inputs[i])->filter = NULL; avfilter_graph_free(&fg->graph); } @@ -1571,7 +1573,7 @@ int configure_filtergraph(FilterGraph *fg) InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); AVFrame *tmp; while (av_fifo_read(ifp->frame_queue, &tmp, 1) >= 0) { - ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp); + ret = av_buffersrc_add_frame(ifp->filter, tmp); av_frame_free(&tmp); if (ret < 0) goto fail; @@ -1582,7 +1584,7 @@ int configure_filtergraph(FilterGraph *fg) for (i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); if (ifp->eof) { - ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL); + ret = av_buffersrc_add_frame(ifp->filter, NULL); if (ret < 0) goto fail; } @@ -1755,7 +1757,7 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t overlayed subpicture and its start/end times */ sub2video_update(ifp, pts2 + 1, NULL); - if (av_buffersrc_get_nb_failed_requests(ifilter->filter)) + if (av_buffersrc_get_nb_failed_requests(ifp->filter)) sub2video_push_ref(ifp, pts2); } @@ -1769,7 +1771,7 @@ int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle) if (ifp->sub2video.end_pts < INT64_MAX) sub2video_update(ifp, INT64_MAX, NULL); - return av_buffersrc_add_frame(ifilter->filter, NULL); + return av_buffersrc_add_frame(ifp->filter, NULL); } sub2video_update(ifp, INT64_MIN, subtitle); @@ -1802,11 +1804,11 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) ifp->eof = 1; - if (ifilter->filter) { + if (ifp->filter) { pts = av_rescale_q_rnd(pts, tb, ifp->time_base, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); - ret = av_buffersrc_close(ifilter->filter, pts, AV_BUFFERSRC_FLAG_PUSH); + ret = av_buffersrc_close(ifp->filter, pts, AV_BUFFERSRC_FLAG_PUSH); if (ret < 0) return ret; } else { @@ -1928,7 +1930,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) ) #endif - ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, + ret = av_buffersrc_add_frame_flags(ifp->filter, frame, AV_BUFFERSRC_FLAG_PUSH); if (ret < 0) { av_frame_unref(frame); @@ -1984,7 +1986,7 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) ist = ifp->ist; if (input_files[ist->file_index]->eagain || ifp->eof) continue; - nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->filter); + nb_requests = av_buffersrc_get_nb_failed_requests(ifp->filter); if (nb_requests > nb_requests_max) { nb_requests_max = nb_requests; *best_ist = ist; From patchwork Sun May 28 09:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41863 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988034pzb; Sun, 28 May 2023 02:17:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LBoyDJ/4roqwH61CZ1FHdyxvMo+k+m4arpt8mzrqMjD2biFPyz/H9cphf9pFw8GSaFeXV X-Received: by 2002:a17:906:6a29:b0:973:940e:a01d with SMTP id qw41-20020a1709066a2900b00973940ea01dmr7416214ejc.67.1685265428523; Sun, 28 May 2023 02:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265428; cv=none; d=google.com; s=arc-20160816; b=HALryaJI/FWeCyiC1gybWvLqjPuY7zTyr1HfrhWTUzPtWcEp4eTZUYm+atm51xr5jB jCmMHoxLcofbmNMshuus8fVA/L4E6L/9R7LhBDkyxMKb3xBmspcR1o6i9bE1IykcB3PE 7GRCiStSdk7+h3iu6gu/IpRHKz7T7d323xVFkOvx4us6PtKh6Rq3m7Zl0Zofplt+wV8d T8yR2aAfL/dgzb4O+ZnzkJYV8V9szNQbHsPZbPAIAq3kNzhJBPPU9bfvHtYuiqs1kL1L /a88fsrJoTFeE+OQXpE7n/iV0E6HsWYb833/PTBgqKAIdRiIFynnYolmpFsr1tIvnLLL aokA== 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=MDQ+jvNQ3ab+Wq6yudxuv74lC9ozHNJfj3CXdJDChao=; b=Q2M4fj9jLNmUl+RkHZxDIoC/bouzWeOhgs1K+oUt08OGyvuS1UMW8wRXOySJrZa8Kv /bFRycmVi4zZU460lTvQ2+eJdSC+MH5wH61cOGMUMti9wkx7hqcNpOWOjTHkptNos4B0 WfX3e79Bd94/G8sIQtlKi40eriBdDT0lGcFX1wnfd1l1VmOgHchCcqYe9KZLZzEejoLg be0j+hJ2SOZUFvCumOe+cTJsC31LhcPc0vBhQ2AuIcYV+08/A+xLW0dl7FDFqRuJRTA/ ovb7dO5Vhi19jfuRUzzJ5+X+GV9im6VXo/v4Yqe1M4uYxCuX1rRdzV0vUPGH62iS3EIz a4zA== 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 jg30-20020a170907971e00b0096f78953b79si3856016ejc.138.2023.05.28.02.17.08; Sun, 28 May 2023 02:17:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 1D4E468C263; Sun, 28 May 2023 12:15:10 +0300 (EEST) 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 B2E6168C214 for ; Sun, 28 May 2023 12:14:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7FBE42404F5 for ; Sun, 28 May 2023 11:14:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id TPaGFIea85wM for ; Sun, 28 May 2023 11:14:58 +0200 (CEST) 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 D318C240D1B for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0DDCD3A0D97 for ; Sun, 28 May 2023 11:14:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:14 +0200 Message-Id: <20230528091416.17927-22-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/24] fftools/ffmpeg_filter: constify the argument of filtergraph_is_simple() 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: pb5hZVan34WV --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_filter.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 655b5c7ec5..966397270d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -731,7 +731,7 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id int configure_filtergraph(FilterGraph *fg); void check_filter_outputs(void); -int filtergraph_is_simple(FilterGraph *fg); +int filtergraph_is_simple(const FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc); int init_complex_filtergraph(FilterGraph *fg); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 0bd0593724..62ba27e559 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -54,6 +54,11 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg) return (FilterGraphPriv*)fg; } +static const FilterGraphPriv *cfgp_from_cfg(const FilterGraph *fg) +{ + return (const FilterGraphPriv*)fg; +} + typedef struct InputFilterPriv { InputFilter ifilter; @@ -1674,9 +1679,9 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr return 0; } -int filtergraph_is_simple(FilterGraph *fg) +int filtergraph_is_simple(const FilterGraph *fg) { - FilterGraphPriv *fgp = fgp_from_fg(fg); + const FilterGraphPriv *fgp = cfgp_from_cfg(fg); return fgp->is_simple; } From patchwork Sun May 28 09:14:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41860 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp987789pzb; Sun, 28 May 2023 02:16:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6A3SWJV8dhWzFU0rtsqJ0Jpc+0DJKNDdrR6rwIEXzAQ1VpX4jxDUdZQrDOLnZM1NHw5lie X-Received: by 2002:aa7:ce12:0:b0:510:f6e0:7d9f with SMTP id d18-20020aa7ce12000000b00510f6e07d9fmr5397153edv.13.1685265403124; Sun, 28 May 2023 02:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265403; cv=none; d=google.com; s=arc-20160816; b=wzdzEe72NQZ12+axeS18bQzOjSwfXSW9R5b9JckG4T0m46JsN+jFdvJ7mCKm7Jt2t0 RwoqcNODSf4NKprh5UxQQNvoFWY03CrYCGXNA/2esBmXb1lFxsH32hD5uNwuNFSw9ab6 M4RBTXXsdcX+Tb7LVAbtPUnVYuO2TCub38Vi1oXkmVW9Z3u8rDomQWstWmaCQQ4Z97lR 90D2lecDBCXppDkqoUSk7GH1YXs+2fPRop/1Bl7Ww8ZSmuLWLor4B4zwvN/40QGf97Fc kNR6zHRyqOX8Rrp5HwypuGoNwpqh8DA7Ol+lqp0jVABteZv//QovRx+5vLCwyAMjECfh ZQWA== 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=K14RMTMsR5MwlRRROfPBmtgvPfYvmi/LnS183LMICcM=; b=VtJ+K9ZlQ5T5zK3qEtOjDN7F+R4tXdJw559rjxaXggPm1H1r6Hpor9yxT1BfwrmdhW 3JkuQbhJV1n3aQqrVRY83QATw60dUbor3AgRNtXQ4Ct84E2YA9L4dPLRLwTmK3NajbRr KEmrlCSF4xVq1+4UyZRfChVuTZ4cnrFjdt/oxwTFb/SKjhjIiTQuJdtAGVszt3B1sjQF gTN6JS6so7K8pjYEBCF/Wg5Isbvj6yCYftXcUwyVPQvrVXIQacm4YF/MSLPkSaEDjiOM QuZt6+TMzv3/2COt+YWQ4YnJwvdOmyBp7TcDRDQob7qvRxj8lT8eP58VqhuhzTAaIIJ2 UuIQ== 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 c8-20020a056402100800b00506758661fdsi2824627edu.618.2023.05.28.02.16.41; Sun, 28 May 2023 02:16:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 E2DC168C25B; Sun, 28 May 2023 12:15:06 +0300 (EEST) 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 3D2F668C1FB for ; Sun, 28 May 2023 12:14:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 08D8E240591 for ; Sun, 28 May 2023 11:14:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ddpzEnYwZEpa for ; Sun, 28 May 2023 11:14:56 +0200 (CEST) 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 BED2C2406CF for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 198893A0DAB for ; Sun, 28 May 2023 11:14:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:15 +0200 Message-Id: <20230528091416.17927-23-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/24] fftools/ffmpeg_mux: flush bsfs immediately on exceeding recoding time 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: Z3ZSTM3NvSSK Current code marks the output stream as finished and waits for a flush packet, but that is both unnecessary and suspect, as in theory nothing should be sent to a finished stream - not even flush packets. --- fftools/ffmpeg_mux.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 3da3c04d7f..feb014ca31 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -386,6 +386,11 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) AVPacket *opkt = ost->pkt; av_packet_unref(opkt); + + if (of->recording_time != INT64_MAX && + dts >= of->recording_time + start_time) + pkt = NULL; + // EOF: flush output bitstream filters. if (!pkt) { of_output_packet(of, opkt, ost, 1); @@ -407,12 +412,6 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) return; } - if (of->recording_time != INT64_MAX && - dts >= of->recording_time + start_time) { - close_output_stream(ost); - return; - } - if (av_packet_ref(opkt, pkt) < 0) exit_program(1); From patchwork Sun May 28 09:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41868 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp988390pzb; Sun, 28 May 2023 02:17:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/C2cbhnBvGbYOoghz2Xz+7n6W72+WikWz4MEhzXcxET2xdnG31qkRzSqdm+rcIwz5c5OG X-Received: by 2002:a17:907:9719:b0:973:713c:d792 with SMTP id jg25-20020a170907971900b00973713cd792mr4517028ejc.28.1685265472116; Sun, 28 May 2023 02:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685265472; cv=none; d=google.com; s=arc-20160816; b=Yn6J15ml20DyZt4lnE7NyWPNQQ8rRH0dM16thzX+3/6x2cWgtyqTUQtz0u8vl3xfrg 0Q9P7Qyh2m54yqq+gac7tGz43tw0akp+QTwhsUrUT/j/edWm6XF00SXkjwiyvLovyVF8 aEYpsyWV7JR+cuvleNM9ZYdgtuCMVML4UeVCYxGmY1y2lXLDSOHy1yqlBy8EwdRCj2NA 6iSrXlBFn5My9GT+ixouaLNEXHZjwPp6sldiGogH123o9ySadb3P0dyWHC/C5eJJlkd8 sJk/VgrRLr/PvD0xCZeO+2P+HF1ExhQfLMBRaXhHqdDV+R7LBtb28VXMES/HSTYU46jf NiJw== 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=NrGO/VYsPPVRdOrnSa4jcjyNsj9Trj1cdaftB8XJVkY=; b=zT0QcfezKKirBgSUeq3MI274EzIwjUf9+3VC9TNfRbI1qa8HoDmUEt/6bdrtdRQQIO QCi5M7R/D44FETcnmNZ9zJnzE7LbjWZR90RxYj6QzNj06JPVgFgBOpnfp9g6kI1nu1WC 4pf7scDyn+9mNSno50tTQbjKEezNFVrujiY5IlKCZWh7kZ+JkIjp5eVlhJrVGBdlcE2G /sosx5hwTNk7gggvL4MWoqAvvNz7vVzMdyGQGnrd9ePXGJ/6/UDZMDZ/FwfGgGefgpr5 OzJOeLRtHDNBFzpcD901qbWr+5wgNgnY2JGzhbwlGwdypuy3CaRU6mroFhIKm4QYbQQ/ 8A/w== 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 hy11-20020a1709068a6b00b00965cc76c350si5374606ejc.17.2023.05.28.02.17.51; Sun, 28 May 2023 02:17:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 B3D1F68C278; Sun, 28 May 2023 12:15:14 +0300 (EEST) 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 4425168C226 for ; Sun, 28 May 2023 12:14:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F1DAC2404F5 for ; Sun, 28 May 2023 11:14:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id N7KGQLSRMtTN for ; Sun, 28 May 2023 11:14:58 +0200 (CEST) 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 DA673240D1D for ; Sun, 28 May 2023 11:14:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 251793A0DB0 for ; Sun, 28 May 2023 11:14:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 May 2023 11:14:16 +0200 Message-Id: <20230528091416.17927-24-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528091416.17927-1-anton@khirnov.net> References: <20230528091416.17927-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/24] fftools/ffmpeg_filter: do not flush encoders on parameter change 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: NzNYU757HY5T It makes no sense to do so. --- fftools/ffmpeg_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 62ba27e559..1eac253023 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1905,7 +1905,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) return ret; } - ret = reap_filters(1); + ret = reap_filters(0); if (ret < 0 && ret != AVERROR_EOF) { av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret)); return ret;