Exemple #1
0
M4Err SetTrackDuration(TrackAtom *trak)
{
	u64 trackDuration;
	u32 i;
	edtsEntry *ent;
	EditListAtom *elst;
	M4Err e;

	//if we have an edit list, the duration is the sum of all the editList 
	//entries' duration (always expressed in MovieTimeScale)
	if (trak->EditAtom && trak->EditAtom->editList) {
		trackDuration = 0;
		elst = trak->EditAtom->editList;
		for (i = 0; i<ChainGetCount(elst->entryList); i++) {
			ent = (edtsEntry*)ChainGetEntry(elst->entryList, i);
			trackDuration += ent->segmentDuration;
		}
	} else {
		//the total duration is the media duration: adjust it in case...
		e = Media_SetDuration(trak);
		if (e) return e;
		//assert the timeScales are non-NULL
		if (!trak->moov->mvhd->timeScale && !trak->Media->mediaHeader->timeScale) return M4InvalidMP4File;
		trackDuration = (trak->Media->mediaHeader->duration * trak->moov->mvhd->timeScale) / trak->Media->mediaHeader->timeScale;
	}
	trak->Header->duration = trackDuration;
	trak->Header->modificationTime = GetMP4Time();
	return M4OK;
}
Exemple #2
0
GF_Err SetTrackDuration(GF_TrackBox *trak)
{
    u64 trackDuration;
    u32 i;
    GF_EdtsEntry *ent;
    GF_EditListBox *elst;
    GF_Err e;

    //the total duration is the media duration: adjust it in case...
    e = Media_SetDuration(trak);
    if (e) return e;

    //assert the timeScales are non-NULL
    if (!trak->moov->mvhd->timeScale || !trak->Media->mediaHeader->timeScale) return GF_ISOM_INVALID_FILE;
    trackDuration = (trak->Media->mediaHeader->duration * trak->moov->mvhd->timeScale) / trak->Media->mediaHeader->timeScale;

    //if we have an edit list, the duration is the sum of all the editList
    //entries' duration (always expressed in MovieTimeScale)
    if (trak->editBox && !trak->editBox->last_is_empty && trak->editBox->editList) {
        trackDuration = 0;
        elst = trak->editBox->editList;
        i=0;
        while ((ent = (GF_EdtsEntry*)gf_list_enum(elst->entryList, &i))) {
            trackDuration += ent->segmentDuration;
            if (ent->mediaRate && !ent->segmentDuration) {
                trak->editBox->last_is_empty = 1;
            }
        }

        if (trak->editBox->last_is_empty) {
            ent = (GF_EdtsEntry*) gf_list_last(elst->entryList);
            ent->segmentDuration = trackDuration;
        }
    }
    trak->Header->duration = trackDuration;
    trak->Header->modificationTime = gf_isom_get_mp4time();
    return GF_OK;
}