twlite / discord-ytdl-core

Simple ytdl wrapper for discord bots with custom ffmpeg args support.
https://www.npmjs.com/package/discord-ytdl-core
Apache License 2.0
51 stars 10 forks source link

Certain encoderArgs throw errors #20

Closed jamesdools closed 3 years ago

jamesdools commented 3 years ago

Heya - great job on the wrapper, super useful!

I wanted to be able to give a start & end time to a youtube clip but it's throwing errors that I'm not really able to interpret.

Here's the snippet:

  const ytdlContent = ytdl(song.url, {
      filter: 'audioonly',
      opusEncoded: true,
      encoderArgs: ['-ss', song.startTime, '-t', song.endTime]
    });

  const dispatcher = serverQueue.connection
    .play(ytdlContent, { type: 'opus' })
    .on('finish', () => {
      serverQueue.songs.shift();
      play(guild, serverQueue.songs[0]);
    })
    .on('error', (error) => console.error(err));

Where song.startTime & song.endTime look something like 2:30, 2:42.

Worth mentioning that only using the startTime works, eg:

 encoderArgs: ['-ss', song.startTime]

Wondering if you meant to add an end time but it was problematic - or am I just using ffmpeg wrong? Here's the error thrown btw (it never gets to the .on( 'error') catch)

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16)
Emitted 'error' event on FFmpeg instance at:
    at FFmpeg.onerror (internal/streams/readable.js:760:14)
    at FFmpeg.emit (events.js:315:20)
    at Socket.processError (/<pwd>/node_modules/prism-media/src/core/FFmpeg.js:65:40)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}
twlite commented 3 years ago

can you try using

seek: song.startTime,
encoderArgs: ['-t', song.endTime]
twlite commented 3 years ago

and weird, encoderArgs: ["-ss", "20", "-t", "50"] worked for me. Maybe something's wrong with your values

jamesdools commented 3 years ago

Thanks for the quick reply!

using a combo of seek & encoderArgs does the same. I should have mentioned also above, have tried both a duration with -t and an endTime with-to.

What happens is - it actually plays it in the voice channel with the correct start / stop time, but ffmpeg throws and error and it crashes immediately. The discordjs error event handlers aren't even triggered, and wrapping it in a try / catch doesn't stop it either..

Any thoughts? I was wondering if those arguments changes the readable stream into something ytdl-core doesn't handle.

Also am using ffmpeg version 4.0.2 on my machine.

twlite commented 3 years ago

Looks like the problem in prism-media I guess? 🤔

twlite commented 3 years ago

hm definitely a problem with prism-media imo coz I tested with prism-media only and same result ¯\(ツ)\

jamesdools commented 3 years ago

Thanks - that's interesting. Just curious as to why encoderArgs: ["-ss", "20", "-t", "50"] ran okay for you earlier though?

Are you using node-opus over @discordjs/opus or something like that?

Wondering if I can get on the same dependencies as you, maybe it'll play nice.

jamesdools commented 3 years ago

ps. If you're able to describe how you're testing it with prism-media directly, I can open an issue with them 🙂

twlite commented 3 years ago

Released: v5.0.2 #21