From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 02B4247823 for ; Sat, 23 Sep 2023 11:11:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A84AF68C9C0; Sat, 23 Sep 2023 14:11:19 +0300 (EEST) 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-Google-Smtp-Source: AGHT+IH+so7m71QFe5Z8IyWjde96idROAGAAHhr9s5PtbObsJQpNEWSxnug/Ar4Pgd5EC0OiabGRow== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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); -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".