Skip to content

Commit

Permalink
ffmpeg_opt: Compensate for DTS/PTS difference in seeking when its bas…
Browse files Browse the repository at this point in the history
…ed on DTS

Fixes Ticket4554

Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed May 18, 2015
1 parent b012bd5 commit b0322e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ffmpeg_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,20 @@ static int open_input_file(OptionsContext *o, const char *filename)

/* if seeking requested, we execute it */
if (o->start_time != AV_NOPTS_VALUE) {
ret = avformat_seek_file(ic, -1, INT64_MIN, timestamp, timestamp, 0);
int64_t seek_timestamp = timestamp;

if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
int dts_heuristic = 0;
for (i=0; i<ic->nb_streams; i++) {
AVCodecContext *avctx = ic->streams[i]->codec;
if (avctx->has_b_frames)
dts_heuristic = 1;
}
if (dts_heuristic) {
seek_timestamp -= 3*AV_TIME_BASE / 23;
}
}
ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
if (ret < 0) {
av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
filename, (double)timestamp / AV_TIME_BASE);
Expand Down

0 comments on commit b0322e4

Please sign in to comment.