Revision 0ba84856

View differences:

libavformat/movenc.c
247 247
    avio_w8(pb, size & 0x7F);
248 248
}
249 249

  
250
static unsigned compute_avg_bitrate(MOVTrack *track)
251
{
252
    uint64_t size = 0;
253
    int i;
254
    for (i = 0; i < track->entry; i++)
255
        size += track->cluster[i].size;
256
    return size * 8 * track->timescale / track->trackDuration;
257
}
258

  
250 259
static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
251 260
{
252 261
    int64_t pos = avio_tell(pb);
253 262
    int decoderSpecificInfoLen = track->vosLen ? 5+track->vosLen : 0;
263
    unsigned avg_bitrate;
254 264

  
255 265
    avio_wb32(pb, 0); // size
256 266
    ffio_wfourcc(pb, "esds");
......
282 292
    avio_w8(pb,  track->enc->rc_buffer_size>>(3+16));      // Buffersize DB (24 bits)
283 293
    avio_wb16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
284 294

  
285
    avio_wb32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
286
    if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
287
        avio_wb32(pb, 0); // vbr
288
    else
289
        avio_wb32(pb, track->enc->rc_max_rate); // avg bitrate
295
    avg_bitrate = compute_avg_bitrate(track);
296
    // maxbitrate (FIXME should be max rate in any 1 sec window)
297
    avio_wb32(pb, FFMAX3(track->enc->bit_rate, track->enc->rc_max_rate, avg_bitrate));
298
    avio_wb32(pb, avg_bitrate);
290 299

  
291 300
    if (track->vosLen) {
292 301
        // DecoderSpecific info descriptor
tests/ref/lavf/mov
1
439684b82ccc1fdd24a23392c238ae53 *./tests/data/lavf/lavf.mov
1
a901cd05609080e8f5c09ca5da7290f0 *./tests/data/lavf/lavf.mov
2 2
357681 ./tests/data/lavf/lavf.mov
3 3
./tests/data/lavf/lavf.mov CRC=0x2f6a9b26
tests/ref/vsynth1/mpeg4
1
080e75117f8142001b096cd977ba287e *./tests/data/vsynth1/odivx.mp4
1
d2405fd9e350854a161f48bc63f49253 *./tests/data/vsynth1/odivx.mp4
2 2
540156 ./tests/data/vsynth1/odivx.mp4
3 3
8828a375448dc5c2215163ba70656f89 *./tests/data/mpeg4.vsynth1.out.yuv
4 4
stddev:    7.97 PSNR: 30.10 MAXDIFF:  105 bytes:  7603200/  7603200
tests/ref/vsynth2/mpeg4
1
8ffbe8ce43fe126b12cf9621717d641b *./tests/data/vsynth2/odivx.mp4
1
2e3bf184668d4807ae6df0bdceba487b *./tests/data/vsynth2/odivx.mp4
2 2
119809 ./tests/data/vsynth2/odivx.mp4
3 3
90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.vsynth2.out.yuv
4 4
stddev:    5.34 PSNR: 33.57 MAXDIFF:   83 bytes:  7603200/  7603200

Also available in: Unified diff