distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
206 stars 43 forks source link

video and audio have no sound #85

Open RyuGameDev opened 1 month ago

RyuGameDev commented 1 month ago

I'm trying to download video and audio for a YouTube link:

https://youtu.be/e4S6ijtD-VY?si=KELR72P5yWEMevyL

And what I get is video and audio that has no sound at all, and the file for audio is very large unlike usual, I'm already using the latest version but the problem it's the same

phucngo2 commented 1 month ago

I tested this video with v4.14.4 on my local environment, and everything works find...

Noted that Youtube separates the audio and video streams, did you use FFmpeg to combine them? https://github.com/fent/node-ytdl-core/blob/master/example/ffmpeg.js

RyuGameDev commented 1 month ago

I tested this video with v4.14.4 on my local environment, and everything works find...

Noted that Youtube separates the audio and video streams, did you use FFmpeg to combine them? https://github.com/fent/node-ytdl-core/blob/master/example/ffmpeg.js

no my code is like this

let vidid = await getYouTubeVideoId(text) let search = await yts({videoId: vidid}) const agentOptions = { pipelining: 5, maxRedirections: 0, }; const agent = ytdl.createAgent(cookiess, agentOptions);

let mp3file = ./${m.chat}.mp3 let nana = ytdl(ply,{agent}, { filter: 'audioonly' }) .pipe(fs.createWriteStream(mp3file)) .on('finish', async () => { Aira.sendMessage(m.chat, {audio: fs.readFileSync(mp3file), mimetype:'audio/mpeg', ptt:true }, {quoted: m}) Aira.sendMessage(m.chat, { document: fs.readFileSync(mp3file), fileName: search.title+'.mp3', mimetype: 'audio/mp3' }, { quoted: m }) })

phucngo2 commented 1 month ago

I tested this video with v4.14.4 on my local environment, and everything works find... Noted that Youtube separates the audio and video streams, did you use FFmpeg to combine them? https://github.com/fent/node-ytdl-core/blob/master/example/ffmpeg.js

no my code is like this

let vidid = await getYouTubeVideoId(text) let search = await yts({videoId: vidid}) const agentOptions = { pipelining: 5, maxRedirections: 0, }; const agent = ytdl.createAgent(cookiess, agentOptions);

let mp3file = ./${m.chat}.mp3 let nana = ytdl(ply,{agent}, { filter: 'audioonly' }) .pipe(fs.createWriteStream(mp3file)) .on('finish', async () => { Aira.sendMessage(m.chat, {audio: fs.readFileSync(mp3file), mimetype:'audio/mpeg', ptt:true }, {quoted: m}) Aira.sendMessage(m.chat, { document: fs.readFileSync(mp3file), fileName: search.title+'.mp3', mimetype: 'audio/mp3' }, { quoted: m }) })

You should put the agent and the filter into the same parameter object and the code will work:

let nana = ytdl(ply, {
  agent,
  filter: "audioonly", // Here
})
  .pipe(fs.createWriteStream(mp3file))
  .on("finish", async () => {
    Aira.sendMessage(
      m.chat,
      { audio: fs.readFileSync(mp3file), mimetype: "audio/mpeg", ptt: true },
      { quoted: m }
    );
    Aira.sendMessage(
      m.chat,
      {
        document: fs.readFileSync(mp3file),
        fileName: search.title + ".mp3",
        mimetype: "audio/mp3",
      },
      { quoted: m }
    );
  });