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 C698743520 for ; Sat, 16 Jul 2022 13:53:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01D6A68B915; Sat, 16 Jul 2022 16:53:39 +0300 (EEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A564B68B74D for ; Sat, 16 Jul 2022 16:53:32 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id E5F951BF203 for ; Sat, 16 Jul 2022 13:53:31 +0000 (UTC) Date: Sat, 16 Jul 2022 15:53:31 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220716135331.GK2088045@pb2> References: <20220714044814.72083-1-quinkblack@foxmail.com> MIME-Version: 1.0 In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH 2/2] avformat/flvdec: make key frame timestamps more accurate 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: multipart/mixed; boundary="===============4074057581403922253==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============4074057581403922253== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cN0A5YokcrYPGsSB" Content-Disposition: inline --cN0A5YokcrYPGsSB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 14, 2022 at 12:48:14PM +0800, Zhao Zhili wrote: > From: Zhao Zhili >=20 > There is an implicit cast from double to int64_t in time unit of > second. > --- > libavformat/flvdec.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) >=20 > diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c > index c5d3c63bd0..a78d720295 100644 > --- a/libavformat/flvdec.c > +++ b/libavformat/flvdec.c > @@ -146,9 +146,9 @@ static void add_keyframes_index(AVFormatContext *s) > if (ffstream(stream)->nb_index_entries =3D=3D 0) { > for (i =3D 0; i < flv->keyframe_count; i++) { > av_log(s, AV_LOG_TRACE, "keyframe filepositions =3D %"PRId64= " times =3D %"PRId64"\n", > - flv->keyframe_filepositions[i], flv->keyframe_times[i= ] * 1000); > + flv->keyframe_filepositions[i], flv->keyframe_times[i= ]); > av_add_index_entry(stream, flv->keyframe_filepositions[i], > - flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME); > + flv->keyframe_times[i], 0, 0, AVINDEX_KEYFRAME); > } > } else > av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n"); > @@ -461,9 +461,13 @@ static int parse_keyframes_index(AVFormatContext *s,= AVIOContext *ioc, int64_t m > d =3D av_int2double(avio_rb64(ioc)); > if (isnan(d) || d < INT64_MIN || d > INT64_MAX) > goto invalid; > - if (current_array =3D=3D × && (d <=3D INT64_MIN / 1000 = || d >=3D INT64_MAX / 1000)) > - goto invalid; > - current_array[0][i] =3D d; > + if (current_array =3D=3D ×) { > + if (d <=3D INT64_MIN / 1000 || d >=3D INT64_MAX / 1000) > + goto invalid; > + current_array[0][i] =3D d * 1000; > + } else { > + current_array[0][i] =3D d; > + } > } > if (times && filepositions) { > // All done, exiting at a position allowing amf_parse_object > @@ -476,7 +480,7 @@ static int parse_keyframes_index(AVFormatContext *s, = AVIOContext *ioc, int64_t m > if (timeslen =3D=3D fileposlen && fileposlen>1 && max_pos <=3D filep= ositions[0]) { > for (i =3D 0; i < FFMIN(2,fileposlen); i++) { > flv->validate_index[i].pos =3D filepositions[i]; > - flv->validate_index[i].dts =3D times[i] * 1000; > + flv->validate_index[i].dts =3D times[i]; > flv->validate_count =3D i + 1; > } > flv->keyframe_times =3D times; can be simplified like this: diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index a78d720295..3155b2a517 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -428,6 +428,7 @@ static int parse_keyframes_index(AVFormatContext *s, AV= IOContext *ioc, int64_t m amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { int64_t **current_array; unsigned int arraylen; + int factor; =20 // Expect array object in context if (avio_r8(ioc) !=3D AMF_DATA_TYPE_ARRAY) @@ -440,10 +441,12 @@ static int parse_keyframes_index(AVFormatContext *s, = AVIOContext *ioc, int64_t m if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) { current_array =3D × timeslen =3D arraylen; + factor =3D 1000; } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions) { current_array =3D &filepositions; fileposlen =3D arraylen; + factor =3D 1; } else // unexpected metatag inside keyframes, will not use such // metadata for indexing @@ -458,16 +461,10 @@ static int parse_keyframes_index(AVFormatContext *s, = AVIOContext *ioc, int64_t m double d; if (avio_r8(ioc) !=3D AMF_DATA_TYPE_NUMBER) goto invalid; - d =3D av_int2double(avio_rb64(ioc)); + d =3D av_int2double(avio_rb64(ioc)) * factor; if (isnan(d) || d < INT64_MIN || d > INT64_MAX) goto invalid; - if (current_array =3D=3D ×) { - if (d <=3D INT64_MIN / 1000 || d >=3D INT64_MAX / 1000) - goto invalid; - current_array[0][i] =3D d * 1000; - } else { - current_array[0][i] =3D d; - } + current_array[0][i] =3D d; } if (times && filepositions) { // All done, exiting at a position allowing amf_parse_object [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire --cN0A5YokcrYPGsSB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYtLC1wAKCRBhHseHBAsP q4JhAJ9UOsMsRAc5jKEAlv2Pkioz2kbTSgCcDGNVlD5CuTOVzWHz60l5PijFBg4= =G8T1 -----END PGP SIGNATURE----- --cN0A5YokcrYPGsSB-- --===============4074057581403922253== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============4074057581403922253==--