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 71D4D42F86 for ; Wed, 18 May 2022 03:38:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EFE1A68B477; Wed, 18 May 2022 06:38:43 +0300 (EEST) Received: from out203-205-251-72.mail.qq.com (out203-205-251-72.mail.qq.com [203.205.251.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5F3D68A2F6 for ; Wed, 18 May 2022 06:38:36 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1652845111; bh=YT/kOqG05YeOLWTbW3GIlP5UZj4w7OQlGofONnk27us=; h=From:Subject:Date:References:To:In-Reply-To; b=TRNfdsSVGC68hP5Ks0SRDiqdfVYvyfDwE0Q2ODkKnYkXCWbkUj7FECJSTGTeT3Job clY5i7XAhnXzUPoLUWirmv7p73JDHF/xpG1b8e/D3wDyj2S164gFpe9FJCJJm5GpYp eF66y73x7Tu/awLM3nxRdiGAhoMJAJ0QykYGtlqY= Received: from [192.168.255.10] ([113.108.77.57]) by newxmesmtplogicsvrszb6.qq.com (NewEsmtp) with SMTP id 99D8CE05; Wed, 18 May 2022 11:38:29 +0800 X-QQ-mid: xmsmtpt1652845109tdzdfybzw Message-ID: X-QQ-XMAILINFO: M6lqjKFHeg8FJ7YmNr/iNyAgeZZjCpfCr8CX64ANqtJOa5CD8u7gkkwdPCeJRJ seOSFuZp9FmLTNIgR/m8o8bUnt0flPXJju6VvCyJfpmyDHiRQDmFmFKZ4IsscAjixVbWePQLp2Ir hbtepUqdXHR4LxlhGHbCSGk1EvwSaaO6vMhAqXJd5+VR9M5vn16CVtBsOhykAyYcRU5JV/+q3Dez Fg6LANYuTah/pzqFSSh5dUWGVljZewDxyQSRb2KC71T7rjgnRO7B6URZQRT1Ziaclg47AGT4zHaL XZU4k7Vr7LE6ekaXZ8SIAz+AtJHy58cz+lMbz0e1GE8P1sDGtyRKlg1hGZiSukzTBy+VBoaKjuNU gA04W628EpWjEk/Tdlal0G3eOn/yUvlp27WxfreRAK/rbzjcnEOB37xp9sYGU1sjlE0eaO5w9Vmg EkXYPy/PQAZI+lVRhMpgjcitwPbJwg441KUmdTKLTq9DWR/g1owTcbXwmTdJ8e77Lf3AaVpxtzmR u5H7QhMNVwDTl6iqRUGxpaHMZNUa3VFmyRUaoBCHGEiT5uD6bg5jroqVODZ4ssDpUdpvoEbq7W7+ ozd+eAxx5KYLVdv1M8ZMIj7kY3l+Ku8CM/9TnsnQ7McMKZ+tSB6MWi0vAooPyHTyoHNLra7l6axp vZof4hnHNDOoATtwQWrRmwtZWpcP8XS5BogQLZnVUFODkMRwwL00MMgJ7VU1LNU1sovuoKEPUbB9 AkQSOFT1qwmhERWiK+zscICaKBgdpCp+WgfoSECXu5AKSZaTpV3vVKaCB81EmkWUgRoRl/9QMsJ0 7aLg1O1vbrGVOXTQFmKYvL8kYAFOLMN0gWuEXfivRCpoSlhMLb5VS6duER/l3wDzUAy5YwQKuSrH RmG3hVC/MUHtXWV8p0+zxF+g1r15OJtqr6DKPHTd99LqpZZDZWN6fJFAGSz7lYt4TIWzYq2sjz From: =?utf-8?B?InpoaWxpemhhbyjotbXlv5fnq4spIg==?= Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Date: Wed, 18 May 2022 11:38:28 +0800 References: <20220517203956.866831-1-derek.buitenhuis@gmail.com> To: FFmpeg development discussions and patches In-Reply-To: <20220517203956.866831-1-derek.buitenhuis@gmail.com> X-OQ-MSGID: <695C6C46-7AAE-4FFD-859B-795B00A8850C@foxmail.com> X-Mailer: Apple Mail (2.3654.60.0.2.21) Subject: Re: [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: > On May 18, 2022, at 4:39 AM, Derek Buitenhuis wrote: > > 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) > { I have an idea which needs more refactor: 1. Remove track_id argument, the `if (track_id >= 0)` code path, and the related part in search_frag_timestamp(). Setting track_id in search_frag_timestamp() is defect. sc->has_sidx is checked there, while tfra can be used here. track_id means to set a higher priority on a stream, while now we have dst_st, which has more information than track_id. 2. Give dst_st a higher priority, and search all streams. > 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". _______________________________________________ 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".