Changeset 1181

Show
Ignore:
Timestamp:
10/24/09 01:59:31 (5 months ago)
Author:
astrange
Message:

Support tracks with start time delays. Fixes #424.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MatroskaImport.h

    r887 r1181  
    161161        int                                             displayOffsetSum; 
    162162        SInt64                                  durationSinceZeroSum; 
     163         
     164        // the timestamp of the first block, used to set delay for the track 
     165        TimeValue64                             lowestPTS; 
    163166}; 
    164167 
  • trunk/MatroskaImportPrivate.cpp

    r1170 r1181  
    10271027        bool replaceSoundDesc = false; 
    10281028         
     1029        lowestPTS = block.GlobalTimecode(); 
     1030         
    10291031        if (desc) { 
    10301032                switch ((*desc)->dataFormat) { 
     
    12331235        if (err) 
    12341236                Codecprintf(NULL, "MKV: error inserting media into track %d\n", err); 
    1235         else 
     1237         
     1238        if (!err) { 
     1239                if (!maxLoadedTime && lowestPTS) 
     1240                        SetTrackOffset(theTrack, lowestPTS / timecodeScale); 
     1241                 
    12361242                maxLoadedTime += durationToAdd; 
     1243        } 
    12371244         
    12381245        durationToAdd = 0; 
  • trunk/ff_private.c

    r1170 r1181  
    910910                        TimeScale mediaTimeScale; 
    911911                        TimeScale movieTimeScale; 
     912                        int startTime = map[j].str->index_entries[0].timestamp; 
    912913 
    913914                        mediaDuration = GetMediaDuration(media); 
     
    927928                        result = InsertMediaIntoTrack(track, time.value.lo, 0, mediaDuration, fixed1); 
    928929 
     930                        // set audio/video start delay 
     931                        // note str.start_time exists but is always 0 for AVI 
     932                        if (startTime) { 
     933                                TimeRecord startTimeRec; 
     934                                startTimeRec.value.hi = 0; 
     935                                startTimeRec.value.lo = startTime * map[j].str->time_base.num; 
     936                                startTimeRec.scale = map[j].str->time_base.den; 
     937                                startTimeRec.base = NULL; 
     938                                ConvertTimeScale(&startTimeRec, movieTimeScale); 
     939                                SetTrackOffset(track, startTimeRec.value.lo); 
     940                        } 
     941                         
    929942                        if(result != noErr) 
    930943                                goto bail; 
     
    961974        ComponentResult result; 
    962975        TimeValue minLoadedTime; 
     976        TimeValue movieTimeScale = GetMovieTimeScale(storage->movie); 
    963977        int64_t availableSize, margin; 
    964978        long idling; 
    965979        int readResult, framesProcessed, i; 
     980        int firstPts[storage->map_count]; 
    966981        short flags; 
    967982         
     
    9911006        } 
    9921007         
     1008        for(i = 0; i < storage->map_count; i++) 
     1009                firstPts[i] = -1; 
     1010         
    9931011        // record stream durations before we add any samples so that we know what to tell InsertMediaIntoTrack later 
    9941012        for(i = 0; i < storage->map_count; i++) { 
     
    10181036                sampleRec.dataSize = packet.size; 
    10191037                sampleRec.sampleFlags = flags; 
     1038                                 
     1039                if(firstPts[packet.stream_index] < 0) 
     1040                        firstPts[packet.stream_index] = packet.pts; 
    10201041                 
    10211042                if(packet.size > storage->largestPacketSize) 
     
    11071128                                result = InsertMediaIntoTrack(track, -1, prevDuration, addedDuration, fixed1); 
    11081129                        } 
     1130                         
     1131                        if (!prevDuration && firstPts[i] > 0) { 
     1132                                TimeRecord startTimeRec; 
     1133                                startTimeRec.value.hi = 0; 
     1134                                startTimeRec.value.lo = firstPts[i] * formatContext->streams[i]->time_base.num; 
     1135                                startTimeRec.scale = formatContext->streams[i]->time_base.den; 
     1136                                startTimeRec.base = NULL; 
     1137                                ConvertTimeScale(&startTimeRec, movieTimeScale); 
     1138                                SetTrackOffset(track, startTimeRec.value.lo); 
     1139                        } 
    11091140                        ncstream->duration = -1; 
    11101141                }