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: 48879 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp1182026pzb; Tue, 14 May 2024 12:59:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWKMMTV+nAn+pNYFOgb0vxg9E1CyChj+ELW8lhoHj5rtegNmAS/RggRKSOeWAYLWU2PuliB3eI08OEsAvHIDbVJvYxDiJyKNC9F6w== X-Google-Smtp-Source: AGHT+IF503nd0c+OX1t+XY6NROjuCFkRMdyY1qJFtTh+U6nw92+BLm97F39+SjNoEvoDq41/LMdX X-Received: by 2002:a17:907:986:b0:a59:cb29:3fa7 with SMTP id a640c23a62f3a-a5a2d54d0cemr1103167166b.1.1715716748397; Tue, 14 May 2024 12:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715716748; cv=none; d=google.com; s=arc-20160816; b=rY5hA8SR3BRQC61jVwXGPhE+bfjCbDszJclyYnIXqjTEZCfGV8bzU5UJUgqNYUi3IJ e4bAEACUgSA21IKwX5RkECQZTaOAeksC3YXhOPP9UNcx/XU6yI05+dW7nU/pxGDQhOd8 jckm+71MiA15wxYAEV1lTYjzXGtaYlGLjl6HYMpuLXFTG2pg+KspdTe6YXoEM1Dm7Ubk n1xoYM0XK+D2OSooxVZa0hLHwbGRvwgZEjpC5lbgfOPnNLCWwQVu1p0nUPHkTF5egl3M WGUEW0Oyb1sUZ/yVx05lwF5AMv7PMJMFmMYBhoIzizUsHn1YllSSo5RySwfI0W5xoPxe h1Sw== 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=soD4TH3U2AnVMudBZgcAD9j1gVaPF2SB0IxeGMwJdwCLHxVfkxS38FrCeHKnSBxhOx k+6PVBddMevAIhcMhIp/Ff2QsB7AFlpMGvbUUmmrgbRUngsmaxcPe0ztnfw8KAGfkONY exWcNhNZzYRehORjz9rMo8a0uJEoMmUFxVtnaEZGy2WaCluX6qT6PntLtJpppIUq9zWU pgCCisaztw5U67oTNqRChQxYXObHKBmxQzqcTMd6l9VXE7LzBFaDMe90Ey2FgjZsTIqj qMMlgun7JV02OXzt/r28yDEm+KuWjdAAIIyjNhiA2u8aVjabZFm2vbn5heR/nFPJ2rJJ Xs2A==; 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=CQh64Knq; 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 a640c23a62f3a-a5a17be66edsi621342066b.761.2024.05.14.12.59.07; Tue, 14 May 2024 12:59:08 -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=CQh64Knq; 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 E6D6B68D73D; Tue, 14 May 2024 22:59:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DD6A68D4FD for ; Tue, 14 May 2024 22:58:58 +0300 (EEST) Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2b346712919so4314984a91.2 for ; Tue, 14 May 2024 12:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715716736; x=1716321536; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=puV7KgiqYI44JhN8iQyMKGnnaRi+V44UhRIDnQRqEXU=; b=CQh64KnqTot9FU6lSzdi+CTVDdylCCJNXfGUR+Bu6eNlyiW11EECZ9UH688oXHOjha oIvR0DO8saKb7QeAwNxl2P+/gO6XEtguOhyamh24jjRf36Y2S92l7J1Wlho4SObI+372 nbgonmHuwcSMOzD+qX7Q9b5TssAMn8tIPNkqalQT0CCKkOTiq5GpG48yHcqUE+cdoDWh ekIqt2mxASyus8X6Ce4IwNVJ27VBnbS8sdY08HAwJ7yvF5GpM8cVaCpKNDVo5M1buNmL eHBnpxOwU87DHWO6wTTq3Br3Iig96nJvHXo2XUh4nWpKCQEX7GZ+Iit6m6c7ReEoMXke Wqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715716736; x=1716321536; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=puV7KgiqYI44JhN8iQyMKGnnaRi+V44UhRIDnQRqEXU=; b=Q2gwRiJhd7cSgX/LXZW8eQxkXGOl7p93cF05Anri0OOWayYsyGfmflbeQd510LPQ+u gcjRAGaQi1SqL2rkgpl/A54s3yAqr7FWTJ5g7lgQxlaj7sGSrnfSMbaaTtU/Kbwu1RZx PSrJeCk6HmC0ye8ym7HKoIb5c8d3UbvCR09smAZDFq2r92u+ws9cogo4mF4ztZW/5uHG Lq8T8YVTB3z1EysyidCpRr7JvIdR1k6YEs0sIf0/1Vcs7rWz7tOJN1IZYGrO30lCj+Zz eSFf59bixa95by3mlekU+oGb7IGxmgJab9G/PWWseeyIR2FXZV+Vg35HNtaVdxbEYgQL CBzg== X-Gm-Message-State: AOJu0YznE9fDCqOJLX7FH90Rje0gl6dp+BrU/PusO6XIrEZ335rTnOhE nZXzjmdmFdGoYDJg3n+jxteJlslNQpiSMolaqZZkSEKW3cLDlkrViVSKug== X-Received: by 2002:a17:90b:3902:b0:2a0:3dc3:8a8b with SMTP id 98e67ed59e1d1-2b6cd0e9730mr9402088a91.47.1715716736163; Tue, 14 May 2024 12:58:56 -0700 (PDT) Received: from localhost ([103.208.20.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b671165fbcsm11286517a91.17.2024.05.14.12.58.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 May 2024 12:58:55 -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: X3klAEzCXCSO 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);