History

ismindex: handle time discontinuities and nonzero start time

The input file may not have consistent start times, stream durations and chunk durations. This patch at least removes negative durations that make chromecast unhappy, and correctly sets starting time on chunks so that the split (or .ismf) outputs match the manifest.

Mika Raento committed 12 years ago

Commit 00431bf1 parent 775a0b01 file · +42 −3Browse files

Unified · Split

tools/ismindex.c+42−3
@@ -252,6 +252,13 @@ static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f) · 251 unmodified lines
252252 ret = AVERROR(ENOMEM);
253253 goto fail;
254254 }
255+ // The duration here is always the difference between consecutive
256+ // start times and doesn't even try to read the actual duration of the
257+ // media fragments. This is what other smooth streaming tools tend to
258+ // do too, but cannot express missing fragments, and the start times
259+ // may not match the stream metadata we get from libavformat. Correct
260+ // calculation would require parsing the tfxd atom (if present, it's
261+ // not mandatory) or parsing the full moof atoms separately.
255262 for (i = 0; i < track->chunks; i++) {
256263 if (version == 1) {
257264 track->offsets[i].time = avio_rb64(f);
@@ -270,9 +277,30 @@ static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f) · 12 unmodified lines
270277 track->offsets[i - 1].duration = track->offsets[i].time -
271278 track->offsets[i - 1].time;
272279 }
273− if (track->chunks > 0)
274− track->offsets[track->chunks - 1].duration = track->duration -
280+ if (track->chunks > 0) {
281+ track->offsets[track->chunks - 1].duration = track->offsets[0].time +
282+ track->duration -
275283 track->offsets[track->chunks - 1].time;
284+ if (track->offsets[track->chunks - 1].duration <= 0) {
285+ fprintf(stderr, "Calculated last chunk duration for track %d "
286+ "was non-positive (%"PRId64"), probably due to missing "
287+ "fragments ", track->track_id,
288+ track->offsets[track->chunks - 1].duration);
289+ if (track->chunks > 1) {
290+ track->offsets[track->chunks - 1].duration =
291+ track->offsets[track->chunks - 2].duration;
292+ } else {
293+ track->offsets[track->chunks - 1].duration = 1;
294+ }
295+ fprintf(stderr, "corrected to %"PRId64"\n",
296+ track->offsets[track->chunks - 1].duration);
297+ track->duration = track->offsets[track->chunks - 1].time +
298+ track->offsets[track->chunks - 1].duration -
299+ track->offsets[0].time;
300+ fprintf(stderr, "Track duration corrected to %"PRId64"\n",
301+ track->duration);
302+ }
303+ }
276304 ret = 0;
277305
278306 fail:
@@ -524,6 +552,7 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main, · 245 unmodified lines
524552 const char *type)
525553 {
526554 int i, j;
555+ int64_t pos = 0;
527556 struct Track *track = tracks->tracks[main];
528557 int should_print_time_mismatch = 1;
529558
@@ -543,8 +572,18 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main, · 13 unmodified lines
543572 }
544573 }
545574 }
546− fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" />\n",
575+ fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" ",
547576 i, track->offsets[i].duration);
577+ if (pos != track->offsets[i].time) {
578+ // With the current logic for calculation of durations from
579+ // chunk start times, this branch can only be hit on the first
580+ // chunk - but that's still useful and this will keep working
581+ // if the duration calculation is improved.
582+ fprintf(out, "t=\"%"PRId64"\" ", track->offsets[i].time);
583+ pos = track->offsets[i].time;
584+ }
585+ pos += track->offsets[i].duration;
586+ fprintf(out, "/>\n");
548587 }
549588 }
550589

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t