avformat: add skip_estimate_duration_from_pts

For seekable mpegts streams, duration is calculated from
pts by seeking to the end of the file for a pts and subtracting
the initial pts to compute a duration.

This can be expensive in terms of added latency during
probe, especially when streaming over a network. This new
option lets you skip the duration calculation, which is useful
when you don't care about the value and want to save some overhead.

This patch is particularly useful when dealing with live mpegts
streams. Normally such streams are not seekable, so durations
are not calculated. However in my case I am dealing with a seekable
live mpegts stream (networked access to a .ts file which is still
being appended to).

Signed-off-by: Aman Gupta <aman@tmm1.net>
This commit is contained in:
Aman Gupta
2018-05-15 15:56:45 -07:00
parent 380ca1bc0c
commit 2734f8d63a
3 changed files with 14 additions and 0 deletions

View File

@@ -2812,6 +2812,11 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
}
}
if (ic->skip_estimate_duration_from_pts) {
av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n");
goto skip_duration_calc;
}
av_opt_set(ic, "skip_changes", "1", AV_OPT_SEARCH_CHILDREN);
/* estimate the end time (duration) */
/* XXX: may need to support wrapping */
@@ -2896,6 +2901,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
}
}
}
skip_duration_calc:
fill_all_stream_timings(ic);
avio_seek(ic->pb, old_offset, SEEK_SET);