Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg stream unpipes around 20 seconds before end of audio file #10

Closed
mbilker opened this issue May 27, 2016 · 13 comments
Closed

FFmpeg stream unpipes around 20 seconds before end of audio file #10

mbilker opened this issue May 27, 2016 · 13 comments

Comments

@mbilker
Copy link

mbilker commented May 27, 2016

YouTube does not always have an Opus audio file available and any other format I pass to Discordie's FFmpegEncoder. This has been happening recently after some of the SIGTERM and SIGKILL changes were implemented, but I am uncertain if this issue is caused by those changes.

I noticed that the stream never fires an unpipe or end event. The timestamp shows the audio file stopped around 8 seconds from the end of the audio file for a full-length song (approx. 3 minutes).

I am still investigating the cause of this. Turning on FFmpegEncoder's debug does not show an error, but I may need to increase the log verbosity.

@mbilker
Copy link
Author

mbilker commented May 27, 2016

For more information, the encoder initialization is:

      this.encoder = voiceConnection.createExternalEncoder({
        type: 'ffmpeg',
        source: this.url,
        format: 'opus',
        outputArgs: ['-ab', '64000'],
        debug: true,
      });

@mbilker
Copy link
Author

mbilker commented May 27, 2016

@mbilker
Copy link
Author

mbilker commented May 27, 2016

Found some log output:

  cardinal:queue QUEUE_ITEM +53s https://www.youtube.com/watch?v=-tRdBsnX4N4
  cardinal:queue fetchYoutubeInfo promise resolve +1s
  cardinal:queue handleQueued +4ms

  cardinal:queued-media stopPlaying +3m -HsOQFVeiGE vorbis
  cardinal:queued-media encoder unpipe +1ms -HsOQFVeiGE vorbis
  cardinal:queued-media stream unpipe +0ms -HsOQFVeiGE vorbis

I discovered I forgot to track when the stream from encoder.play() fires its end event.

@qeled
Copy link
Owner

qeled commented May 28, 2016

How often does that happen?
This may be caused by Discord servers disconnecting you (though it will stay in the channel and autoreconnect if it's just a server change), thus why the library could be cleaning up all resources without firing an end event.
Adding a VOICE_DISCONNECTED handler would clear the case up a bit.

Also for debugging stuff like this I'd additionally recommend logging all library events using Dispatcher.onAny or in case of regular event emitters just hooking the emit method.

@mbilker
Copy link
Author

mbilker commented May 28, 2016

It happens with every non-Opus passthrough song. I am going to debug this with the methods you provided. Thanks for the quick response!

@mbilker
Copy link
Author

mbilker commented May 28, 2016

Okay tested it out on https://www.youtube.com/watch?v=rGd7IEOjk-0

It stopped at 2:41 out of 2:48. No disconnect event fired.

EDIT: Classify the event better.

@mbilker
Copy link
Author

mbilker commented May 28, 2016

I screwed up my logging comment from before. I am sorry. The song never ends, but the timestamp stops updating. I had to manually trigger the unpipe.

EDIT: Updated issue post with more accurate information.

@qeled
Copy link
Owner

qeled commented May 28, 2016

Seems to be an issue with stream behavior changes in newer nodejs versions, can consistently reproduce on v5.11.0+.

@qeled
Copy link
Owner

qeled commented May 28, 2016

This commit seems to be a part of the issue: nodejs/node#6023.

v5.11.0:

spawned: 16340
:: STDOUT :: resume
:: PROCESS :: exit
:: STDOUT :: resume

v5.11.0 with commit rolled back:

spawned: 14756
:: STDOUT :: resume
:: PROCESS :: exit
:: STDOUT :: resume
:: STDOUT :: _socketEnd
stdout end
:: STDOUT :: end
:: STDOUT :: prefinish
:: STDOUT :: finish
process exited with code 0
:: PROCESS :: close
:: STDOUT :: close

@qeled
Copy link
Owner

qeled commented May 28, 2016

Pushed a workaround a7de2f4 to dev branch, will push to master and npm if that fixes it.

Doesn't fix the actual source of the bug, but it seems too deep for me to hunt it down and keeps only happening with ffmpeg processes, things like cat close cleanly.

@mbilker
Copy link
Author

mbilker commented May 29, 2016

Thanks for the investigation. I did upgrade my Arch system between restarts of my bot, and I wasn't playing a lot of non-Opus songs so I never noticed.

@mbilker
Copy link
Author

mbilker commented May 29, 2016

Testing now

@mbilker
Copy link
Author

mbilker commented May 29, 2016

Yep that fixes it! I know it is a hack, but thank you for figuring it out.

@mbilker mbilker closed this as completed May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants