avcodec/encode: add a helper to convert from a duration to samples

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-02-13 13:00:10 -03:00
parent cb0f4de1f5
commit dd9756286d
+12
View File
@@ -99,6 +99,18 @@ static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *av
avctx->time_base); 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 * Check if the elements of codec context matrices (intra_matrix, inter_matrix or
* chroma_intra_matrix) are within the specified range. * chroma_intra_matrix) are within the specified range.