Commit 3b358f15 authored by Dai, Jianhui J's avatar Dai, Jianhui J Committed by Ronald S. Bultje

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-vectorsSigned-off-by: 's avatarJianhui Dai <jianhui.j.dai@intel.com>
Signed-off-by: 's avatarRonald S. Bultje <rsbultje@gmail.com>
parent fcbee7ef
...@@ -53,9 +53,16 @@ static int read_header(AVFormatContext *s) ...@@ -53,9 +53,16 @@ static int read_header(AVFormatContext *s)
st->codecpar->height = avio_rl16(s->pb); st->codecpar->height = avio_rl16(s->pb);
time_base.den = avio_rl32(s->pb); time_base.den = avio_rl32(s->pb);
time_base.num = avio_rl32(s->pb); time_base.num = avio_rl32(s->pb);
st->duration = avio_rl32(s->pb); st->nb_frames = avio_rl32(s->pb);
avio_skip(s->pb, 4); // unused 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; ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS;
if (!time_base.den || !time_base.num) { if (!time_base.den || !time_base.num) {
......
...@@ -72,7 +72,8 @@ static int ivf_write_header(AVFormatContext *s) ...@@ -72,7 +72,8 @@ static int ivf_write_header(AVFormatContext *s)
avio_wl16(pb, par->height); avio_wl16(pb, par->height);
avio_wl32(pb, s->streams[0]->time_base.den); avio_wl32(pb, s->streams[0]->time_base.den);
avio_wl32(pb, s->streams[0]->time_base.num); 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; return 0;
} }
...@@ -99,16 +100,12 @@ static int ivf_write_trailer(AVFormatContext *s) ...@@ -99,16 +100,12 @@ static int ivf_write_trailer(AVFormatContext *s)
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
IVFEncContext *ctx = s->priv_data; IVFEncContext *ctx = s->priv_data;
if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && // overwrite the "number of frames"
(ctx->frame_cnt > 1 || (ctx->frame_cnt == 1 && ctx->last_pkt_duration))) { if ((pb->seekable & AVIO_SEEKABLE_NORMAL)) {
int64_t end = avio_tell(pb); int64_t end = avio_tell(pb);
avio_seek(pb, 24, SEEK_SET); avio_seek(pb, 24, SEEK_SET);
// overwrite the "length" field (duration) avio_wl32(pb, ctx->frame_cnt);
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_seek(pb, end, SEEK_SET); avio_seek(pb, end, SEEK_SET);
} }
......
bb630ef560f83951fa6547a664fdb636 fe62460fe28202e0666e628afd8602ca
2ca9d012c7212e38f5e2727ac66ec6c5 179e228004c396a301c89f34b6c72f68
78f5e46bfaecbcd62b9126697a0d97b7 1d1f0768c547461ae2abef57f0aabc24
eea9d10a696c6ed971e4fae9fb619b10 13fa042ee1b4079c227a5c5c96e2db38
abf4c7d4be7d3576d96b6f92166b5894 2ab7c95e4637fb6a15efd8c0a8d6af98
86cd3750cc9a0672717643c9b9f87fd5 b5be66a6a8792f7aac090beb9f3b4555
5d12fbe6220aae9e62b1d79785a83387 7bde6532fc682bfa3f5170cf9d607865
4c51f3c796baa7c2baa4b7ec0d011406 1e40e8b48e4682e8b8004b9e0e60a5b6
293bdc92851ca1105e27f04737d8c5f3 9bb416c0304a13c4f66c56aef8431cd4
911eafd8e442e646c5ce97d781757ca8 3a7ed001d30f96d4888f5ca16e6263ce
16198c32c29228e0513004ed1bf6fcee 7315bb7b55693a87c350b48cd2ee9811
4bceedef4aa6a663a09761971e43b5a8 1a7b5bf86bf0bbef10c9a1b2c799b276
0f413b840633bfcfcc78b4c9fab933bf 9b7a0b7fc081542d9be1074b23054861
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment