Revision 7524f46e

View differences:

libavformat/mxfenc.c
1001 1001
}
1002 1002

  
1003 1003
static void mxf_write_partition(AVFormatContext *s, int bodysid,
1004
                                int indexsid, unsigned index_byte_count,
1004
                                int indexsid,
1005 1005
                                const uint8_t *key, int write_metadata)
1006 1006
{
1007 1007
    MXFContext *mxf = s->priv_data;
1008 1008
    ByteIOContext *pb = s->pb;
1009 1009
    int64_t header_byte_count_offset;
1010
    unsigned index_byte_count = 0;
1011

  
1012
    if (mxf->edit_units_count) {
1013
        index_byte_count = 109 + (s->nb_streams+1)*6 +
1014
            mxf->edit_units_count*(11+mxf->slice_count*4);
1015
        // add encoded ber length
1016
        index_byte_count += 16 + klv_ber_length(index_byte_count);
1017
        index_byte_count += klv_fill_size(index_byte_count);
1018
    }
1010 1019

  
1011 1020
    // write klv
1012 1021
    put_buffer(pb, key, 16);
......
1029 1038

  
1030 1039
    // indexTable
1031 1040
    put_be64(pb, index_byte_count); // indexByteCount
1032
    put_be32(pb, indexsid); // indexSID
1041
    put_be32(pb, index_byte_count ? indexsid : 0); // indexSID
1033 1042
    put_be64(pb, 0); // bodyOffset
1034 1043

  
1035 1044
    put_be32(pb, bodysid); // bodySID
......
1320 1329
    }
1321 1330

  
1322 1331
    if (!mxf->header_written) {
1323
        mxf_write_partition(s, 1, 0, 0, header_open_partition_key, 1);
1332
        mxf_write_partition(s, 1, 0, header_open_partition_key, 1);
1324 1333
        mxf->header_written = 1;
1325 1334
    }
1326 1335

  
......
1369 1378
{
1370 1379
    MXFContext *mxf = s->priv_data;
1371 1380
    ByteIOContext *pb = s->pb;
1372
    unsigned index_byte_count =
1373
        109 + (s->nb_streams+1)*6 +
1374
        mxf->edit_units_count*(11+mxf->slice_count*4);
1375

  
1376
    // add encoded ber length
1377
    index_byte_count += 16 + klv_ber_length(index_byte_count);
1378
    index_byte_count += klv_fill_size(index_byte_count);
1379 1381

  
1380 1382
    mxf_write_klv_fill(s);
1381 1383
    mxf->footer_partition_offset = url_ftell(pb);
1382
    mxf_write_partition(s, 0, 2, index_byte_count, footer_partition_key, 0);
1384
    mxf_write_partition(s, 0, 2, footer_partition_key, 0);
1383 1385

  
1384 1386
    mxf_write_klv_fill(s);
1385 1387
    mxf_write_index_table_segment(s);
......
1389 1391

  
1390 1392
    if (!url_is_streamed(s->pb)) {
1391 1393
        url_fseek(pb, 0, SEEK_SET);
1392
        mxf_write_partition(s, 1, 0, 0, header_closed_partition_key, 1);
1394
        mxf_write_partition(s, 1, 0, header_closed_partition_key, 1);
1393 1395
    }
1394 1396

  
1395 1397
    ff_audio_interleave_close(s);

Also available in: Unified diff