From patchwork Sat Sep 23 10:56:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: llyyr X-Patchwork-Id: 48880 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp1183708pzb; Tue, 14 May 2024 13:02:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXYREgBWQJj8HqLd3kZKMnZ3V1D5yabfkq2yjblsWWmThyCVkhcActs5ngu0ghQdjopwBLaG76VBNsEV6PjSm8OIdp6IRUZ6I4ytA== X-Google-Smtp-Source: AGHT+IHAkkR2r328lbV4tfgwWa0Ud/ub1XRh9I7uIDRMtwr/BVYePXdjVRH3coJi/2UWE9DNthqY X-Received: by 2002:ac2:5970:0:b0:523:481e:9f32 with SMTP id 2adb3069b0e04-523481ea355mr3582074e87.69.1715716924639; Tue, 14 May 2024 13:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715716924; cv=none; d=google.com; s=arc-20160816; b=XDPodH3+xJoP7zg59Z7T0FfmW4wguaDRlJ9FMjWyg3Efyr7eHwH+xJ3Brz+Liqq5oj dnlPw0jyzIJJzwPuI5AiVUOuvq26Q8/kQkpMXQmXgg2wR92qhBnpyM9LPvEy4hFnCl+m MVDZc3+hDX3SqsprMsAJySfMLWGQEmpwll4QDth8qeXGVfN7ReksJSZVlJCm12O/MUAr 3ATsbGSyuN/zsfebTB/6jN6Wem79ORbjLfEuh328BhE0ft4aG/ngaHywDGN48ahQYl0Y A0c3ugBdU1Q2rIEE4GrcX79k3sxs2fFtDuJ402heXYRNAmlfshoRcu9IqDad9H+EB7X8 O8Dw== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:dkim-signature :delivered-to; bh=/NsR0GkBmYt19hcfP5vkWGrcNt97m2Kf2Sh49o+Hteo=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=lKM3i/YhofjFHeRiH9Clp4suIKsQf2rpIasDjBgXaYPox/CPnCKb28jIe4ER9vZdaD 5TTwEFWDR9imI1lOIZUVwuhh9d6nzS+LHstQ33evCKVMHLul0AId6iOit1FFmEWvgqEb W1pf16tN2KD9b9Y4YTuvVJOFUryREWMHofikXpVbCFwY/PDjRFW+5i9iPGxQ1oG6V2zC j5alkRvdTKLRAmH60a1zEGGW/O7dMtO+2XL//al9Zya0ZyvTPxhD1ydE77Kh7kaaXTcK b6ZHXM8/m/NQH0p5LfL2Oj3+IdGc/IEFo4wBXv+ImrGdFDUTbPEDZBKUekJ5g6JrWKU5 Liuw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="Y6lJ/cjj"; 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 2adb3069b0e04-521f38d4434si3856105e87.210.2024.05.14.13.02.04; Tue, 14 May 2024 13:02:04 -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="Y6lJ/cjj"; 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 6112868D741; Tue, 14 May 2024 23:01:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2E2C68D4DA for ; Tue, 14 May 2024 23:01:47 +0300 (EEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1ec92e355bfso57395565ad.3 for ; Tue, 14 May 2024 13:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715716905; x=1716321705; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=puV7KgiqYI44JhN8iQyMKGnnaRi+V44UhRIDnQRqEXU=; b=Y6lJ/cjjLepv80wcyVso9cuZPcC4ifGl1CBit+bhwM2wRL7y57Kk1LMVnYTlwjoVkx /fbjld/9pWLNWYjkxDfpzync0NpaqQfTiOYdNmmM5roD/e6KHz7tPSKBfJ1T+3ec1/Fi hTvUs/sl74vWdmh/OSh/WbLkiuycpTnFkuuMh7jD4IBBhY0RhA2Y4OldlW0sxOjvXuNx dMm+NUkwufQ3uxE1nz+x8WFfrqVz0KRTJxQp7rjgWle+0ErpxMKKQDHMfrY/+L0ZskUb NMutLjiZjLunPSAtLfk/cTUZ2IUxG8NJUmaWgJWkqW6b6NOHe5DvWtW3YL/Hjpj9bzCw wpZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715716905; x=1716321705; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=puV7KgiqYI44JhN8iQyMKGnnaRi+V44UhRIDnQRqEXU=; b=SrG+jVE05y/m7D/qKP3FMzDj7VwsalNBiT0KLIDbLaha2EVYDTansYQ3kD3HV+upDu JgKhycNgRre6n+zLaXe3uxIb3eLkpns6w5hz8zvJ4zhnKgt6XYPOwM27Wj+pxLFfYA7M 60pHPA1TO+SYgq+p+H3VsBGqKI3UD4fhbiDMS2b3zDzWwrh1fW1rZz8+uvB5o+j/2IgV P74/ZEnX+2BEnrkwpeE68v4cd2AZxBD0z3+rUA7t98VUMRNuAKO6c4Ed1qj5lKB0Ded5 WeYXgKWrCZsSFwYxpUlA9H49YiKXSPZmeaOp8L2AdVHsG36TXwT3tpoisVvG0sE1T/Fh kzHQ== X-Gm-Message-State: AOJu0YwU+ohtJD6oBrTEaKj6KmsGkwYtTngGmJjZvX2AT9RT+NO7HoYp m1Sy6oyfkjU16LFDNk96SFzwe0I3Bgw1bp60eNoJ8dZiyF5eEJMo/9pP0g== X-Received: by 2002:a17:902:d507:b0:1e7:e7ed:7787 with SMTP id d9443c01a7336-1ef43f522bdmr178661315ad.51.1715716905260; Tue, 14 May 2024 13:01:45 -0700 (PDT) Received: from localhost ([103.208.20.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c039c31sm104409195ad.213.2024.05.14.13.01.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 May 2024 13:01:44 -0700 (PDT) Message-Id: To: From: Date: Sat, 23 Sep 2023 16:26:20 +0530 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eFiUydgmpP6c 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") Fixes: #10585 --- libavformat/mov.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) base-commit: b0093ab8a3d34bf2fefd6665464cc343a9ef0d53 diff --git a/libavformat/mov.c b/libavformat/mov.c index b3fa748f27e8..6174a04c3169 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -10133,7 +10133,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 @@ -10154,7 +10154,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've reached a different sample trying to find a good pts to + // seek to, give up searching because 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);