From patchwork Mon Apr 4 11:30:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35193 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1915378pzb; Mon, 4 Apr 2022 04:40:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNCYZso1fiK+P9wa6JR3A4mmP8mdcfI3X5C25JjrIupKYoBZQJsSeeLm8uQEyjEe+F7Vye X-Received: by 2002:a17:907:86a3:b0:6da:870c:af44 with SMTP id qa35-20020a17090786a300b006da870caf44mr10048063ejc.445.1649072403504; Mon, 04 Apr 2022 04:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649072403; cv=none; d=google.com; s=arc-20160816; b=EMa5hTCujmlJO1s06bQsLb6rraEI1VR8wLE+kR1tOKP5TCLBRcuLAymTCqo4Ze/ccT 40Q7E1+mkorlkZVjCTP55TLH6KgO+vhVj1hovB9AGAUoYTfRwLFsn4x8LxYDOhm0pV7K MqDeI9ID7t7YY7rIk5lLHrWlOl8cvmaCYLLdxcZ0M2wLMxlCfRxhksJFw1DGRXWvjHTu CW513vtjS/Dlh5yVsGM5n7T/i3MlMHvIs3nR2VcP283V5gYylgQS0MglzsQII3tSCS8W 7xHi8hylLdzpmj0kDoGs1AnzBUCs7diGUYCcx5+nW0wS5NyK81aPc3pWQUaUgGmPAk2z S/hw== 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=9khHpXqmmx1nLBr1EIp/D0swGodSykYtBPBCSjdSZxw=; b=GQqjeqx0bIorBuaYrMyP3F4D71lalTccVoutuuQxIQhCvICYeJJKBUrtAT/KXi84be wyVrI544q2D4bTl7IUpgSmB9ojE+X4vFwvyfKELF9F1Q3i8BTWQewETsdJUfURHlNbaI PyBTLfR/0N6QPr6KEErC7afkybNbw2ccOoh3QCJ9YOYUb7OELvNhdeOWfre6Cxup4NM5 MUyC6yVaw0fN41Cqe0ERGykcnMbhX1q3wxvd7TCT4A6S4SalkRC3p8UyPlVYaeRWHgpk ZVX0amBnJdYAZz9GUlgBpc8SXymg/D3C+seRyDWUynyhzankKKqraVC/t22psUjuDHmO MISg== 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 hw13-20020a170907a0cd00b006e0ae9e6ed9si2569333ejc.498.2022.04.04.04.40.03; Mon, 04 Apr 2022 04:40:03 -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 5CE0068B376; Mon, 4 Apr 2022 14:37: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 1711068B350 for ; Mon, 4 Apr 2022 14:37:46 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BF6352404FE for ; Mon, 4 Apr 2022 13:37:45 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5Kw5_1wD50C1 for ; Mon, 4 Apr 2022 13:37:45 +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 B2570240512 for ; Mon, 4 Apr 2022 13:37:41 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 1C6053A0D35; Mon, 4 Apr 2022 13:32:12 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Apr 2022 13:30:21 +0200 Message-Id: <20220404113037.13070-34-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404113037.13070-1-anton@khirnov.net> References: <20220404113037.13070-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 33/49] fftools/ffmpeg: use refcounted packets for encoded subtitles 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: g4w1AEd6cciI --- fftools/ffmpeg.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e0f15c0f61..07d1fc8a5d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -141,8 +141,6 @@ unsigned nb_output_dumped = 0; static BenchmarkTimeStamps current_time; AVIOContext *progress_avio = NULL; -static uint8_t *subtitle_out; - InputStream **input_streams = NULL; int nb_input_streams = 0; InputFile **input_files = NULL; @@ -559,8 +557,6 @@ static void ffmpeg_cleanup(int ret) } av_freep(&filtergraphs); - av_freep(&subtitle_out); - /* close files */ for (i = 0; i < nb_output_files; i++) of_close(&output_files[i]); @@ -924,7 +920,7 @@ static void do_subtitle_out(OutputFile *of, AVSubtitle *sub) { int subtitle_out_max_size = 1024 * 1024; - int subtitle_out_size, nb, i; + int subtitle_out_size, nb, i, ret; AVCodecContext *enc; AVPacket *pkt = ost->pkt; int64_t pts; @@ -938,14 +934,6 @@ static void do_subtitle_out(OutputFile *of, enc = ost->enc_ctx; - if (!subtitle_out) { - subtitle_out = av_malloc(subtitle_out_max_size); - if (!subtitle_out) { - av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n"); - exit_program(1); - } - } - /* Note: DVB subtitle need one packet to draw them and one other packet to clear them */ /* XXX: signal it in the codec context ? */ @@ -965,6 +953,12 @@ static void do_subtitle_out(OutputFile *of, if (!check_recording_time(ost)) return; + ret = av_new_packet(pkt, subtitle_out_max_size); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle encode buffer\n"); + exit_program(1); + } + sub->pts = pts; // start_display_time is required to be 0 sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); @@ -975,8 +969,7 @@ static void do_subtitle_out(OutputFile *of, ost->frames_encoded++; - subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, - subtitle_out_max_size, sub); + subtitle_out_size = avcodec_encode_subtitle(enc, pkt->data, pkt->size, sub); if (i == 1) sub->num_rects = save_num_rects; if (subtitle_out_size < 0) { @@ -984,8 +977,6 @@ static void do_subtitle_out(OutputFile *of, exit_program(1); } - av_packet_unref(pkt); - pkt->data = subtitle_out; pkt->size = subtitle_out_size; pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase); pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);