On Sun, 14 Sep 2014, Mika Raento wrote:
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.
---
tools/ismindex.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/tools/ismindex.c b/tools/ismindex.c
index bc98226..9f46030 100644
--- a/tools/ismindex.c
+++ b/tools/ismindex.c
@@ -252,6 +252,11 @@ static int read_tfra(struct Tracks *tracks, int
start_index, AVIOContext *f)
ret = AVERROR(ENOMEM);
goto fail;
}
+ // The duration here is always the difference between consecutive
+ // start times and doesn't even try to read the actual duration of the
+ // media fragments. This is what other smooth streaming tools tend to
+ // do too, but cannot express missing fragments, and the start times
+ // may not match the stream metadata we get from libavcodec.
Nit: libavformat
for (i = 0; i < track->chunks; i++) {
if (version == 1) {
track->offsets[i].time = avio_rb64(f);
@@ -270,9 +275,28 @@ static int read_tfra(struct Tracks *tracks, int
start_index, AVIOContext *f)
track->offsets[i - 1].duration = track->offsets[i].time -
track->offsets[i - 1].time;
}
- if (track->chunks > 0)
+ if (track->chunks > 0) {
track->offsets[track->chunks - 1].duration = track->duration -
track->offsets[track->chunks - 1].time;
Why not simply change this into this instead?
track->offsets[track->chunks - 1].duration = track->offsets[0].time +
track->duration -
track->offsets[track->chunks - 1].time;
This would take care of the case of a nonzero start time without any extra
fuss, and would be completely correct continuous files with nonzero start.
+ if (track->offsets[track->chunks - 1].duration <= 0) {
+ fprintf(stderr, "calculated last chunk duration for track %d "
+ "was non-positive (%"PRId64"), probably due to non-0 "
+ "starting time - ", track->track_id,
+ track->offsets[track->chunks - 1].duration);
+ if (track->chunks > 1) {
+ track->offsets[track->chunks - 1].duration =
+ track->offsets[track->chunks - 2].duration;
+ } else {
+ track->offsets[track->chunks - 1].duration = 1;
+ }
IMO it's unnecessary to try to do this kind of guessing for
continuous files with nonzero start time, which we can handle
exactly/correctly anyway.
+ fprintf(stderr, "corrected to %"PRId64"\n",
+ track->offsets[track->chunks - 1].duration);
+ track->duration = track->offsets[track->chunks - 1].time +
+ track->offsets[track->chunks - 1].duration;
This calculation still assumes we've shifted the timestamps back to 0,
which this patch no longer does - right?
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel