Skip to content

Commit

Permalink
deps-libff: Adjust start_pts if invalid pts found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kc5nra committed Aug 2, 2015
1 parent 3b2b7f2 commit ff0c58e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deps/libff/libff/ff-decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff0c58e

Please sign in to comment.