From patchwork Thu Jun 16 19:55:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36283 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1129367pzb; Thu, 16 Jun 2022 13:07:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfvRCdczhqcVbWiItiMYVtDXwfOrHmBFrb8hPIy7ywwghLaLDb5MmlGaWhEygN+X1FWGNe X-Received: by 2002:a05:6402:354c:b0:431:51e2:eef9 with SMTP id f12-20020a056402354c00b0043151e2eef9mr8770430edd.344.1655410068989; Thu, 16 Jun 2022 13:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655410068; cv=none; d=google.com; s=arc-20160816; b=Irpggkzz/hc1MCydiW9yNUBMn4Emv9JyIMmTGhMEinLyUu6VT2mN9jkOdz7iVkpKo2 7wn+g37Rs2VLX92+07NAE/DaZ4OGgLqmv0CIIrSEFN2nLdnIweT/vIhL01p6iSNw7KiC 8LFQr+1/QcWFvpCoGag3uJjd4uzhs7hoexD7+76uKugLsKFZWCEELDnc4iA+TnyzZ2JG LJUPcGFtZOs1Y7Xw193IJy++23McbGYo1CR/EMf4Yc5fGgnwPKpNkJIqb0rw6YnPqifG layRQwVBd84tASiP8pJfMCZv+whW6SDexp7tZsYMGq28Zdj08uwnbeL4EQlPgbl7zwjk XIUA== 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=heV27fZEAOCMlcJmhxB2ZmUlYT+lenOyrYEI9GDKf1U=; b=sLSG7JUpUEtW34TajgiutfstLgI/fiIvr9FYXK2cFfKSGye3iw1chV6tWvZnMpRZ67 L997rgglMvS5+AHmDB/IB/H5VAjHfOzSQXwwGkmItshC8xTuA+nKX/LaDNCMeipswVAx b5wICQeoh7XztuQkBY7gl/7efQFeR+0KXP44nQ+Xb1EvAnQN5kRKAL+0jRgx53/H//X9 nK8IBCcQa3fiMeiBn6ADGzSRsPwWgT3hSp2xznx/pu9EC6IsKcyAaVabEoI9ktPyajBN ixEUtgFdSAg9bWKLeXLH1LQZQb43wREjGqSNLAdLvfZoZOsRBh6dBFyxM1SYVF2nqwfI gM/A== 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 sg6-20020a170907a40600b00711fca6bc59si2979871ejc.263.2022.06.16.13.07.48; Thu, 16 Jun 2022 13:07:48 -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 9B55D68B85C; Thu, 16 Jun 2022 23:04: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 6F5D568B878 for ; Thu, 16 Jun 2022 23:03:48 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 08C8A240175 for ; Thu, 16 Jun 2022 22:03:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0hv-wgcWUSkm for ; Thu, 16 Jun 2022 22:03: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 4E63F240687 for ; Thu, 16 Jun 2022 22:03:34 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id BE16E3A1EEB; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:15 +0200 Message-Id: <20220616195534.5278-16-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195534.5278-1-anton@khirnov.net> References: <20220616195534.5278-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/35] 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: sxwzPP0Z+x5G --- fftools/ffmpeg.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index f60013eace..b8a11818b8 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -140,8 +140,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; @@ -558,8 +556,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]); @@ -989,7 +985,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; @@ -1003,14 +999,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 ? */ @@ -1030,6 +1018,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); @@ -1040,8 +1034,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) { @@ -1049,8 +1042,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);