Revision 0ba84856 libavformat/movenc.c

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

Also available in: Unified diff