diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.com> | 2019-02-21 08:48:31 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-05-02 08:42:15 +0100 |
commit | 524e9e40f3b9f06cdd02f3e18069e88bd7cc63b1 (patch) | |
tree | 693fb601ac7db8a0244e5623f1640b068d707eb4 | |
parent | 7ebabedb4d63b906535af5e991f854a4254b744e (diff) | |
download | gst-libav-524e9e40f3b9f06cdd02f3e18069e88bd7cc63b1.tar.gz |
avdemux: fix negative pts if start_time is bigger than the ts
The start time is supposed to be the ts of the first frame.
FFmpeg uses fractions to represent timestamps and the start time may use a
different base than the frame pts. So we may end up having the start
time bigger than the pts because of rounding when converting to gst ts.
See https://gitlab.freedesktop.org/gstreamer/gst-libav/issues/51
for details.
-rw-r--r-- | ext/libav/gstavdemux.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/libav/gstavdemux.c b/ext/libav/gstavdemux.c index 6f3a7af..c9c5cd5 100644 --- a/ext/libav/gstavdemux.c +++ b/ext/libav/gstavdemux.c @@ -1467,8 +1467,14 @@ gst_ffmpegdemux_loop (GstFFMpegDemux * demux) goto drop; #endif - if (GST_CLOCK_TIME_IS_VALID (timestamp)) - timestamp -= demux->start_time; + if (GST_CLOCK_TIME_IS_VALID (timestamp)) { + /* start_time should be the ts of the first frame but it may actually be + * higher because of rounding when converting to gst ts. */ + if (demux->start_time >= timestamp) + timestamp = 0; + else + timestamp -= demux->start_time; + } /* check if we ran outside of the segment */ if (demux->segment.stop != -1 && timestamp > demux->segment.stop) |