From patchwork Thu Jun 25 18:35:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 20610 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 46706449F4F for ; Thu, 25 Jun 2020 21:35:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FBE96880C5; Thu, 25 Jun 2020 21:35:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF099687FCF for ; Thu, 25 Jun 2020 21:35:20 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 05PIZJC7007009 for ; Thu, 25 Jun 2020 20:35:20 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id A246DEB5C1; Thu, 25 Jun 2020 20:35:19 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Jun 2020 20:35:16 +0200 Message-Id: <20200625183518.1217406-1-george@nsup.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 25 Jun 2020 20:35:20 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/3] lavfi/buffersink: add av_buffersink_get_pts(). 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" TODO APIChange & bump Signed-off-by: Nicolas George --- libavfilter/buffersink.c | 5 +++++ libavfilter/buffersink.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 76a46f6678..c65a5051a4 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -125,6 +125,11 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, return get_frame_internal(ctx, frame, 0, nb_samples); } +int64_t av_buffersink_get_pts(AVFilterContext *ctx) +{ + return ctx->inputs[0]->current_pts; +} + #if FF_API_NEXT AVBufferSinkParams *av_buffersink_params_alloc(void) { diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 2ec821c685..b3e3cc0f29 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -59,6 +59,11 @@ int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flag */ #define AV_BUFFERSINK_FLAG_NO_REQUEST 2 +/** + * Get the current PTS, i.e. the PTS of the last frame or the end of stream. + */ +int64_t av_buffersink_get_pts(AVFilterContext *ctx); + #if FF_API_NEXT /** * Struct to use for initializing a buffersink context. From patchwork Thu Jun 25 18:35:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 20608 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A46D9449F4F for ; Thu, 25 Jun 2020 21:35:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7EB5568805D; Thu, 25 Jun 2020 21:35:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9E8168011F for ; Thu, 25 Jun 2020 21:35:20 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 05PIZJ4X007010 for ; Thu, 25 Jun 2020 20:35:20 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id E1795EB5C3; Thu, 25 Jun 2020 20:35:19 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Jun 2020 20:35:17 +0200 Message-Id: <20200625183518.1217406-2-george@nsup.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200625183518.1217406-1-george@nsup.org> References: <20200625183518.1217406-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 25 Jun 2020 20:35:20 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg: move filter/encoder PTS computation to a separate function. 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" Signed-off-by: Nicolas George --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448ea2b..3919f2ab62 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1404,6 +1404,32 @@ static void finish_output_stream(OutputStream *ost) } } +static double compute_encoder_pts_from_filter_pts(AVFilterContext *filter, OutputFile *of, + AVCodecContext *enc, int64_t *filtered_frame_pts) +{ + double float_pts = AV_NOPTS_VALUE; + + if (*filtered_frame_pts != AV_NOPTS_VALUE) { + int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; + AVRational filter_tb = av_buffersink_get_time_base(filter); + AVRational tb = enc->time_base; + int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); + + tb.den <<= extra_bits; + float_pts = + av_rescale_q(*filtered_frame_pts, filter_tb, tb) - + av_rescale_q(start_time, AV_TIME_BASE_Q, tb); + float_pts /= 1 << extra_bits; + // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers + float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); + + *filtered_frame_pts = + av_rescale_q(*filtered_frame_pts, filter_tb, enc->time_base) - + av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); + } + return float_pts; +} + /** * Get and encode new output from any of the filtergraphs, without causing * activity. @@ -1460,24 +1486,7 @@ static int reap_filters(int flush) av_frame_unref(filtered_frame); continue; } - if (filtered_frame->pts != AV_NOPTS_VALUE) { - int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; - AVRational filter_tb = av_buffersink_get_time_base(filter); - AVRational tb = enc->time_base; - int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); - - tb.den <<= extra_bits; - float_pts = - av_rescale_q(filtered_frame->pts, filter_tb, tb) - - av_rescale_q(start_time, AV_TIME_BASE_Q, tb); - float_pts /= 1 << extra_bits; - // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers - float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); - - filtered_frame->pts = - av_rescale_q(filtered_frame->pts, filter_tb, enc->time_base) - - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); - } + float_pts = compute_encoder_pts_from_filter_pts(filter, of, enc, &filtered_frame->pts); switch (av_buffersink_get_type(filter)) { case AVMEDIA_TYPE_VIDEO: From patchwork Thu Jun 25 18:35:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 20609 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 69FA6449F4F for ; Thu, 25 Jun 2020 21:35:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 540B8688091; Thu, 25 Jun 2020 21:35:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACEB268066A for ; Thu, 25 Jun 2020 21:35:21 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 05PIZKfb007012 for ; Thu, 25 Jun 2020 20:35:20 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 2BCF4EB5C5; Thu, 25 Jun 2020 20:35:20 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Jun 2020 20:35:18 +0200 Message-Id: <20200625183518.1217406-3-george@nsup.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200625183518.1217406-1-george@nsup.org> References: <20200625183518.1217406-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 25 Jun 2020 20:35:20 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg: get EOF timestamp from filter. 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" Signed-off-by: Nicolas George --- fftools/ffmpeg.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) This breaks fate-lagarith-ticket4119-cfr. I have decided to leave it. The new output is more correct. The input ends with: pts_time=2.000000 duration_time=0.040000 It is right that the output file ends at 2.04, not at 3.00. I did not change the ref file, because it was there for something: there may be a bug to fix for ticket 4119, but the fix that was done was wrong. In fact, I suspect 9f6d48d696d679de77e8cb513d5f64cd708ed86f should be reverted entirely. Or we could just drop this chunk of code and insert the fps filter. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3919f2ab62..b1c7745d93 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1075,7 +1075,7 @@ static void do_video_out(OutputFile *of, duration = lrintf(next_picture->pkt_duration * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)); } - if (!next_picture) { + if (!next_picture && sync_ipts == AV_NOPTS_VALUE) { //end, flushing nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0], ost->last_nb0_frames[1], @@ -1152,6 +1152,8 @@ static void do_video_out(OutputFile *of, default: av_assert0(0); } + if (!next_picture) + nb0_frames = FFMAX(nb_frames, 1) - 1; } nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); @@ -1477,8 +1479,11 @@ static int reap_filters(int flush) av_log(NULL, AV_LOG_WARNING, "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret)); } else if (flush && ret == AVERROR_EOF) { - if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) - do_video_out(of, ost, NULL, AV_NOPTS_VALUE); + if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) { + int64_t pts = av_buffersink_get_pts(filter); + float_pts = compute_encoder_pts_from_filter_pts(filter, of, enc, &pts); + do_video_out(of, ost, NULL, float_pts); + } } break; }