[FFmpeg-devel] [PATCH] lavf/concatdec: fix timestamp conversion

Stefano Sabatini stefasab at gmail.com
Wed Nov 19 11:40:36 CET 2014


On date Tuesday 2014-11-18 20:30:21 +0100, Nicolas George encoded:
> L'octidi 28 brumaire, an CCXXIII, Stefano Sabatini a écrit :
> > Use the correct output time base when converting.
> > ---
> >  libavformat/concatdec.c | 21 +++++++++++----------
> >  1 file changed, 11 insertions(+), 10 deletions(-)
> > 
> > diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> > index f275bac..2574e0b 100644
> > --- a/libavformat/concatdec.c
> > +++ b/libavformat/concatdec.c
> > @@ -480,7 +480,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
> >      int ret;
> >      int64_t delta;
> >      ConcatStream *cs;
> > -    AVStream *st;
> > +    AVStream *ist, *ost;
> >  
> >      while (1) {
> >          ret = av_read_frame(cat->avf, pkt);
> > @@ -506,22 +506,23 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
> >      if ((ret = filter_packet(avf, cs, pkt)))
> >          return ret;
> >  
> > -    st = cat->avf->streams[pkt->stream_index];
> > -    av_log(avf, AV_LOG_DEBUG, "file:%li stream:%d pts:%s pts_time:%s dts:%s dts_time:%s",
> > +    ist = cat->avf->streams[pkt->stream_index];
> > +    ost = avf     ->streams[pkt->stream_index];
> > +    av_log(avf, AV_LOG_DEBUG, "file:%li stream:%d pts:%s pts_time:%s dts:%s dts_time:%s time_base:%d/%d",
> >             cat->cur_file - cat->files, pkt->stream_index,
> > -           av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base),
> > -           av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base));
> > +           av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->time_base),
> > +           av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->time_base), ist->time_base.num, ist->time_base.den);
> >  
> 
> > +    av_packet_rescale_ts(pkt, ist->time_base, ost->time_base);
> 

> Normally, ist->time_base and ost->time_base should be the same. Can you
> explain the circumstances where this is needed?

I'm concatenating samples with different time bases. Apparently
concatdec is setting the first stream timebase as the overall
timebase, and always assuming the timebase is shared for all the input
files.

This is causing timestamp conversion issues.

Example:
ffmpeg -f lavfi -i "testsrc=d=5:r=10"        clip0.mp4
ffmpeg -f lavfi -i "testsrc=d=5:r=25,negate" clip1.mp4
cat > test.concat
ffconcat version 1.0
file clip0.mp4
file clip1.mp4
^D

ffprobe test.concat -show_entries packet=pts_time -of compact=nk=1:p=0 -loglevel debug
[...]
[concat @ 0x2696500] file:1 stream:0 pts:61440 pts_time:4.8 dts:58880 dts_time:4.6 -> pts:125440 pts_time:9.8 dts:122880 dts_time:9.6
12.250000
[concat @ 0x2696500] file:1 stream:0 pts:60416 pts_time:4.72 dts:59392 dts_time:4.64 -> pts:124416 pts_time:9.72 dts:123392 dts_time:9.64
12.150000
[concat @ 0x2696500] file:1 stream:0 pts:59904 pts_time:4.68 dts:59904 dts_time:4.68 -> pts:123904 pts_time:9.68 dts:123904 dts_time:9.68
12.100000
[concat @ 0x2696500] file:1 stream:0 pts:60928 pts_time:4.76 dts:60416 dts_time:4.72 -> pts:124928 pts_time:9.76 dts:124416 dts_time:9.72
12.200000
[concat @ 0x2696500] file:1 stream:0 pts:63488 pts_time:4.96 dts:60928 dts_time:4.76 -> pts:127488 pts_time:9.96 dts:124928 dts_time:9.76
12.450000
[concat @ 0x2696500] file:1 stream:0 pts:62464 pts_time:4.88 dts:61440 dts_time:4.8 -> pts:126464 pts_time:9.88 dts:125440 dts_time:9.8
12.350000
[concat @ 0x2696500] file:1 stream:0 pts:61952 pts_time:4.84 dts:61952 dts_time:4.84 -> pts:125952 pts_time:9.84 dts:125952 dts_time:9.84
12.300000
[concat @ 0x2696500] file:1 stream:0 pts:62976 pts_time:4.92 dts:62464 dts_time:4.88 -> pts:126976 pts_time:9.92 dts:126464 dts_time:9.88
12.400000
-- 
FFmpeg = Formidable and Foolish Meaningful Practical Epic Guru


More information about the ffmpeg-devel mailing list