avformat/ivfenc: Set the "number of frames" in IVF header

Should set "number of frames" to bytes 24-27 of IVF header, not
duration.
It is described by [1], and confirmed by parsing all IVF files in [2].

This commit also updates the md5sum of refs to pass fate-cbs.

[1] Duck IVF - MultimediaWiki
https://wiki.multimedia.cx/index.php/Duck_IVF

[2] webm/vp8-test-vectors
https://chromium.googlesource.com/webm/vp8-test-vectors

Signed-off-by: Jianhui Dai <jianhui.j.dai@intel.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
Dai, Jianhui J 2023-07-03 04:25:38 +00:00 committed by Ronald S. Bultje
parent fcbee7efdf
commit 3b358f151d
15 changed files with 28 additions and 24 deletions

View File

@ -51,11 +51,18 @@ static int read_header(AVFormatContext *s)
st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codecpar->codec_tag);
st->codecpar->width = avio_rl16(s->pb);
st->codecpar->height = avio_rl16(s->pb);
time_base.den = avio_rl32(s->pb);
time_base.num = avio_rl32(s->pb);
st->duration = avio_rl32(s->pb);
time_base.den = avio_rl32(s->pb);
time_base.num = avio_rl32(s->pb);
st->nb_frames = avio_rl32(s->pb);
avio_skip(s->pb, 4); // unused
// Infer duration from nb_frames, in order to be backward compatible with
// previous IVF demuxer.
// It is popular to configure time_base to 1/frame_rate by IVF muxer, that
// the duration happens to be the same with nb_frames. See
// `https://chromium.googlesource.com/webm/vp8-test-vectors/+/refs/heads/main`
st->duration = st->nb_frames;
ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS;
if (!time_base.den || !time_base.num) {

View File

@ -72,7 +72,8 @@ static int ivf_write_header(AVFormatContext *s)
avio_wl16(pb, par->height);
avio_wl32(pb, s->streams[0]->time_base.den);
avio_wl32(pb, s->streams[0]->time_base.num);
avio_wl64(pb, 0xFFFFFFFFFFFFFFFFULL); // length is overwritten at the end of muxing
avio_wl32(pb, 0xFFFFFFFF); // "number of frames" is overwritten at the end of muxing
avio_wl32(pb, 0); // unused
return 0;
}
@ -99,16 +100,12 @@ static int ivf_write_trailer(AVFormatContext *s)
AVIOContext *pb = s->pb;
IVFEncContext *ctx = s->priv_data;
if ((pb->seekable & AVIO_SEEKABLE_NORMAL) &&
(ctx->frame_cnt > 1 || (ctx->frame_cnt == 1 && ctx->last_pkt_duration))) {
// overwrite the "number of frames"
if ((pb->seekable & AVIO_SEEKABLE_NORMAL)) {
int64_t end = avio_tell(pb);
avio_seek(pb, 24, SEEK_SET);
// overwrite the "length" field (duration)
avio_wl32(pb, ctx->last_pkt_duration ?
ctx->sum_delta_pts + ctx->last_pkt_duration :
ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1));
avio_wl32(pb, 0); // zero out unused bytes
avio_wl32(pb, ctx->frame_cnt);
avio_seek(pb, end, SEEK_SET);
}

View File

@ -1 +1 @@
bb630ef560f83951fa6547a664fdb636
fe62460fe28202e0666e628afd8602ca

View File

@ -1 +1 @@
2ca9d012c7212e38f5e2727ac66ec6c5
179e228004c396a301c89f34b6c72f68

View File

@ -1 +1 @@
78f5e46bfaecbcd62b9126697a0d97b7
1d1f0768c547461ae2abef57f0aabc24

View File

@ -1 +1 @@
eea9d10a696c6ed971e4fae9fb619b10
13fa042ee1b4079c227a5c5c96e2db38

View File

@ -1 +1 @@
abf4c7d4be7d3576d96b6f92166b5894
2ab7c95e4637fb6a15efd8c0a8d6af98

View File

@ -1 +1 @@
86cd3750cc9a0672717643c9b9f87fd5
b5be66a6a8792f7aac090beb9f3b4555

View File

@ -1 +1 @@
5d12fbe6220aae9e62b1d79785a83387
7bde6532fc682bfa3f5170cf9d607865

View File

@ -1 +1 @@
4c51f3c796baa7c2baa4b7ec0d011406
1e40e8b48e4682e8b8004b9e0e60a5b6

View File

@ -1 +1 @@
293bdc92851ca1105e27f04737d8c5f3
9bb416c0304a13c4f66c56aef8431cd4

View File

@ -1 +1 @@
911eafd8e442e646c5ce97d781757ca8
3a7ed001d30f96d4888f5ca16e6263ce

View File

@ -1 +1 @@
16198c32c29228e0513004ed1bf6fcee
7315bb7b55693a87c350b48cd2ee9811

View File

@ -1 +1 @@
4bceedef4aa6a663a09761971e43b5a8
1a7b5bf86bf0bbef10c9a1b2c799b276

View File

@ -1 +1 @@
0f413b840633bfcfcc78b4c9fab933bf
9b7a0b7fc081542d9be1074b23054861