javascript - How can I play an audio file while converting it with ffmpeg in Node.js? -
i created simple video-to-audio converter ffmpeg discord.js bot:
let stream = //an mp4 stream ffmpeg(stream) .toformat("mp3") .stream(fs.createwritestream("./audio.mp3")) .on("end", () => { connection.playstream(fs.createreadstream("./audio.mp3")) });
this works fine, using .on() play file - after finishes converting - can take while.
is there efficient way use connection.playstream play audio file or stream ffmpeg conversion still happening?
i ended seeing this question , used growing-file module stream file being converted. here's general idea:
const writestream = fs.createwritestream("./audio.mp3"); const stream = //mp4 stream ffmpeg(stream) .toformat("mp3") .pipe(writestream); const file = growingfile.open("./audio.mp3"); connection.playstream(file);
the downside still forced download stream mp3 file, while prefer skip step , use connection.playstream
play ffmpeg's pipe
.
if has idea of how skip mp3 download , stream/pipe connection.playstream, appreciated!
Comments
Post a Comment