if(maxTrackLen < mov->tracks[i].entry*mov->tracks[i].frameDuration) maxTrackLen = mov->tracks[i].entry*mov->tracks[i].frameDuration;
maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)mov->tracks[i].trackDuration)/(int64_t)mov->tracks[i].timescale; if(maxTrackLen < maxTrackLenTemp) maxTrackLen = maxTrackLenTemp;
static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov){    int maxTrackID = 1, maxTrackLen = 0, i;    put_be32(pb, 0x6c); /* size (always 0x6c) */    put_tag(pb, "mvhd");    put_be32(pb, 0); /* version & flags */    put_be32(pb, mov->time); /* creation time */    put_be32(pb, mov->time); /* modification time */    put_be32(pb, mov->timescale); /* timescale */    for (i=0; i<MAX_STREAMS; i++) {        if(mov->tracks[i].entry > 0) {            if(maxTrackLen < mov->tracks[i].entry*mov->tracks[i].frameDuration)                maxTrackLen = mov->tracks[i].entry*mov->tracks[i].frameDuration;            if(maxTrackID < mov->tracks[i].trackID)                maxTrackID = mov->tracks[i].trackID;        }    }    put_be32(pb, maxTrackLen); /* duration of longest track */    put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */    put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */    put_be16(pb, 0); /* reserved */    put_be32(pb, 0); /* reserved */    put_be32(pb, 0); /* reserved */    /* Matrix structure */    put_be32(pb, 0x00010000); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x00010000); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x0); /* reserved */    put_be32(pb, 0x40000000); /* reserved */    put_be32(pb, 0); /* reserved (preview time) */    put_be32(pb, 0); /* reserved (preview duration) */    put_be32(pb, 0); /* reserved (poster time) */    put_be32(pb, 0); /* reserved (selection time) */    put_be32(pb, 0); /* reserved (selection duration) */    put_be32(pb, 0); /* reserved (current time) */    put_be32(pb, maxTrackID+1); /* Next track id */    return 0x6c;}