[FFmpeg-devel] [PATCH] avformat/demux: use producer timestamp as wallclock when available
Clément Péron
peron.clem at gmail.com
Wed Oct 25 14:42:45 EEST 2023
When use_wallclock_as_timestamps option is enabled the demux rely on
the time of the system even when a producer wallclock is available.
If a Producer Reference Timestamp is available use it instead of the
system timestamp.
Signed-off-by: Clément Péron <peron.clem at gmail.com>
---
libavformat/demux.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 6decb08698..94a622e0cc 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -635,8 +635,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
force_codec_ids(s, st);
/* TODO: audio: time filter; video: frame reordering (pts != dts) */
- if (s->use_wallclock_as_timestamps)
- pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base);
+ if (s->use_wallclock_as_timestamps) {
+ AVProducerReferenceTime *prft;
+ size_t side_data_size;
+
+ // User Producer Reference time as wallclock when available
+ prft = (AVProducerReferenceTime *)av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &side_data_size);
+ if (prft && side_data_size == sizeof(AVProducerReferenceTime) && prft->flags == 24)
+ pkt->dts = pkt->pts = av_rescale_q(prft->wallclock, AV_TIME_BASE_Q, st->time_base);
+ else
+ pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base);
+ }
if (!pktl && sti->request_probe <= 0)
return 0;
--
2.42.0
More information about the ffmpeg-devel
mailing list