0

As I understand, ffmpeg compiled with --enable-libopus has two opus decoders: builtin and libopus. I am decoding an opus file to wav.

  1. How can I know which opus decoder is being used by ffmpeg?

  2. opusdec has an option --rate which can directly downsample to the needed sample rate. When I use ffmpeg for decoding an opus file and set -ar, the decoding time grows x6 from the baseline 10sec (for a 3Mb, 2hour opus file). For opusdec, the decoding time is same regardless of used --rate. So I suspect that ffmpeg has some bug or duplicates resampling work. For workaround, is there a way to pass an option to ffmpeg to pass it down to libopus and to emulate the effect of --rate?

Thank you!

UPD Adding -acodec libopus in the beginning of ffmpeg command clearly does something (forces libopus decoder?) and completes decoding in 6.2sec. When I add -ar 8000, it slows down to 7.3sec. I would assume, it's still too large of a change for a fair effect of downsampling (for opusdec -ar 8000 actually speeds things up, not slows it), so maybe ffmpeg has a decoder configuration / resampling bug even when libopus decoder is used.

1 Answer 1

0

The libopus decoder in ffmpeg will only output at a fixed rate of 48000 Hz. Using -ar leads to resampling using the swresample library.

3
  • It appears that you're right and the sample_rate is reset at avc->sample_rate = 48000;. It's a shame that there is no way to save compute and resample directly to the requested sample_rate... I guess the proper way would be to introduce special libopus decoder options if -ar is supposed to only affect post-hoc swresample processing. Commented Jun 23, 2023 at 5:30
  • introduce special libopus decoder options --> this possibility will depend on whether the resampling is taken care of by the decoder directly or does opusdec delegate it to a bundled resampler. If the latter, then it will be the responsibility of the libopus decoder wrapper in ffmpeg to insert a resampler and that won't be allowed since ffmpeg architecture guidelines don't allow mixing of resampling inside a decoder interface. That violates clean separation of library roles. That said, you haven't posted your command and log, so I can't check if you've unnecessary compute in your runtime.
    – Gyan
    Commented Jun 23, 2023 at 6:43
  • I'll check if I can repro on a synthetic file and will post full ffmpeg command lines. libopus can do resampling to the target sample rate directly during decoding, but it appears that ffmpeg doesn't let the user access this functionality. It also appears post-hoc resampling severely affects wall clock time for the builtin opus decoder case (no such bad difference for libopus decoder) Commented Jun 26, 2023 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.