Discord.js: Strange music playback with opus codec

Created on 25 Feb 2018  Â·  6Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

Music which is played is incomplete / is jumpy / has wrong speed / doesnt play some parts. This bug occurs in the 12.0.0dev version and not in the stable one from npmjs (11.3.0) with the exact same code.

For clarification I recorded the output of my bot: (you can clearly recognize the wrong behaviour from ~25 seconds)
https://workupload.com/file/ayX5MHC

And this is the original song:
https://www.youtube.com/watch?v=A3mScURQA5U

Include a reproducible code sample here, if possible:

fluent-ffmpeg:

        this.ffmpegProcess = ffmpegCommand()
            .addInput(input)
            .format('data')
            .addOutputOptions(
                [
                    '-vn',
                    '-map 0:a',
                    '-sample_fmt s16',
                    '-acodec libopus',
                    '-b:a 96k',
                    '-ar 48k',
                    '-vbr off'
                ]);

The output of ffmpeg goes into a Transform / Duplex stream which is then played like:

guild.voiceConnection.play(stream, {type: "opus"});

also tried:

guild.voiceConnection.play(stream, {type: "opus", passes: 3});

Further details:

Dependencies:

  "dependencies": {
    "discord.js": "github:discordjs/discord.js",
    "erlpack": "github:discordapp/erlpack",
    "fluent-ffmpeg": "^2.1.2",
    "node-opus": "^0.2.7",
    "sodium": "^2.0.3",
    "typings": "^2.1.1",
    "uws": "^9.14.0"
  }
  • discord.js version: 12.0.0dev (github:discordjs/discord.js) hash: 35babc706d6351d5899aa6eb1ee4bf54be88cf04
  • node.js version: 9.6.1
  • Operating system: Kubuntu 17.10 ; Kernel: 4.13.0-36-generic
  • Priority this issue should have – please be realistic and elaborate if possible: normal

  • [ ] I found this issue while running code on a __user account__

  • [X] I have also tested the issue on latest master, commit hash: 35babc706d6351d5899aa6eb1ee4bf54be88cf04
low voice

Most helpful comment

Hmm, than its a dev branch bug. I think???

All 6 comments

What codec you have installed, I have problem with playing audio on opusscript (11.3.0), but on node-opus everything is good.

I am using node-opus v0.2.7. I quickly added my dependencies.

Hmm, than its a dev branch bug. I think???

I'm also getting this with type: "opus". It seems to be trying to play it back at the same speed as ffmpeg is outputting it. Could it need a buffer of sorts? This also happens with -frame_duration 20 sent to ffmpeg. I don't believe node-opus comes into play when using type: "opus"

@DerTechNick: What does your Transform stream look like?

Same versions:

  • node 9.6.1
  • using node-opus
  • latest master branch discord.js

Dependencies:

  "bufferutil": "^3.0.3",
  "discord.js": "git+https://github.com/discordjs/discord.js.git",
  "erlpack": "github:discordapp/erlpack",
  "libsodium-wrappers": "^0.7.3",
  "node-opus": "^0.2.7",
  "uws": "^9.14.0",
  "zlib-sync": "^0.1.4"

My transform stream is in fact just a duplex stream.

        this._outputStream = new Transform({
            transform: function (chunk, encoding, callback) {
                this.push(chunk);
                callback();
            },
            highWaterMark: 1024 * 4096 // TODO
        });

Btw: I have found a workaround. I have choosen "opus" as output format instead of "data" for ffmpeg and used "ogg/opus" as type when i play the resource.

Yep, otherwise the stream would send data back to ffmpeg to be reconverted to pcm. As a sidenote, why not just let discord.js convert your stream to opus?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dmitry221060 picture Dmitry221060  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

ghost picture ghost  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Blumlaut picture Blumlaut  Â·  3Comments