From patchwork Fri Jul 19 16:52:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Zibis X-Patchwork-Id: 13998 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 CE1BF44967D for ; Fri, 19 Jul 2019 19:52:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A597A68AD0A; Fri, 19 Jul 2019 19:52:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from wp215.webpack.hosteurope.de (wp215.webpack.hosteurope.de [80.237.132.222]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C76CF68AD06 for ; Fri, 19 Jul 2019 19:52:47 +0300 (EEST) Received: from dslb-092-073-107-251.092.073.pools.vodafone-ip.de ([92.73.107.251] helo=[192.168.178.138]); authenticated by wp215.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1hoW7j-0005td-7m; Fri, 19 Jul 2019 18:52:47 +0200 To: FFmpeg development discussions and patches From: Ulf Zibis Message-ID: <74177968-0eaf-671a-bb1e-237502e5a6d6@CoSoCo.de> Date: Fri, 19 Jul 2019 18:52:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Language: de-DE X-bounce-key: webpack.hosteurope.de; ulf.zibis@cosoco.de; 1563555172; 483bd17d; X-HE-SMSGID: 1hoW7j-0005td-7m Subject: [FFmpeg-devel] [PATCH v1] filter select - avoid 2 times rounding 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" Hi, I have seen, that filter select sometimes doesn't catch a frame determined by t as cause of floating point rounding. I could experience less problems after removing 2 times rounding in filter select. I'm aware that there still is a chance to miss a catch, but I believe it should be much more rare. The patch works fine e.g. with: $ ./ffmpeg in.mp4 -vf select='eq(t\,10.16)+eq(t\,10.2)+eq(t\,10.24)+eq(t\,10.28)+eq(t\,10.32)+eq(t\,10.36)+eq(t\,10.4)+eq(t\,10.44)+eq(t\,17.52)+eq(t\,47.96)+eq(t\,49.08)+eq(t\,49.2)+eq(t\,55.72)+eq(t\,83.0)' -vsync vfr out_%02d.png Without the patch the frame for eq(t\,10.2) was missing. -Ulf From f14142a22d340cba48b3e2352a33026590dec3a5 Mon Sep 17 00:00:00 2001 From: Ulf Zibis Date: 19.07.2019, 18:27:51 avfilter/select: avoid twice rounding diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c index 1132375..39cc004 100644 --- a/libavfilter/f_select.c +++ b/libavfilter/f_select.c @@ -297,6 +297,7 @@ #define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d)) #define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)) +#define TS2DT(ts, tb) (TS2D((ts) * (tb).num / (double)(tb).den)) static void select_frame(AVFilterContext *ctx, AVFrame *frame) { @@ -307,11 +308,11 @@ if (isnan(select->var_values[VAR_START_PTS])) select->var_values[VAR_START_PTS] = TS2D(frame->pts); if (isnan(select->var_values[VAR_START_T])) - select->var_values[VAR_START_T] = TS2D(frame->pts) * av_q2d(inlink->time_base); + select->var_values[VAR_START_T] = TS2DT(frame->pts, inlink->time_base); select->var_values[VAR_N ] = inlink->frame_count_out; select->var_values[VAR_PTS] = TS2D(frame->pts); - select->var_values[VAR_T ] = TS2D(frame->pts) * av_q2d(inlink->time_base); + select->var_values[VAR_T ] = TS2DT(frame->pts, inlink->time_base); select->var_values[VAR_POS] = frame->pkt_pos == -1 ? NAN : frame->pkt_pos; select->var_values[VAR_KEY] = frame->key_frame; select->var_values[VAR_CONCATDEC_SELECT] = get_concatdec_select(frame, av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q));