From: Aman Gupta <a...@tmm1.net> Signed-off-by: Aman Gupta <a...@tmm1.net> --- libavcodec/v4l2_buffers.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c index 389b5dea8d..d8cec06cb3 100644 --- a/libavcodec/v4l2_buffers.c +++ b/libavcodec/v4l2_buffers.c @@ -55,40 +55,41 @@ static inline AVCodecContext *logger(V4L2Buffer *buf) return buf_to_m2mctx(buf)->avctx; } +static inline AVRational v4l2_get_timebase(V4L2Buffer *avbuf) +{ + V4L2m2mContext *s = buf_to_m2mctx(avbuf); + + if (s->filterctx) + return s->filterctx->inputs[0]->time_base; + if (s->avctx->pkt_timebase.num) + return s->avctx->pkt_timebase; + return s->avctx->time_base; +} + static inline void v4l2_set_pts(V4L2Buffer *out, int64_t pts) { - V4L2m2mContext *s = buf_to_m2mctx(out); AVRational v4l2_timebase = { 1, USEC_PER_SEC }; - AVRational timebase; int64_t v4l2_pts; if (pts == AV_NOPTS_VALUE) pts = 0; - timebase = s->filterctx ? s->filterctx->inputs[0]->time_base - : s->avctx->time_base; - /* convert pts to v4l2 timebase */ - v4l2_pts = av_rescale_q(pts, timebase, v4l2_timebase); + v4l2_pts = av_rescale_q(pts, v4l2_get_timebase(out), v4l2_timebase); out->buf.timestamp.tv_usec = v4l2_pts % USEC_PER_SEC; out->buf.timestamp.tv_sec = v4l2_pts / USEC_PER_SEC; } static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf) { - V4L2m2mContext *s = buf_to_m2mctx(avbuf); AVRational v4l2_timebase = { 1, USEC_PER_SEC }; - AVRational timebase; int64_t v4l2_pts; - timebase = s->filterctx ? s->filterctx->inputs[0]->time_base - : s->avctx->time_base; - /* convert pts back to encoder timebase */ v4l2_pts = (int64_t)avbuf->buf.timestamp.tv_sec * USEC_PER_SEC + avbuf->buf.timestamp.tv_usec; - return av_rescale_q(v4l2_pts, v4l2_timebase, timebase); + return av_rescale_q(v4l2_pts, v4l2_timebase, v4l2_get_timebase(avbuf)); } static enum AVColorPrimaries v4l2_get_color_primaries(V4L2Buffer *buf) -- 2.20.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".