From patchwork Tue May 17 20:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 35810 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:906:4548:b0:6fe:2728:7bda with SMTP id s8csp1329834ejq; Tue, 17 May 2022 13:41:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygJk9Zp2M7FkN2J4CnUWTxWgRKRi5KiezNpbXOpnhIJatypEMR3nTwjaI6sIfN3rhmnoTU X-Received: by 2002:a05:6402:34cd:b0:428:1043:6231 with SMTP id w13-20020a05640234cd00b0042810436231mr20898526edc.274.1652820061983; Tue, 17 May 2022 13:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652820061; cv=none; d=google.com; s=arc-20160816; b=zqrkkKEYU3qEztZBs9AKYOjKNV7cPdr7qGjPzfVoRn4de2y+1Vb9qIzvlWbJm+DEk/ JC/jiXpt1a8HJgxCvfqQM58yNti7nFs7jXsQU+uOJxr2LMyFJ83KOWsLN712H8yHSMYy wf77X4q/aOT5kq3S0X/no+tj3RXInPWHROHvKXehVKIkd9nIF2wWLQZC7t3Q8OK+RJki nOXw/ILoVz2/C8RqwL23BRItvJVmd8uEfdhvD5oFlPx8pcyY5v4jCbobPAYk6B6Vi74U 1uOo6SjetAhvTG9CCe22TA3r1ay7+aU+DZucZ7w2jefWsce8LobrUGYJU11M7N5j22K9 akCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=+AIdx+2rWPS73nZX2yqF+60WeS7KeMfvFLELBf9enMs=; b=Lxohud/vkXgzX7fTBkIx42usTDGFTx49gA7Vn4dHQhy58RfSLFOVREWg6+4nD/DP8M xm35AT1GlrU+78lb/M8e+Iw3oLS92TNIRr56fRSrPMiUKxjNosIQZl9OyoeFCkH5Gv8F PMRVRWHoxc5qQPOReXFCvCJ4W19mMm9AQ+x31x7bp3kQULwFnMAsFW2QPw/8blsjQXFl N91+Go0XjohnEyjVlucXQkABjHtAwO6tP11JolcNng08HE9E2kjcswi6u2b86mrdtwPP HBZfWi2ikThCq2uBJzUyHyL/jyBSS7UII0ePVJL2s/SGsDEJ9SZDRcPVFG8ebhU8KIje WpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YpV8WCQe; 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 qh7-20020a170906eca700b006e66edfcccesi196926ejb.756.2022.05.17.13.40.38; Tue, 17 May 2022 13:41:01 -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=20210112 header.b=YpV8WCQe; 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 6D16868B406; Tue, 17 May 2022 23:40:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CBF468B314 for ; Tue, 17 May 2022 23:40:10 +0300 (EEST) Received: by mail-ed1-f50.google.com with SMTP id i40so410243eda.7 for ; Tue, 17 May 2022 13:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=0Dp4bm2HLBJN3WmskLtPl6qo82qPG4Avp4zF+hewMrI=; b=YpV8WCQegiz4gRC78TjPCQ9TmvLHBzi8e0esl05+6QbcL2DG+6b4kwSO9LQmJLRv6f CY5K5HWl99ieHGvZ0HGqxKPX+bYtmKZC6js4x4dp4rmTVeLipHs0T0gdyBYUVldlnomv zD2FkJxLZF2Y+742TxHWEZ4/1RwwNf2wdMmbdhHO1TBDZy5KCcga8+2mfxNBq6mrkwIX ZOe2hLckpxpPyV9ey8OhOd3isDhOLVKIttrya/brTQqUsb9C3D5cct8xH5uk0Ix4ZSEz BXPZCWn3PdY1mI8ttfytfRVH8o4Xh/l1K1pSBQLLRLAZLWL7LYiRzwC6n6BNVqhVKGPg +x4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=0Dp4bm2HLBJN3WmskLtPl6qo82qPG4Avp4zF+hewMrI=; b=kQHnfLyxZB5+yMsMCaKz32S5gLgXDqVEXeBU2+SuBXKzCzUO13ckYqA/RzwFWbDq6N 29c9n2hNsc5LpD8vMARZyFSqVl8gQbcf8hpz1iqEqF78TuAfbPvXv5awAy41CmOLcBoR N+mJXz8qoWud4wkzSXcJaVOAUS7yehgywLO1F7Y/6lCE7RqKTnR9hWombH98zno0fxUV XEwahkL8eVw5ujt1JxRLrnc6pm+i83Q4PJjzlB+97udqzmxB1NUvTGI2Yc5yFAUrstCZ 8lCDzs/cd+qKP6G7gDPucByQjjiKIIANRl1UOOXgRRnzmG4NCmaeF/fVHkBTHh9SzLV/ V6Vw== X-Gm-Message-State: AOAM53193VUKJYXenRMMZ2OmRUpmO3K89y86fmVyaLI/myoIXV0h9pKl NySexBB2TcBFaapD3DH3cBO+Z3gDQSk= X-Received: by 2002:a05:6402:3695:b0:427:b16e:e1b4 with SMTP id ej21-20020a056402369500b00427b16ee1b4mr21375944edb.117.1652820009376; Tue, 17 May 2022 13:40:09 -0700 (PDT) Received: from localhost.localdomain ([149.12.10.163]) by smtp.gmail.com with ESMTPSA id bt1-20020a0564020a4100b0042a9d52d811sm147119edb.75.2022.05.17.13.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 13:40:07 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 May 2022 21:39:56 +0100 Message-Id: <20220517203956.866831-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] mov: Compare frag times in correct time base when seeking a stream without a corresponding sidx 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lnt3P8WSAT29 Some muxers, such as GPAC, create files with only one sidx, but two streams muxed into the same fragments pointed to by this sidx. Prevously, in such a case, when we seeked in such files, we fell back to, for example, using the sidx associated with the video stream, to seek the audio stream, leaving the seekhead in the wrong place. We can still do this, but we need to take care to compare timestamps in the same time base. Signed-off-by: Derek Buitenhuis --- libavformat/mov.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index d7be593a86..fe3b2b15ab 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1270,12 +1270,12 @@ static int64_t get_stream_info_time(MOVFragmentStreamInfo * frag_stream_info) return frag_stream_info->tfdt_dts; } -static int64_t get_frag_time(MOVFragmentIndex *frag_index, - int index, int track_id) +static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st, + MOVFragmentIndex *frag_index, int index, int track_id) { MOVFragmentStreamInfo * frag_stream_info; int64_t timestamp; - int i; + int i, j; if (track_id >= 0) { frag_stream_info = get_frag_stream_info(frag_index, index, track_id); @@ -1287,15 +1287,23 @@ static int64_t get_frag_time(MOVFragmentIndex *frag_index, } for (i = 0; i < frag_index->item[index].nb_stream_info; i++) { + AVStream *frag_stream = NULL; frag_stream_info = &frag_index->item[index].stream_info[i]; + for (j = 0; j < s->nb_streams; j++) + if (s->streams[j]->id == frag_stream_info->id) + frag_stream = s->streams[j]; timestamp = get_stream_info_time(frag_stream_info); - if (timestamp != AV_NOPTS_VALUE) - return timestamp; + if (timestamp != AV_NOPTS_VALUE) { + if (frag_stream) + return av_rescale_q(timestamp, frag_stream->time_base, dst_st->time_base); + else + return timestamp; + } } return AV_NOPTS_VALUE; } -static int search_frag_timestamp(MOVFragmentIndex *frag_index, +static int search_frag_timestamp(AVFormatContext *s, MOVFragmentIndex *frag_index, AVStream *st, int64_t timestamp) { int a, b, m, m0; @@ -1317,7 +1325,7 @@ static int search_frag_timestamp(MOVFragmentIndex *frag_index, m0 = m = (a + b) >> 1; while (m < b && - (frag_time = get_frag_time(frag_index, m, id)) == AV_NOPTS_VALUE) + (frag_time = get_frag_time(s, st, frag_index, m, id)) == AV_NOPTS_VALUE) m++; if (m < b && frag_time <= timestamp) @@ -8782,7 +8790,7 @@ static int mov_seek_fragment(AVFormatContext *s, AVStream *st, int64_t timestamp if (!mov->frag_index.complete) return 0; - index = search_frag_timestamp(&mov->frag_index, st, timestamp); + index = search_frag_timestamp(s, &mov->frag_index, st, timestamp); if (index < 0) index = 0; if (!mov->frag_index.item[index].headers_read)