Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Somtimes ffmpeg process is not finished. #194

Open
cjh980402 opened this issue Aug 28, 2021 · 8 comments
Open

Somtimes ffmpeg process is not finished. #194

cjh980402 opened this issue Aug 28, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@cjh980402
Copy link

cjh980402 commented Aug 28, 2021

ubuntu     33024   33017  7  8월26 ?      04:34:36 /home/ubuntu/.nvm/versions/node/v16.6.2/bin/node /home/ubuntu/bot/index.js
ubuntu     36962   33024  0  8월26 ?      00:00:01 /home/ubuntu/bot/node_modules/ffmpeg-static/ffmpeg -i - -analyzeduration 0 -loglevel 0 -f s16le -ar 48000 -ac 2 pipe:1
ubuntu     37297   33024  0  8월27 ?      00:00:00 /home/ubuntu/bot/node_modules/ffmpeg-static/ffmpeg -i - -analyzeduration 0 -loglevel 0 -f s16le -ar 48000 -ac 2 pipe:1
ubuntu     44057   33024  0  8월27 ?      00:00:01 /home/ubuntu/bot/node_modules/ffmpeg-static/ffmpeg -i - -analyzeduration 0 -loglevel 0 -f s16le -ar 48000 -ac 2 pipe:1
ubuntu     56265   33024  0  8월28 ?      00:00:03 python /home/ubuntu/bot/node_modules/youtube-dl-exec/bin/youtube-dl https://www.youtube.com/watch?v=PUSkqc1amgI -o - -q -f bestaudio[
ubuntu     56268   33024  0  8월28 ?      00:00:20 /home/ubuntu/bot/node_modules/ffmpeg-static/ffmpeg -i - -analyzeduration 0 -loglevel 0 -f s16le -ar 48000 -ac 2 pipe:1

Even if 3 songs are finished, 3 ffmpeg processes are not ended. Is there any solution?

Further details:

  • @discordjs/voice version: 0.6.0
  • Node.js version: 16.6.2
  • Operating system: ubuntu 20.04
  • Priority this issue should have – please be realistic and elaborate if possible:
  • Sometimes the ffmpeg process remains even when the song ends normally. In the above process log, the three ffmpeg processes above correspond to this problem.
@cjh980402 cjh980402 added the bug Something isn't working label Aug 28, 2021
@amishshah
Copy link
Member

Please post code that can reproduce this situation

@cjh980402
Copy link
Author

cjh980402 commented Aug 29, 2021

// create AudioResource
async function songDownload(url) {
    const ytdlProcess = ytdl(
        url,
        {
            o: '-',
            q: '',
            f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio',
            r: '100K'
        },
        { stdio: ['ignore', 'pipe', 'ignore'] }
    );

    const stream = ytdlProcess.stdout;
    if (!stream) {
        throw new Error('no stdout');
    }

    const onError = () => {
        if (!ytdlProcess.killed) {
            ytdlProcess.kill();
        }
        stream.resume();
    };
    ytdlProcess.on('error', onError);

    try {
        const probe = await demuxProbe(stream);
        return createAudioResource(probe.stream, { inputType: probe.type, inlineVolume: true });
    } catch (err) {
        onError();
        throw err;
    }
};

// play the song
try {
    player.play(await songDownload(songs[0].url));
    player.state.resource.volume.setVolume(volume / 100);
} catch {
    sendMessage('failed to play song');
    songs.shift();
    return;
}

@iim-ayush
Copy link
Contributor

Just a recommendation, you can switch to play-dl. Play-dl doesn't require ffmpeg in normal streams.

@cjh980402
Copy link
Author

Thanks for your recommendation. However, I think that ffmpeg used by discordjs/voice module (https://github.com/discordjs/voice/blob/main/src/audio/TransformerGraph.ts)

@iim-ayush
Copy link
Contributor

Thanks for your recommendation. However, I think that ffmpeg used by discordjs/voice module (https://github.com/discordjs/voice/blob/main/src/audio/TransformerGraph.ts)

Can you test again with using this script running in a different ubuntu session after the 1st song has been completed ??

#!/bin/bash

# Check if ffmpeg is running
# -x flag only match processes whose name (or command line if -f is
# specified) exactly match the pattern. 

if pgrep -x "ffmpeg" > /dev/null
then
    echo "Running"
else
    echo "Stopped"
fi

@cjh980402
Copy link
Author

I will check if there is a bug that corresponds to this issue. Thanks!

@cjh980402
Copy link
Author

Even if all song is finished, result of that script is Running

@iim-ayush
Copy link
Contributor

iim-ayush commented Aug 30, 2021

That only means ffmpeg instance is not deleted.

@amishshah

Maybe this is the reason of #164 [ Memory Leak ] .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants