diff mbox series

[FFmpeg-devel] avcodec/libopusenc: Fix for header pre-skip value

Message ID 20210107205559.6330-1-art@ified.ca
State Accepted
Commit f4bdeddc3cab807e43e0450744dfe9a45661e1d7
Headers show
Series [FFmpeg-devel] avcodec/libopusenc: Fix for header pre-skip value
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Arthur Taylor Jan. 7, 2021, 8:55 p.m. UTC
The Opus header initial padding preskip amount is always to be expressed
relative to 48kHz. However, the encoder delay returned from querying
libopus is relative to the encoding samplerate. Multiply by the
samplerate conversion factor to correct.

Signed-off-by: Arthur Taylor <art@ified.ca>
---
 libavcodec/libopusenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lynne Jan. 7, 2021, 9:44 p.m. UTC | #1
Jan 7, 2021, 21:55 by art@ified.ca:

> The Opus header initial padding preskip amount is always to be expressed
> relative to 48kHz. However, the encoder delay returned from querying
> libopus is relative to the encoding samplerate. Multiply by the
> samplerate conversion factor to correct.
>
> Signed-off-by: Arthur Taylor <art@ified.ca>
> ---
>  libavcodec/libopusenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
> index bf2d04b4fb..70d17f802b 100644
> --- a/libavcodec/libopusenc.c
> +++ b/libavcodec/libopusenc.c
> @@ -94,7 +94,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count,
>  bytestream_put_buffer(&p, "OpusHead", 8);
>  bytestream_put_byte(&p, 1); /* Version */
>  bytestream_put_byte(&p, channels);
> -    bytestream_put_le16(&p, avctx->initial_padding); /* Lookahead samples at 48kHz */
> +    bytestream_put_le16(&p, avctx->initial_padding * 48000 / avctx->sample_rate); /* Lookahead samples at 48kHz */
>  bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
>  bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */ 
>

Pushed, thanks.
diff mbox series

Patch

diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index bf2d04b4fb..70d17f802b 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -94,7 +94,7 @@  static void libopus_write_header(AVCodecContext *avctx, int stream_count,
     bytestream_put_buffer(&p, "OpusHead", 8);
     bytestream_put_byte(&p, 1); /* Version */
     bytestream_put_byte(&p, channels);
-    bytestream_put_le16(&p, avctx->initial_padding); /* Lookahead samples at 48kHz */
+    bytestream_put_le16(&p, avctx->initial_padding * 48000 / avctx->sample_rate); /* Lookahead samples at 48kHz */
     bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
     bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */