[FFmpeg-devel] [PATCH]Ignore xing number of frames if filesize is wrong
Nicolas George
george at nsup.org
Thu Jul 17 21:41:40 CEST 2014
Le nonidi 29 messidor, an CCXXII, Carl Eugen Hoyos a écrit :
> Hi!
>
> Attached patch fixes ticket #3777 for me, analyzed by Oliver Fromme.
>
> Please comment, Carl Eugen
> diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
> index 8335388..cdef6d9 100644
> --- a/libavformat/mp3dec.c
> +++ b/libavformat/mp3dec.c
> @@ -138,6 +138,7 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
>
> MP3DecContext *mp3 = s->priv_data;
> static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
> + int64_t fsize = avio_size(s->pb);
>
> /* Check for Xing / Info tag */
> avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
> @@ -151,6 +152,9 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
> mp3->frames = avio_rb32(s->pb);
> if (v & XING_FLAG_SIZE)
> mp3->header_filesize = avio_rb32(s->pb);
> + if (fsize > 0 && mp3->header_filesize > 0 &&
> + FFABS(fsize - (int64_t)mp3->header_filesize) / (float)FFMIN(fsize, mp3->header_filesize) > 0.05)
I would suggest to avoid floating point arithmetic if possible. Possibly
something like that:
uint64_t min = FFMIN(fsize, mp3->header_filesize);
uint64_t delta = FFMAX(fsize, mp3->header_filesize) - min;
uint64_t tolerance = min / 20;
if (... && min - tolerance < 2 * tolerance)
I also find this version easier to understand.
And in any case, someone may correct me, but I believe nowadays double
should always preferred to float unless you need a lot of them and want to
reduce the memory use.
I can not judge on the correctness, though.
> + mp3->frames = 0;
> if (v & XING_FLAG_TOC)
> read_xing_toc(s, mp3->header_filesize, av_rescale_q(mp3->frames,
> (AVRational){spf, c->sample_rate},
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140717/8e1d3b7d/attachment.asc>
More information about the ffmpeg-devel
mailing list