From patchwork Sat Sep 23 11:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: llyyr X-Patchwork-Id: 43878 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2a18:b0:15d:8365:d4b8 with SMTP id e24csp157675pzh; Sat, 23 Sep 2023 04:11:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoAy/S3bYVo8HqUsVutiyRQ3NmcbGuSzwX12r3CxL3fTs2TwsSwbQtmFy+pgNOuVPHDS1i X-Received: by 2002:a05:6512:32a2:b0:503:2a53:7480 with SMTP id q2-20020a05651232a200b005032a537480mr1597820lfe.49.1695467483308; Sat, 23 Sep 2023 04:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695467483; cv=none; d=google.com; s=arc-20160816; b=VO/lqkjfxlHI4PRX+344pLOi14L8fpZ/9B8cQ7mF2tZUk37Jho4qM/cTjCwiJ3EUT4 inhC1m/8eXcxAnygNJiAVrTDjhANgrW0OlfL8hasbVXhZUqESgXc5l305w4pD4GVtKtU ei0sGMtxkeTCJUe1yBnCYrT0sXByJcm4y+fR3MgctA6mT8+//j50IAtYBVGCov1q1oTK Fl0BpCor+AiznqbyoLCt7VFod2v7Oj3OGJhsiOigg6GyXGP5X80wV9VDlLfm6jgACUEA UY8NxKIGL50VH45t+GgU37cGXlyecGXegI1xo1p2XHksDOfQhKOcCbofMQ57NBw3Y14y 8RuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=/l5CyE1yIxbBRAPPV/lvTLurBQkZ9OYtdA8VfdhBiXk=; fh=9+5V1imiycJiT5azxiNRH94nOdHnEBV1p/NpmNUA0dg=; b=TZzV3CUkN/hionMwhpIBTBvptSy9tYS0yBi8BAabnsk3BV8qqDs2GBhjZrNGxcI1Ob j5e+jBwzv06c7vDtJV07MsH84f4B54p7gaHFHenhwXHklqxlMtP7ss8EJdRhta0AYISR oo0tHbhITQwkpcck6WCE0l0qc4IwxWcsRorBNxGeIPKPdWC3TzwU8AlG+gxM/7XHNVhY EUrg1zOTykgEx4ezFowXrpmRrnnIx8Uw0v3x3Yy31J94LGnPjDjvIr/nVa5mGk0hcgjs sp3EkPqAnX5l+YXAOx3+a/OMlf6LvEP2kj0igM56lMFmAHxwfix7RpFWvt0qqcui0nKZ MZqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="L/kl9/aL"; 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=QUARANTINE 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 x23-20020aa7d6d7000000b00530e8a1bc9fsi4784099edr.208.2023.09.23.04.11.22; Sat, 23 Sep 2023 04:11:23 -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=20230601 header.b="L/kl9/aL"; 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=QUARANTINE 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 DC8F268C8B6; Sat, 23 Sep 2023 14:11:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49F8E68C8B6 for ; Sat, 23 Sep 2023 14:11:13 +0300 (EEST) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-692779f583fso2212215b3a.0 for ; Sat, 23 Sep 2023 04:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695467471; x=1696072271; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OB0tddfqdgPXsOvFSD+fT1k0A1ivTBPPsOQCtXcBSRA=; b=L/kl9/aLdBW0W+cXqxexBIgZ/fbeH0HKGltww39+U7+Pd0GDUVey2cLS3vxn7abEHj QXTCTIv/3vLTClJqwpq53uaWe4gXU3oLx6SHkN0DEErJjpg2i9d6EpkdhgTS8bzZVfyR ZO427pBtaO2XC25e5nbKUG99/BTuNDTfPEfOeeVgNBw9XqldGA52RU7WfSL98jWoBFu7 /KDZe1lSGOiEmprq5wgthHVqSP1hZAROkrt2YHzc+4ulnbrjDjo4lFcLCSyjF4ZRUqJw /PA29h7G5O9daPOwk5InxEOFW+P4siKgT0YnNNXc0zx9XdHBnlej0BLRU3wIwPs3xVv/ DFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695467471; x=1696072271; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OB0tddfqdgPXsOvFSD+fT1k0A1ivTBPPsOQCtXcBSRA=; b=ZSeKy/xphNVKLq5gqzq+PsYxs+iSNWixlxw4cOkrGLlu3aqMMbOysJhhtQw0hIGTBz K2/LlbD5rYayGJsViZb8XokRPuYQS5+yyamP+DcTQrGFmXXzZwQ8Vcxc0BUyqtKRLBYv OLJqSrLQxiE8itRciQ0t3yqmPrFctRLUjR+Hff6K2pGDuwCeKBqfmO/GZFzfjGfgM6U3 NjlIGeBGFpMmWTDiwSGWuqNML0KCl4sMHU14O2fg0VU9oH62py8XlJNeSoxobqtzqXai mm3DW6bAIBtw24vt8mA7MU8GKpco+BVXLkFuET7jzTYLfJNyZH7CBFg2ZEdmNYAJPNUf arLA== X-Gm-Message-State: AOJu0Ywrm7nhCdDXgHl6uwalyGhRBdOnBXyN78vASAVehr/RtCvITcJx 7EYrhHfvBzNzYL0ity47vBQiRv3fCYI= X-Received: by 2002:a05:6a00:2d94:b0:68e:2478:d6c9 with SMTP id fb20-20020a056a002d9400b0068e2478d6c9mr1852948pfb.2.1695467470878; Sat, 23 Sep 2023 04:11:10 -0700 (PDT) Received: from localhost.localdomain ([103.194.71.93]) by smtp.gmail.com with ESMTPSA id e5-20020a62ee05000000b0069069ca9814sm4674791pfi.219.2023.09.23.04.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 04:11:10 -0700 (PDT) From: llyyr To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Sep 2023 16:40:35 +0530 Message-ID: <20230923111034.6320-2-llyyr.public@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: llyyr Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sS79pIar8Qmx ab77b878f1 attempted to fix the issue of broken packets being sent to the decoder by implementing logic that kept attempting to PTS-step backwards until it reached a valid point, however applying this heuristic meant that in files that had no valid points (such as HEVC videos shot on iPhones), we'd seek back to sample 0 on every seek attempt. This meant that files that were previously seekable, albeit with some skipped frames, were not seekable at all now. Relax this heuristic a bit by giving up on seeking to a valid point if we've tried a different sample and we still don't have a valid point to seek to. This may some frames to be skipped on seeking but it's better than not being able to seek at all in such files. Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files") --- libavformat/mov.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 1996e0028c..60a4d581d9 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -9108,7 +9108,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, { MOVStreamContext *sc = st->priv_data; FFStream *const sti = ffstream(st); - int sample, time_sample, ret; + int sample, time_sample, ret, next_ts, requested_sample; unsigned int i; // Here we consider timestamp to be PTS, hence try to offset it so that we @@ -9129,7 +9129,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break; - timestamp -= FFMAX(sc->min_sample_duration, 1); + + next_ts = timestamp - FFMAX(sc->min_sample_duration, 1); + requested_sample = av_index_search_timestamp(st, next_ts, flags); + + // If we can't seek to the next pts either and it's a different sample, + // give up trying to find a good pts to seek to, otherwise we'll end up + // seeking back to sample 0 on every seek. + if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample) + break; + + timestamp = next_ts; } mov_current_sample_set(sc, sample);