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 77F1442FF1 for ; Tue, 17 May 2022 20:40:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 32B3C68B403; Tue, 17 May 2022 23:40:17 +0300 (EEST) 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-Google-Smtp-Source: ABdhPJwM8X3sFxzUMvfkBKz1aBV3w4B7gRbLx9LyMUSxEnNulQR7VygXkhsxPsSg5FSqE/iTMQQynQ== 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 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: 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) -- 2.36.1 _______________________________________________ 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".