From ff0c58e963245c705c00f9bfbab50c3e45b00735 Mon Sep 17 00:00:00 2001 From: kc5nra Date: Sun, 2 Aug 2015 15:54:35 -0500 Subject: [PATCH] deps-libff: Adjust start_pts if invalid pts found If the first guessed pts is less than the start_pts, it could lead to a negative PTS being returned. Change the behavior so that the first frame's pts, if zero, is set to the start_pts. If more than one frame is less than the start_pts, the start_pts is determined invalid and set to 0. Valid start_pts example: start_pts = 500 first frame (pts = 0) pts = 500 (< start_pts) pts -= 500 (offset by start_pts) ret 0 second frame (pts = 700) pts = 700 (no change, > start_pts) pts -= 500 (offset by start_pts) ret 200 Invalid start_pts example: start_pts = 500 first frame (pts = 0) pts = 500 (< start_pts) pts -= 500 (offset by start_pts) ret 0 second frame (pts = 300) pts = 300 (< start_pts, start_pts set to 0) pts -= 0 (start_pts is now 0) ret 300 --- deps/libff/libff/ff-decoder.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deps/libff/libff/ff-decoder.c b/deps/libff/libff/ff-decoder.c index 3eb658ca8..cd12e61c9 100644 --- a/deps/libff/libff/ff-decoder.c +++ b/deps/libff/libff/ff-decoder.c @@ -320,6 +320,18 @@ double ff_decoder_get_best_effort_pts(struct ff_decoder *decoder, best_effort_pts = av_frame_get_best_effort_timestamp(frame); if (best_effort_pts != AV_NOPTS_VALUE) { + // Fix the first pts if less than start_pts + if (best_effort_pts < decoder->start_pts) { + if (decoder->first_frame) { + best_effort_pts = decoder->start_pts; + } else { + av_log(NULL, AV_LOG_WARNING, "multiple pts < " + "start_pts; setting start pts " + "to 0"); + decoder->start_pts = 0; + } + } + best_effort_pts -= decoder->start_pts; // Since the best effort pts came from the stream we use his