Revision 02f487fc

View differences:

libavformat/matroskaenc.c
28 28
    offset_t    segment;
29 29
    offset_t    cluster;
30 30
    uint64_t    cluster_pts;
31
    offset_t    duration_offset;
32
    uint64_t    duration;
31 33
} MatroskaMuxContext;
32 34

  
33 35
static void put_ebml_id(ByteIOContext *pb, unsigned int id)
......
155 157
        // XXX: both are required; something better for writing app?
156 158
        put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);
157 159
    }
158
    // XXX: segment UID and duration
160
    // XXX: segment UID
161
    // reserve space for the duration
162
    mkv->duration = 0;
163
    mkv->duration_offset = url_ftell(pb);
164
    put_ebml_void(pb, 11);                  // assumes double-precision float to be written
159 165
    end_ebml_master(pb, segment_info);
160 166

  
161 167
    tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS);
......
290 296
    put_byte(pb, !!(pkt->flags & PKT_FLAG_KEY));
291 297
    put_buffer(pb, pkt->data, pkt->size);
292 298
    end_ebml_master(pb, block);
299

  
300
    mkv->duration = pkt->pts + pkt->duration;
293 301
    return 0;
294 302
}
295 303

  
......
297 305
{
298 306
    MatroskaMuxContext *mkv = s->priv_data;
299 307
    ByteIOContext *pb = &s->pb;
308
    offset_t currentpos;
309

  
300 310
    end_ebml_master(pb, mkv->cluster);
311

  
312
    // update the duration
313
    currentpos = url_ftell(pb);
314
    url_fseek(pb, mkv->duration_offset, SEEK_SET);
315
    put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration);
316
    url_fseek(pb, currentpos, SEEK_SET);
317

  
301 318
    end_ebml_master(pb, mkv->segment);
302 319
    return 0;
303 320
}

Also available in: Unified diff