From patchwork Tue Sep 12 01:25:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Foucu X-Patchwork-Id: 5100 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp3726294jaa; Mon, 11 Sep 2017 18:25:43 -0700 (PDT) X-Received: by 10.28.31.140 with SMTP id f134mr3318068wmf.81.1505179543107; Mon, 11 Sep 2017 18:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505179543; cv=none; d=google.com; s=arc-20160816; b=j9VbhaT7skvm1odTuk7RiRUv3mah/ef8kp9mnqogKj+xeo3B5+Z86s1mioHRAW2j78 XM7HChTJ/dQhnAjiouba4J7839gybT2TCqiBwba9UOfsmoI7BHmZF6UU4PzBn8ggQCmL IXeuZk3MCmVdBHdkQ2TDdsRTe1g3A+pJzmwmL9fAzljQ8hDOmKQbD8WMN00qQ0Y59h5b hBzMXCUHaiy0X9eldazTeyeQ3Opm6ZtAnddxwD61qjdXWE4a85KyuPDnGQZtebgNPv3a icyHI3Rhry8OicbqP+957Sm+jmxe70CUNC5mPLk2h0J5ynWzMY2wS8pfLzUcqJ7gGk8r nuvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=efQhgWZvYHzuw/zwLJfKoEoc73ogURDoOsYl0CTxTXQ=; b=TI9SjEFQ6lT/YsYFyF9kQkQXJ3GxgsrMn61wvV931n/eYQEW3T9hN7eb9u7699JX2e ZTeY02G/jw0PWDtDP1srf5vfXGl3f0wWtF1WzjtXQNWEfpexUuKPyHE2NDkbZqzNITrz 9ocyIw9HuhKbMA8nVeYzvFQBsO0OukBp/YpBiyhYi6NOr9gcOgpt3m7Wy+CZnwAHU/jO BKNbEf3UVl+MS6b5u8pRdf1xm9OUfFhEjs74LM1eAYbBUqEos0u62oifnw0t3LGQHt3j cnLIxmbhzh+c4HXxU8ORz1ZPVNVZGYmb5wZgxI6nx7KmofatEVhmZfL8cclvoQj8TGW9 S9SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Tux8Eq5T; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 36si4002632wrk.246.2017.09.11.18.25.42; Mon, 11 Sep 2017 18:25:43 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Tux8Eq5T; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 550E9689C81; Tue, 12 Sep 2017 04:25:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f45.google.com (mail-pg0-f45.google.com [74.125.83.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 118586897A3 for ; Tue, 12 Sep 2017 04:25:26 +0300 (EEST) Received: by mail-pg0-f45.google.com with SMTP id v66so18450192pgb.5 for ; Mon, 11 Sep 2017 18:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5o5L9Vb08LsPpVgdICJdzzCfxZ00KQ8CDKcaAtDTDdY=; b=Tux8Eq5TP3fbZh7nzxpm8x6M6QFh93CdYGb/RhdUdQIItV8mL5j0pcdSHZrOsxZisW fxMLkRXmUNA2nZTWZFqeaJtjh7K58rgXoVJm/Vd6VWsPkjMsK1bkGZsZFp7Htux1dGWh eeW7MCdMIui13TFOFOHNROnIKQA1dg3npQbC5QTpCuyEj1wMLi/zi99Sog4WZ+O08h6M f4lu/9TIY4ijqU6htdTZqaTke8qlqVlTUGW4PCQj2CUdhLliEkRm9YOHOYSRRbjuT0q/ Oxpo+bN4u9Uhb4WNtzlkkdeMJstFmRjUkprq18BEX5Np4QdLa3wFcpQwBXLCJ9zttLbm qnIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5o5L9Vb08LsPpVgdICJdzzCfxZ00KQ8CDKcaAtDTDdY=; b=eJVvnB4+4zxl42bOs3alG0Pqo6B/tZev9dNqHwLyst2UU5awpWPC8DGGBpqovjzuE+ VppNAwYiD3QXx/enZPUAQSILnEcGim72aXzhCvC+nNpFYaLfrrdAJlRVJL+mLz9WEKVy UvOl2lLkaRwAid2GHTfCSd6DYjRRcjB9l2iJhsTbqTGUi/cmar7Y8RPGrRBlFIynOlhk /JIrw7ng1wMUYdVweEonRy/fEc/J0c7rh3kJaZ40HPc1L8y/jolcsb4htjkF5hIFwCHQ 0o3A0zTEJ+nBgpQCpuU22+JmjQVX5C2YWec2BVNsNfnAPjBd5ytTNyuVxyASSbNV8bgN IZ3w== X-Gm-Message-State: AHPjjUhqqDykac7UPX7WicbBZhxRRwN96T8MsqsqzoaP2wCaFF6XB70v OLaVtHMpg7Ivr/wZgVU= X-Google-Smtp-Source: ADKCNb4xqbe3bUPuHERi8gIXfIu6QT7Urk+Ky2dF4ro+jCJEaNwhKPG44p5I6KPrfAl1OHBsPaSuiQ== X-Received: by 10.99.121.194 with SMTP id u185mr13148363pgc.21.1505179529552; Mon, 11 Sep 2017 18:25:29 -0700 (PDT) Received: from tfoucu.mtv.corp.google.com ([172.27.196.64]) by smtp.gmail.com with ESMTPSA id n18sm18684295pgd.69.2017.09.11.18.25.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Sep 2017 18:25:28 -0700 (PDT) From: Thierry Foucu To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Sep 2017 18:25:08 -0700 Message-Id: <20170912012508.139701-1-tfoucu@gmail.com> X-Mailer: git-send-email 2.14.1.581.gf28d330327-goog In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed. 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 Cc: Thierry Foucu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fix ticket #2674 Tested with examples from ticket 2674. --- Update the Patch with the correct number of duplicate showing. For exmaple, in case we up-sample one second video at 24fps by 2, we should be getting 24 duplicate frames. ffmpeg -loglevel verbose -i 24fps.avi -vf fps=48 -f null - ffmpeg version N-87234-g9a32769f5e Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configuration: libavutil 55. 74.100 / 55. 74.100 libavcodec 57.105.100 / 57.105.100 libavformat 57. 81.100 / 57. 81.100 libavdevice 57. 8.100 / 57. 8.100 libavfilter 6.103.100 / 6.103.100 libswscale 4. 7.103 / 4. 7.103 libswresample 2. 8.100 / 2. 8.100 Input #0, avi, from '24fps.avi': Metadata: encoder : Lavf57.81.100 Duration: 00:00:01.00, start: 0.000000, bitrate: 368 kb/s Stream #0:0: Video: mpeg4 (Simple Profile), 1 reference frame (FMP4 / 0x34504D46), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 24 fps, 24 tbr, 24 tbn, 24 tbc Stream mapping: Stream #0:0 -> #0:0 (mpeg4 (native) -> wrapped_avframe (native)) Press [q] to stop, [?] for help [Parsed_fps_0 @ 0x25ea6a0] fps=48/1 [graph 0 input from stream 0:0 @ 0x275cc00] w:320 h:240 pixfmt:yuv420p tb:1/24 fr:24/1 sar:1/1 sws_param:flags=2 Output #0, null, to 'pipe:': Metadata: encoder : Lavf57.81.100 Stream #0:0: Video: wrapped_avframe, 1 reference frame, yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 48 fps, 48 tbn, 48 tbc Metadata: encoder : Lavc57.105.100 wrapped_avframe No more output streams to write to, finishing. frame= 48 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=99.3x video:25kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown Input file #0 (24fps.avi): Input stream #0:0 (video): 24 packets read (39693 bytes); 24 frames decoded; Total: 24 packets (39693 bytes) demuxed Output file #0 (pipe:): Output stream #0:0 (video): 48 frames encoded; 48 packets muxed (25344 bytes); Total: 48 packets (25344 bytes) muxed [Parsed_fps_0 @ 0x25ea6a0] 24 frames in, 48 frames out; 0 frames dropped, 24 frames duplicated. libavfilter/vf_fps.c | 44 +++++++++++++++++++++++++++++++++++++++----- tests/ref/fate/filter-fps | 6 ++++++ tests/ref/fate/filter-fps-r | 4 ++++ tests/ref/fate/m4v-cfr | 1 - 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c index 20ccd797d1..09fc66a73c 100644 --- a/libavfilter/vf_fps.c +++ b/libavfilter/vf_fps.c @@ -34,6 +34,8 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#define FF_INTERNAL_FIELDS 1 +#include "framequeue.h" #include "avfilter.h" #include "internal.h" #include "video.h" @@ -137,13 +139,45 @@ static int request_frame(AVFilterLink *outlink) AVFrame *buf; av_fifo_generic_read(s->fifo, &buf, sizeof(buf), NULL); - buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base, - outlink->time_base) + s->frames_out; + if (av_fifo_size(s->fifo)) { + buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base, + outlink->time_base) + s->frames_out; - if ((ret = ff_filter_frame(outlink, buf)) < 0) - return ret; + if ((ret = ff_filter_frame(outlink, buf)) < 0) + return ret; - s->frames_out++; + s->frames_out++; + } else { + /* This is the last frame, we may have to duplicate it to match + * the last frame duration */ + int j; + int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts - s->first_pts, + ctx->inputs[0]->time_base, + outlink->time_base, s->rounding) - s->frames_out ; + /* if the delta is equal to 1, it means we just need to output + * the last frame. Greater than 1 means we will need duplicate + * delta-1 frames */ + if (delta > 0 ) { + for (j = 0; j < delta; j++) { + AVFrame *dup = av_frame_clone(buf); + + av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n"); + dup->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base, + outlink->time_base) + s->frames_out; + + if ((ret = ff_filter_frame(outlink, dup)) < 0) + return ret; + + s->frames_out++; + if (j > 0) s->dup++; + } + } else { + /* for delta less or equal to 0, we should drop the frame, + * otherwise, we will have one or more extra frames */ + av_frame_free(&buf); + s->drop++; + } + } } return 0; } diff --git a/tests/ref/fate/filter-fps b/tests/ref/fate/filter-fps index 55712cfb1c..242fb04e85 100644 --- a/tests/ref/fate/filter-fps +++ b/tests/ref/fate/filter-fps @@ -85,3 +85,9 @@ 0, 79, 79, 1, 30576, 0xa2fcd06f 0, 80, 80, 1, 30576, 0xa2fcd06f 0, 81, 81, 1, 30576, 0xd4150aad +0, 82, 82, 1, 30576, 0xd4150aad +0, 83, 83, 1, 30576, 0xd4150aad +0, 84, 84, 1, 30576, 0xd4150aad +0, 85, 85, 1, 30576, 0xd4150aad +0, 86, 86, 1, 30576, 0xd4150aad +0, 87, 87, 1, 30576, 0xd4150aad diff --git a/tests/ref/fate/filter-fps-r b/tests/ref/fate/filter-fps-r index 826b1ed6c6..c1bc7d1547 100644 --- a/tests/ref/fate/filter-fps-r +++ b/tests/ref/fate/filter-fps-r @@ -72,3 +72,7 @@ 0, 79, 79, 1, 30576, 0xa2fcd06f 0, 80, 80, 1, 30576, 0xa2fcd06f 0, 82, 82, 1, 30576, 0xd4150aad +0, 83, 83, 1, 30576, 0xd4150aad +0, 84, 84, 1, 30576, 0xd4150aad +0, 85, 85, 1, 30576, 0xd4150aad +0, 86, 86, 1, 30576, 0xd4150aad diff --git a/tests/ref/fate/m4v-cfr b/tests/ref/fate/m4v-cfr index 4eee84d01b..e2d02032fe 100644 --- a/tests/ref/fate/m4v-cfr +++ b/tests/ref/fate/m4v-cfr @@ -44,4 +44,3 @@ 0, 38, 38, 1, 115200, 0xf30825d5 0, 39, 39, 1, 115200, 0xe3c944a1 0, 40, 40, 1, 115200, 0x8fec4420 -0, 41, 41, 1, 115200, 0x9381fdab