From patchwork Thu Mar 2 15:03:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 2734 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.31.14 with SMTP id f14csp289844vsf; Thu, 2 Mar 2017 07:03:11 -0800 (PST) X-Received: by 10.28.28.69 with SMTP id c66mr9032791wmc.28.1488466990904; Thu, 02 Mar 2017 07:03:10 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x95si10949649wrb.293.2017.03.02.07.03.10; Thu, 02 Mar 2017 07:03:10 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F0876883D8; Thu, 2 Mar 2017 17:02:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C2166882EA for ; Thu, 2 Mar 2017 17:02:50 +0200 (EET) Received: by mail-wm0-f68.google.com with SMTP id v190so6912701wme.3 for ; Thu, 02 Mar 2017 07:03:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:mime-version; bh=k+t0dAFKbCZWUMxgZvOIyxwphq4AG1I2s9UVHPIhEDo=; b=BoafzwaLXdTTgg6Z11FstkTrjebwAx/q1xHEWyXtUCbvR2fLdk1OIGl77cCfX6j1BO g7qkQX0iLo9Msr24xaMtnR7iVHh9M+R5Zk23aqaWH7AjunKTTFTJXWUVWsXSkd80goyl KisOFwZ9tntDiv6TiDYGnZvWS3VPAKTNwmwtuoWVe8t1MW/uUkTfIjws/d/zMUmtj/5U prLVtlld1eR8UB0zOOT5LLc7DyPirxY1y+2g2Z0kxcrdtPyWUIpiTA2YAv/FjbNQMmsN s7Y+O21wfd+QvZUTg9hMXY+eyu7I0Zwk/fmK56grB9JgsWy6asp2+y9QDYS4GhakCDXv PLvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version; bh=k+t0dAFKbCZWUMxgZvOIyxwphq4AG1I2s9UVHPIhEDo=; b=TaYlHlrI/OqQdVlbRyBkWu3RgtwPJfUMt6qTBzus1xoKf7QPxP6++uzQCEL9frdeS4 MM7EiDf8+SBfgvaqi/D51kE9NkZ776GNtY0R9Dm+wN/CWALT/ZtAbcCN0xliDNdg4efs w5Z955A+L6Axg9E18VJ6GYWRWjb6ZoDJmQ7L67InKoWNExNkYB5DXoYWck3QsxcmLelc x4qd1+Wpe0qQIlQHmc3ytWGohX+/wKVpXz0fmpol25yRYfsdEi6QbIhFQyFwzWVEpaM0 B5YM2x+revZ3uzlDeLk2ygoKmpB9MwOK8lD7FmTNjAFtKCGwSlU+ceCWnIf5lrZTdQPW vT5w== X-Gm-Message-State: AMke39nB1G8wIYcFaKDSqeClf1OA+SIGsnDfb/c2std5rj3Ya8FIsf2qErat6ZA8TUbEeQ== X-Received: by 10.28.17.11 with SMTP id 11mr3404196wmr.32.1488466981228; Thu, 02 Mar 2017 07:03:01 -0800 (PST) Received: from debian (p4FF003DA.dip0.t-ipconnect.de. [79.240.3.218]) by smtp.googlemail.com with ESMTPSA id r82sm8223419wmd.32.2017.03.02.07.03.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Mar 2017 07:03:00 -0800 (PST) Date: Thu, 2 Mar 2017 16:03:02 +0100 From: wm4 To: ffmpeg-devel@ffmpeg.org Message-ID: <20170302160302.471dc009@debian> In-Reply-To: <20170302130318.GB5776@nb4> References: <20170210123541.32375-1-nfxjfg@googlemail.com> <20170302085309.11471-1-nfxjfg@googlemail.com> <20170302130318.GB5776@nb4> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v3 0/7] Merge lazy filter initialization in ffmpeg CLI X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" On Thu, 2 Mar 2017 14:03:18 +0100 Michael Niedermayer wrote: > This one looses the first displayed subtitle (the green "help") > ./ffmpeg -i ~/tickets/153/bbc_small.ts -filter_complex '[0:v][0:s]overlay' -qscale 2 -t 3 test.avi Attached patch fixes it. Will push it as part of the series tomorrow. From adb5854221bb55d34a225bea9c2c29c7bbbfe8c0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 2 Mar 2017 16:01:01 +0100 Subject: [PATCH] ffmpeg: delay processing of subtitles before filters are initialized If a subtitle packet came before the first video frame could be fully decoded, the subtitle packet would get discarded. This puts the subtitle into a queue instead, and processes it once the attached filter graph is initialized. --- ffmpeg.c | 22 +++++++++++++++++++--- ffmpeg.h | 3 +++ ffmpeg_filter.c | 13 +++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 27bfc72cff..d232bbd7fd 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -226,7 +226,7 @@ static void sub2video_push_ref(InputStream *ist, int64_t pts) AV_BUFFERSRC_FLAG_PUSH); } -static void sub2video_update(InputStream *ist, AVSubtitle *sub) +void sub2video_update(InputStream *ist, AVSubtitle *sub) { AVFrame *frame = ist->sub2video.frame; int8_t *dst; @@ -2468,6 +2468,7 @@ fail: static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) { AVSubtitle subtitle; + int free_sub = 1; int i, ret = avcodec_decode_subtitle2(ist->dec_ctx, &subtitle, got_output, pkt); @@ -2502,7 +2503,21 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) if (!*got_output) return ret; - sub2video_update(ist, &subtitle); + if (ist->sub2video.frame) { + sub2video_update(ist, &subtitle); + } else { + if (!ist->sub2video.sub_queue) + ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle)); + if (!ist->sub2video.sub_queue) + exit_program(1); + if (!av_fifo_space(ist->sub2video.sub_queue)) { + ret = av_fifo_realloc2(ist->sub2video.sub_queue, 2 * av_fifo_size(ist->sub2video.sub_queue)); + if (ret < 0) + exit_program(1); + } + av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL); + free_sub = 0; + } if (!subtitle.num_rects) goto out; @@ -2520,7 +2535,8 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) } out: - avsubtitle_free(&subtitle); + if (free_sub) + avsubtitle_free(&subtitle); return ret; } diff --git a/ffmpeg.h b/ffmpeg.h index 59f6cb3659..06a1251124 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -337,6 +337,7 @@ typedef struct InputStream { struct sub2video { int64_t last_pts; int64_t end_pts; + AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init AVFrame *frame; int w, h; } sub2video; @@ -636,6 +637,8 @@ int filtergraph_is_simple(FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost); int init_complex_filtergraph(FilterGraph *fg); +void sub2video_update(InputStream *ist, AVSubtitle *sub); + int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame); int ffmpeg_parse_options(int argc, char **argv); diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index 816c906c7e..da2a46d3b7 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -1137,6 +1137,19 @@ int configure_filtergraph(FilterGraph *fg) } } + /* process queued up subtitle packets */ + for (i = 0; i < fg->nb_inputs; i++) { + InputStream *ist = fg->inputs[i]->ist; + if (ist->sub2video.sub_queue && ist->sub2video.frame) { + while (av_fifo_size(ist->sub2video.sub_queue)) { + AVSubtitle tmp; + av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL); + sub2video_update(ist, &tmp); + avsubtitle_free(&tmp); + } + } + } + return 0; } -- 2.11.0