1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avformat/mov: don't use stream duration to calculate bitrate with fragmented input

sc->data_size may contain the size of a single fragment after probing, and
using it alongside the duration of the entire stream to calculate bitrate
will result in a bogus small value.

Before:
  Duration: 00:00:05.00, start: 0.000000, bitrate: 586 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 640x360 [SAR 1:1 DAR 16:9], 112 kb/s, 60 fps, 60 tbr, 15360 tbn (default)

After:
  Duration: 00:00:05.00, start: 0.000000, bitrate: 586 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 640x360 [SAR 1:1 DAR 16:9], 561 kb/s, 60 fps, 60 tbr, 15360 tbn (default)

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2024-04-30 23:08:46 -03:00
parent 82397084a9
commit 0ec8f3c55a

View File

@ -9667,25 +9667,7 @@ static int mov_read_header(AVFormatContext *s)
}
}
if (mov->trex_data) {
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
MOVStreamContext *sc = st->priv_data;
if (st->duration > 0) {
/* Akin to sc->data_size * 8 * sc->time_scale / st->duration but accounting for overflows. */
st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) sc->time_scale) * 8, st->duration);
if (st->codecpar->bit_rate == INT64_MIN) {
av_log(s, AV_LOG_WARNING, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
st->codecpar->bit_rate = 0;
if (s->error_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;
}
}
}
}
if (mov->use_mfra_for > 0) {
if (mov->trex_data || mov->use_mfra_for > 0) {
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
MOVStreamContext *sc = st->priv_data;