From 0ba8485666f532f2dbab716f74e1be1189102c89 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier Date: Sat, 16 Apr 2011 16:19:10 -0700 Subject: [PATCH] In mov muxer, compute avg bitrate in esds --- libavformat/movenc.c | 19 ++++++++++++++----- tests/ref/lavf/mov | 2 +- tests/ref/vsynth1/mpeg4 | 2 +- tests/ref/vsynth2/mpeg4 | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 599c913b35..5bc356279a 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -247,10 +247,20 @@ static void putDescr(AVIOContext *pb, int tag, unsigned int size) avio_w8(pb, size & 0x7F); } +static unsigned compute_avg_bitrate(MOVTrack *track) +{ + uint64_t size = 0; + int i; + for (i = 0; i < track->entry; i++) + size += track->cluster[i].size; + return size * 8 * track->timescale / track->trackDuration; +} + static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic { int64_t pos = avio_tell(pb); int decoderSpecificInfoLen = track->vosLen ? 5+track->vosLen : 0; + unsigned avg_bitrate; avio_wb32(pb, 0); // size ffio_wfourcc(pb, "esds"); @@ -282,11 +292,10 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic avio_w8(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits) avio_wb16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB - avio_wb32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window) - if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0) - avio_wb32(pb, 0); // vbr - else - avio_wb32(pb, track->enc->rc_max_rate); // avg bitrate + avg_bitrate = compute_avg_bitrate(track); + // maxbitrate (FIXME should be max rate in any 1 sec window) + avio_wb32(pb, FFMAX3(track->enc->bit_rate, track->enc->rc_max_rate, avg_bitrate)); + avio_wb32(pb, avg_bitrate); if (track->vosLen) { // DecoderSpecific info descriptor diff --git a/tests/ref/lavf/mov b/tests/ref/lavf/mov index 22aac3600e..940e518b5f 100644 --- a/tests/ref/lavf/mov +++ b/tests/ref/lavf/mov @@ -1,3 +1,3 @@ -439684b82ccc1fdd24a23392c238ae53 *./tests/data/lavf/lavf.mov +a901cd05609080e8f5c09ca5da7290f0 *./tests/data/lavf/lavf.mov 357681 ./tests/data/lavf/lavf.mov ./tests/data/lavf/lavf.mov CRC=0x2f6a9b26 diff --git a/tests/ref/vsynth1/mpeg4 b/tests/ref/vsynth1/mpeg4 index ebe2f5a613..93c13bc662 100644 --- a/tests/ref/vsynth1/mpeg4 +++ b/tests/ref/vsynth1/mpeg4 @@ -1,4 +1,4 @@ -080e75117f8142001b096cd977ba287e *./tests/data/vsynth1/odivx.mp4 +d2405fd9e350854a161f48bc63f49253 *./tests/data/vsynth1/odivx.mp4 540156 ./tests/data/vsynth1/odivx.mp4 8828a375448dc5c2215163ba70656f89 *./tests/data/mpeg4.vsynth1.out.yuv stddev: 7.97 PSNR: 30.10 MAXDIFF: 105 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth2/mpeg4 b/tests/ref/vsynth2/mpeg4 index fe436e88f3..d534ec1ed1 100644 --- a/tests/ref/vsynth2/mpeg4 +++ b/tests/ref/vsynth2/mpeg4 @@ -1,4 +1,4 @@ -8ffbe8ce43fe126b12cf9621717d641b *./tests/data/vsynth2/odivx.mp4 +2e3bf184668d4807ae6df0bdceba487b *./tests/data/vsynth2/odivx.mp4 119809 ./tests/data/vsynth2/odivx.mp4 90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.vsynth2.out.yuv stddev: 5.34 PSNR: 33.57 MAXDIFF: 83 bytes: 7603200/ 7603200