From patchwork Wed Sep 13 01:45:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Foucu X-Patchwork-Id: 5128 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp390282jaa; Tue, 12 Sep 2017 18:46:12 -0700 (PDT) X-Received: by 10.28.74.89 with SMTP id x86mr964562wma.57.1505267172322; Tue, 12 Sep 2017 18:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505267172; cv=none; d=google.com; s=arc-20160816; b=Y13ywYgc6VPtCzr1PqBSaPuwdWEMLF93L9jrrxxQ/MmrqS9bn4/p5ypHZfL1M0DtBy C8nX8HOCCllkct66TNu5/nZfI2kjxAwFgnxmEPz/aXcXYsfy+xxfsvMG4v5rbnJFCvcD a9OH5mzRGHIvCG/5OIDB31rhitlUOAbcx6onPqEx8QhdwimbtJVH/EQN8sSwEGI1WQ/f 1apRGpr9hEt0nLxEuMi92utgSZFXEEhUaPTmeYDdlvKhbbkrBpscGcPOyck/kzAY3aWe 5l41vxBaLqGIGdiGFZWiFBep51c51D9UAoumsoqkdZUWxbdS7TY4HwftHJjgN/BNvgjp XB6A== 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=ZcZ55UYL2khdiuxSXT/QS9gZbIYv9FIYQVI2l57ZL5c=; b=ihqLU4fN73vLC0lx1RRtt3tOgBkF5tC0GpBMtRXwuYfwLraV5aLQD6H3P6QhmydfJU X6yPmk4w9+9mmbJhCqNwPmfcxvPQ8qK+Nr5ZDFZ00y081WGLN+SlTmSRR3VSfkhREWh2 hDwRh/P6nFCF+OXgtOtjbL7htAshamVGulogrOnOV2Jf1LssKCvkkStSOTXFSRSBfx0L K9US+QQ9XCsCjECuzdc1O0Qs6tVPkFPK2VKuauti4MXdj3Kv3IrY8E8oky8bF5lMQ0lr TSKbhp3h0//XPQ97qJ7xZYrB+0QxDO/oQfUsFr7uS3LuwHcZFFpIEb7J0ZA6a53bJfe0 jMtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pHTT9s6/; 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 r184si97338wmg.188.2017.09.12.18.46.10; Tue, 12 Sep 2017 18:46:12 -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=pHTT9s6/; 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 BD4C9689E0E; Wed, 13 Sep 2017 04:46:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33F9B689DE0 for ; Wed, 13 Sep 2017 04:45:57 +0300 (EEST) Received: by mail-pf0-f172.google.com with SMTP id e199so21286290pfh.3 for ; Tue, 12 Sep 2017 18:46:03 -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=BgZG8gxeXkgI5lTuiL0Xkmj384FAp3/g5+3T5kifqCM=; b=pHTT9s6/DbEsGPOgGZhtvkFDkj9icPl/pjDeyCx90Z4I9mC8vIpg7FjoCjVkg0x/lW aDBA4deE3hkeqgttnz2JVNUyUfyPbROUOhtzoN/mmvRpphjD2n1KM1DnmlcuEegvPxAr inNpsNtJmK/re0SO0pxdKvNHicu+y3oTJqmNGFO+nmg7i0+fe5WmJmovOd0rd5SOOtHZ ovsBdASbnZ8Y9Kg0m+4g7l8nEtstY210F680uoGiL8Zg83/arFOtWeG42R/nbm7b0FwN EqgmXg2PZIzeW57/54ZW/h5SgQMnAA00N3y7eXfdCig6Tn21KalPqL/mLmv17aHIEhPg 8ngQ== 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=BgZG8gxeXkgI5lTuiL0Xkmj384FAp3/g5+3T5kifqCM=; b=ufvO/O+1YPzOrJr3yrvbqiN80ozbZR9/rJoTSIH/2S3CPJk98/BeoN5/Yyp25vwMzu 9wnUCqZAEWJPmq0nM/1QOBqCrbtDq+XHriPqMQpBRbRmd4/RjJ7WApHiIScluJDLy4EC Il6RwcBYYdya05RER4dOwg+AOMEoxOLQ8ee2J6rXewbGi3ymFt0iiAmpvEulC/L7U/x2 RmAzvcnH5vvcy3eTUbvYVVRLF6ywveq3zrpFTYcquIZ9YT7iiGQ9HCE2cF6fEORE9eQH kheprPtYEwXgtfadvTpnv+JIafMXqSInI8icP7Q+WyIC1loScVv+BmucrU26iSZduaRT x8eA== X-Gm-Message-State: AHPjjUjAANJlBWUvxcw+SGXK+LzZVtRbUuAWEbCJLjMG8jFxr0e2aqkY Dwx7JtMtob71qLqG2PY= X-Google-Smtp-Source: ADKCNb6vxmLUxBFkqAL+ILm5jH6orHvWeJka2ORuXppB4uAtoT7AtivKXOUiKCV2Ww0P1Wkg67QOmA== X-Received: by 10.99.132.199 with SMTP id k190mr16749037pgd.25.1505267161069; Tue, 12 Sep 2017 18:46:01 -0700 (PDT) Received: from tfoucu.mtv.corp.google.com ([172.27.196.64]) by smtp.gmail.com with ESMTPSA id w9sm19879388pfg.129.2017.09.12.18.46.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Sep 2017 18:46:00 -0700 (PDT) From: Thierry Foucu To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Sep 2017 18:45:57 -0700 Message-Id: <20170913014557.19839-1-tfoucu@gmail.com> X-Mailer: git-send-email 2.14.1.581.gf28d330327-goog In-Reply-To: <20170913004600.GA7094@nb4> References: <20170913004600.GA7094@nb4> 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. --- Sorry Michael, I forgot to configure using --enable-gpl. Please find new patch. libavfilter/vf_fps.c | 44 +++++++++++++++++++++++++++++++++++----- tests/ref/fate/filter-fps | 6 ++++++ tests/ref/fate/filter-fps-r | 4 ++++ tests/ref/fate/filter-mpdecimate | 1 - tests/ref/fate/m4v-cfr | 1 - 5 files changed, 49 insertions(+), 7 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/filter-mpdecimate b/tests/ref/fate/filter-mpdecimate index d438dacc2e..9c1dc36562 100644 --- a/tests/ref/fate/filter-mpdecimate +++ b/tests/ref/fate/filter-mpdecimate @@ -22,4 +22,3 @@ 0, 24, 24, 1, 115200, 0x056d40ca 0, 26, 26, 1, 115200, 0xa4374737 0, 27, 27, 1, 115200, 0x3eaa3ae8 -0, 29, 29, 1, 115200, 0x7551e9ee 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