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
master
kc5nra 2015-08-02 15:54:35 -05:00
parent 3b2b7f2f37
commit ff0c58e963
1 changed files with 12 additions and 0 deletions

View File

@ -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