From patchwork Wed Feb 15 20:07:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 2567 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2138200vsb; Wed, 15 Feb 2017 12:16:11 -0800 (PST) X-Received: by 10.28.228.213 with SMTP id b204mr9825063wmh.59.1487189771619; Wed, 15 Feb 2017 12:16:11 -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 t82si830836wmg.0.2017.02.15.12.16.10; Wed, 15 Feb 2017 12:16:11 -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=@google.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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2838C689A6E; Wed, 15 Feb 2017 22:16:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 647F06899D5 for ; Wed, 15 Feb 2017 22:15:55 +0200 (EET) Received: by mail-pg0-f48.google.com with SMTP id t188so463987pgt.2 for ; Wed, 15 Feb 2017 12:16:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3AhVRzJ7UelI11P/YBxjk5OPaudu24W/0IRxc4Dpi58=; b=dBiAc2/uXp/am6KPgpEoHue12KW9b9C7+SISo9/uG2FrO+aAtDXCRLP2L/ixkLm0XK yHnrwg3f+NesFd1tE6xEda3yVt/7yiHqcW6qW4twOpc8Ed8lkrN150Xb79hWmupE+0Aj 6+0HXGxkJ5XILJ563uYQWs4Bp25xoGbtqKqdKziSjrrevXkuM6gYVlXEbMLpn7CgMZvE J3GhD3RtJQ1inhcxjCH/j3ruJDcCE9U42b64h406pG58gbIxEGrRzhpfX9vjIysfkMPK SiZ7hS70j2HDuzdMhAlvB2XTWKR7AGDi7QHDuSvRHBiQB/D/413Br8aNCdHRnpItyTvY sdhg== 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; bh=3AhVRzJ7UelI11P/YBxjk5OPaudu24W/0IRxc4Dpi58=; b=kgJQkQZwSh1SuuWCLntXy9cvgNcOFL6ikyxIJQG6EKtt6azWkAqZLF7Hh6+OOJQsuO swaz9+sQl9Clhp1AdevwwTQa2cWJQ8TU4CpW8b2KNDaT41KfgFTwayO9wuU2ArrkQXHl euL6r1Q66cGc1EMejfvFb30S/bxf/iDNeYQx+teJJrWlrBwV4jkFgdN8PbmrEL39CLZe DxjJ6n9lOfBQ0AbxoO7mdndOwdJDwA/k5UrKXgJmWtFRplgm3PytsfUzwYyjeX+GN/Y/ ZfcpCy6vagsIWS5QMx6sXBM9BtYu3NSXgKMUbeqfdzFF2lR9Nqp+fPc5gyb2u3xxbSaL +4zw== X-Gm-Message-State: AMke39mGcfqvHUsOBZFxZH1IAF6VuZ/DigUgbayc5mPql9u5bPtTeQEoG2hyfeMMciYmZu1d X-Received: by 10.99.145.68 with SMTP id l65mr40940544pge.12.1487189310417; Wed, 15 Feb 2017 12:08:30 -0800 (PST) Received: from isasi.mtv.corp.google.com ([172.27.82.89]) by smtp.gmail.com with ESMTPSA id y187sm9018462pfy.123.2017.02.15.12.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Feb 2017 12:08:28 -0800 (PST) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Feb 2017 12:07:55 -0800 Message-Id: <20170215200755.24048-1-isasi@google.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog Subject: [FFmpeg-devel] [PATCH] lavf/mov.c: Correct keyframe search in edit list to return the very first keyframe/frame with matching timestamp. Fixes ticket#5904 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: Sasi Inguva MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Sasi Inguva --- libavformat/mov.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index b5181775e7..2a7cbfe142 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2847,11 +2847,23 @@ static int64_t find_prev_closest_index(AVStream *st, AVIndexEntry *e_keep = st->index_entries; int nb_keep = st->nb_index_entries; int64_t found = -1; + int64_t i = 0; st->index_entries = e_old; st->nb_index_entries = nb_old; found = av_index_search_timestamp(st, timestamp, flag | AVSEEK_FLAG_BACKWARD); + // Keep going backwards in the index entries until the timestamp is the same. + if (found >= 0) { + for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp; + i--) { + if ((flag & AVSEEK_FLAG_ANY) || + (e_old[i - 1].flags & AVINDEX_KEYFRAME)) { + found = i - 1; + } + } + } + /* restore AVStream state*/ st->index_entries = e_keep; st->nb_index_entries = nb_keep;