From 759231566a02db7f6de6a1cfcf59820d70ec2ad2 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 6 Nov 2010 23:17:16 +0200 Subject: demux_lavf: for avi, use packet .dts instead of .pts When playing avi files take timestamps from the .dts field of the packet instead of .pts. For avi libavformat returns the original avi timestamps in .dts; without GENPTS set .pts is sometimes unset, with GENPTS set it'll contain some made up values which are not correct pts. Current libavformat also has a bug take makes it loop over the whole avi file if you use GENPTS with video streams disabled. The timing code can cope with the avi timestamps even though they're not really pts. --- libmpdemux/demux_lavf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index 6eaae9065c..dbe6f4ecf1 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -76,6 +76,7 @@ typedef struct lavf_priv { int cur_program; int nb_streams_last; bool internet_radio_hack; + bool use_dts; }lavf_priv_t; static int mp_read(void *opaque, uint8_t *buf, int size) { @@ -516,8 +517,14 @@ static demuxer_t* demux_open_lavf(demuxer_t *demuxer){ if (lavfdopts->cryptokey) parse_cryptokey(avfc, lavfdopts->cryptokey); - if (opts->user_correct_pts != 0) - avfc->flags |= AVFMT_FLAG_GENPTS; + if (matches_avinputformat_name(priv, "avi")) { + /* for avi libavformat returns the avi timestamps in .dts, + * some made-up stuff that's not really pts in .pts */ + priv->use_dts = true; + } else { + if (opts->user_correct_pts != 0) + avfc->flags |= AVFMT_FLAG_GENPTS; + } if (index_mode == 0) avfc->flags |= AVFMT_FLAG_IGNIDX; @@ -721,8 +728,9 @@ static int demux_lavf_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){ av_free_packet(&pkt); } - if(pkt.pts != AV_NOPTS_VALUE){ - dp->pts=pkt.pts * av_q2d(priv->avfc->streams[id]->time_base); + int64_t ts = priv->use_dts ? pkt.dts : pkt.pts; + if(ts != AV_NOPTS_VALUE){ + dp->pts = ts * av_q2d(priv->avfc->streams[id]->time_base); priv->last_pts= dp->pts * AV_TIME_BASE; // always set endpts for subtitles, even if PKT_FLAG_KEY is not set, // otherwise they will stay on screen to long if e.g. ASS is demuxed from mkv -- cgit v1.2.3