From dd9756286d0c98959dea77a79920063716d3c5c1 Mon Sep 17 00:00:00 2001 From: James Almer Date: Fri, 13 Feb 2026 13:00:10 -0300 Subject: [PATCH] avcodec/encode: add a helper to convert from a duration to samples Signed-off-by: James Almer --- libavcodec/encode.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/encode.h b/libavcodec/encode.h index 82bd3c9431..b66b387030 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -99,6 +99,18 @@ static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *av avctx->time_base); } +/** + * Rescale from time base to AVCodecContext.sample_rate. + */ +static av_always_inline int64_t ff_samples_from_time_base(const AVCodecContext *avctx, + int64_t duration) +{ + if (!duration) + return duration; + return av_rescale_q(duration, avctx->time_base, + (AVRational){ 1, avctx->sample_rate }); +} + /** * Check if the elements of codec context matrices (intra_matrix, inter_matrix or * chroma_intra_matrix) are within the specified range.