[FFmpeg-devel] [PATCH] lavf/utils: update default wrap-around reference while iterating streams
Jan Ekström
jeebjp at gmail.com
Thu Feb 7 01:57:40 EET 2019
From: Masaki Tanaka <maki.rxrz at gmail.com>
Seems to fix mistaken cases of discontinuity handling in MPEG-TS
when program structure changes.
Additional changes to patch from its original state by Jan Ekström.
---
Had been meaning to post this for comments/discussion for a while, as
this seems to make timestamps continuously rising in at least one of
my samples where the program structure changes mid-stream.
The original version of this patch can be found at:
https://github.com/jeeb/ffmpeg/commit/6117366eaadbaf48bbd88eb2a353dfc852ff3400
The sample for which this helped is available at:
https://kuroko.fushizen.eu/samples/pid_switch_sample.ts
The difference of timestamps received from libavformat can be seen with:
https://kuroko.fushizen.eu/screenshots/ffmpeg/blue_vanilla-orange_patched.png
Jan
libavformat/utils.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7afef545fe..0efb1aae9c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -815,8 +815,41 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in
while (program) {
if (program->pts_wrap_reference != pts_wrap_reference) {
for (i = 0; i<program->nb_stream_indexes; i++) {
- s->streams[program->stream_index[i]]->pts_wrap_reference = pts_wrap_reference;
- s->streams[program->stream_index[i]]->pts_wrap_behavior = pts_wrap_behavior;
+ int64_t *stream_pts_wrap_reference = &(s->streams[program->stream_index[i]]->pts_wrap_reference);
+ int *stream_pts_wrap_behavior = &(s->streams[program->stream_index[i]]->pts_wrap_behavior);
+
+ if (*stream_pts_wrap_reference != AV_NOPTS_VALUE &&
+ (*stream_pts_wrap_reference - pts_wrap_reference > 1ULL << (st->pts_wrap_bits - 3) ||
+ *stream_pts_wrap_reference < pts_wrap_reference)) {
+ /*
+ * If we find a defined wrap reference that is
+ * considerably larger, or that is smaller than the
+ * current default wrap reference, we update
+ * the default to current stream's wrap reference.
+ */
+ av_log(s, AV_LOG_DEBUG,
+ "Updating default PTS wrap reference "
+ "%"PRId64" and PTS wrap behavior %d to "
+ "stream PTS wrap reference %"PRId64" and "
+ "PTS wrap behavior %d (program: %d, stream:%d, "
+ "stream_id: %d)\n", pts_wrap_reference,
+ pts_wrap_behavior,
+ *stream_pts_wrap_reference,
+ *stream_pts_wrap_behavior,
+ program->id, program->stream_index[i],
+ s->streams[program->stream_index[i]]->id);
+
+ pts_wrap_reference = *stream_pts_wrap_reference;
+ pts_wrap_behavior = *stream_pts_wrap_behavior;
+ } else {
+ /*
+ * Otherwise, we just utilize and override the
+ * stream's wrap-around reference with the default
+ * wrap-around reference.
+ */
+ *stream_pts_wrap_reference = pts_wrap_reference;
+ *stream_pts_wrap_behavior = pts_wrap_behavior;
+ }
}
program->pts_wrap_reference = pts_wrap_reference;
--
2.20.1
More information about the ffmpeg-devel
mailing list