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
252 ret = AVERROR(ENOMEM);252 ret = AVERROR(ENOMEM);
253 goto fail;253 goto fail;
254 }254 }
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.
255 for (i = 0; i < track->chunks; i++) {262 for (i = 0; i < track->chunks; i++) {
256 if (version == 1) {263 if (version == 1) {
257 track->offsets[i].time = avio_rb64(f);264 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
270 track->offsets[i - 1].duration = track->offsets[i].time -277 track->offsets[i - 1].duration = track->offsets[i].time -
271 track->offsets[i - 1].time;278 track->offsets[i - 1].time;
272 }279 }
273 if (track->chunks > 0)280 if (track->chunks > 0) {
274 track->offsets[track->chunks - 1].duration = track->duration -281 track->offsets[track->chunks - 1].duration = track->offsets[0].time +
282 track->duration -
275 track->offsets[track->chunks - 1].time;283 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 }
276 ret = 0;304 ret = 0;
277 305
278fail:306fail:
@@ -524,6 +552,7 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main, · 245 unmodified lines
524 const char *type)552 const char *type)
525{553{
526 int i, j;554 int i, j;
555 int64_t pos = 0;
527 struct Track *track = tracks->tracks[main];556 struct Track *track = tracks->tracks[main];
528 int should_print_time_mismatch = 1;557 int should_print_time_mismatch = 1;
529 558
@@ -543,8 +572,18 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main, · 13 unmodified lines
543 }572 }
544 }573 }
545 }574 }
546 fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" />\n",575 fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" ",
547 i, track->offsets[i].duration);576 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");
548 }587 }
549}588}
550 589

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