diff --git a/CHANGELOG.md b/CHANGELOG.md index cd4df136c6..dceebd4d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ These changes are available on the `master` branch, but have not yet been releas - Fixed `Enum` options not setting the correct type when only one choice is available. ([#2577](https://github.com/Pycord-Development/pycord/pull/2577)) +- Fixed `codec` option for `FFmpegOpusAudio` class to make it in line with + documentation. ([#2581](https://github.com/Pycord-Development/pycord/pull/2581)) ### Changed diff --git a/discord/player.py b/discord/player.py index b76fe7b366..d7631907f0 100644 --- a/discord/player.py +++ b/discord/player.py @@ -355,8 +355,9 @@ class FFmpegOpusAudio(FFmpegAudio): The codec to use to encode the audio data. Normally this would be just ``libopus``, but is used by :meth:`FFmpegOpusAudio.from_probe` to opportunistically skip pointlessly re-encoding Opus audio data by passing - ``copy`` as the codec value. Any values other than ``copy``, ``opus``, or - ``libopus`` will be considered ``libopus``. Defaults to ``libopus``. + ``copy`` as the codec value. Any values other than ``copy``, or + ``libopus`` will be considered ``libopus``. ``opus`` will also be considered + ``libopus`` since the ``opus`` encoder is still in development. Defaults to ``libopus``. .. warning:: @@ -407,7 +408,9 @@ def __init__( args.append("-i") args.append("-" if pipe else source) - codec = "copy" if codec in ("opus", "libopus") else "libopus" + # use "libopus" when "opus" is specified since the "opus" encoder is incomplete + # link to ffmpeg docs: https://www.ffmpeg.org/ffmpeg-codecs.html#opus + codec = "copy" if codec == "copy" else "libopus" args.extend( ( @@ -417,17 +420,24 @@ def __init__( "opus", "-c:a", codec, - "-ar", - "48000", - "-ac", - "2", - "-b:a", - f"{bitrate}k", "-loglevel", "warning", ) ) + # only pass in bitrate, sample rate, channels arguments when actually encoding to avoid ffmpeg warnings + if codec != "copy": + args.extend( + ( + "-ar", + "48000", + "-ac", + "2", + "-b:a", + f"{bitrate}k", + ) + ) + if isinstance(options, str): args.extend(shlex.split(options)) @@ -501,6 +511,8 @@ def custom_probe(source, executable): executable = kwargs.get("executable") codec, bitrate = await cls.probe(source, method=method, executable=executable) + # only re-encode if the source isn't already opus, else directly copy the source audio stream + codec = "copy" if codec in ("opus", "libopus") else "libopus" return cls(source, bitrate=bitrate, codec=codec, **kwargs) # type: ignore @classmethod