From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B61D9473C5 for ; Wed, 6 Dec 2023 10:30:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B00768CF3A; Wed, 6 Dec 2023 12:30:18 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE6C068C9D3 for ; Wed, 6 Dec 2023 12:30:11 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 66BF21049 for ; Wed, 6 Dec 2023 11:30:11 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id xHiSn91Q2T3q for ; Wed, 6 Dec 2023 11:30:11 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 7AE081D33 for ; Wed, 6 Dec 2023 11:30:10 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 63E723A0613 for ; Wed, 6 Dec 2023 11:30:10 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Dec 2023 11:27:09 +0100 Message-ID: <20231206103002.30084-4-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231206103002.30084-1-anton@khirnov.net> References: <20231206103002.30084-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/10] fftools/ffmpeg_filter: buffer sub2video heartbeat frames like other frames 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Otherwise they'd be silently ignored if received by the filtering thread before the filtergraph can be initialized, which would make the output dependent on the order in which frames from different inputs arrive. --- fftools/ffmpeg_filter.c | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d845448332..1800296aa4 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1769,6 +1769,8 @@ static int graph_is_meta(AVFilterGraph *graph) return 1; } +static int sub2video_frame(InputFilter *ifilter, AVFrame *frame); + static int configure_filtergraph(FilterGraph *fg, const FilterGraphThread *fgt) { FilterGraphPriv *fgp = fgp_from_fg(fg); @@ -1880,7 +1882,7 @@ static int configure_filtergraph(FilterGraph *fg, const FilterGraphThread *fgt) AVFrame *tmp; while (av_fifo_read(ifp->frame_queue, &tmp, 1) >= 0) { if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) { - sub2video_update(ifp, INT64_MIN, (const AVSubtitle*)tmp->buf[0]->data); + sub2video_frame(&ifp->ifilter, tmp); } else { ret = av_buffersrc_add_frame(ifp->filter, tmp); } @@ -2475,9 +2477,6 @@ static void 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; @@ -2495,18 +2494,38 @@ static void sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational tb sub2video_push_ref(ifp, pts2); } -static int sub2video_frame(InputFilter *ifilter, const AVFrame *frame) +static int sub2video_frame(InputFilter *ifilter, AVFrame *frame) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); int ret; + if (!ifilter->graph->graph) { + AVFrame *tmp; + + if (!frame) + return 0; + + tmp = av_frame_alloc(); + if (!tmp) + return AVERROR(ENOMEM); + + av_frame_move_ref(tmp, frame); + + ret = av_fifo_write(ifp->frame_queue, &tmp, 1); + if (ret < 0) { + av_frame_free(&tmp); + return ret; + } + + return 0; + } + // heartbeat frame if (frame && !frame->buf[0]) { sub2video_heartbeat(ifilter, frame->pts, frame->time_base); return 0; } - if (ifilter->graph->graph) { if (!frame) { if (ifp->sub2video.end_pts < INT64_MAX) sub2video_update(ifp, INT64_MAX, NULL); @@ -2518,18 +2537,6 @@ static int sub2video_frame(InputFilter *ifilter, const AVFrame *frame) ifp->height = frame->height ? frame->height : ifp->height; sub2video_update(ifp, INT64_MIN, (const AVSubtitle*)frame->buf[0]->data); - } else if (frame) { - AVFrame *tmp = av_frame_clone(frame); - - if (!tmp) - return AVERROR(ENOMEM); - - ret = av_fifo_write(ifp->frame_queue, &tmp, 1); - if (ret < 0) { - av_frame_free(&tmp); - return ret; - } - } return 0; } -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".