Reputation: 67
my code snippet as below:
const express = require('express');
const app = express();
const ytdl = require('ytdl-core');
const fs = require('fs')
var router = express.Router();
router.get('/', function (req, res, next) {
console.log('rputer calld')
let url = "https://youtu.be/nD_NDngrEl8";
ytdl(url).pipe(fs.createWriteStream('./presentation/video.webm'));
res.end();
})
app.use(router);
app.listen(2222, () => {
console.log('app listingin on 2222')
})
I have used express server and put a youtube URL, which I wanted to download in its high quality.
Upvotes: 0
Views: 14584
Reputation: 1
just use the npm package "ytdl-max"
https://www.npmjs.com/package/ytdl-max
https://github.com/BrunoItacaramby/Youtube-Downloader
You just need to start coping the youtube links and it will download automatically, high quality videos, audio or lower quality videos!
Upvotes: 0
Reputation: 11
For your requirements "High Quality" you can use the filter function to return the video with the highest format
const video = ytdl(url, {
filter: function (format) {
return format.quality== "highest";
},
});
Or using the quality's itag which is a constant number for each quality (ex. for 720p itag = 22)
const iTag = 22;
const video = ytdl(url, {
filter: function (format) {
return format.itag === iTag;
},
});
Upvotes: 1
Reputation: 575
this is working perfect download video change ./presentation/video.webm to video.mp4
const express = require('express');
const app = express();
const ytdl = require('ytdl-core');
const fs = require('fs')
var router = express.Router();
router.get('/', function (req, res, next) {
console.log('rputer calld')
let url = "https://youtu.be/nD_NDngrEl8";
ytdl(url).pipe(fs.createWriteStream('video.mp4'));
res.end();
})
app.use(router);
app.listen(2222, () => {
console.log('app listingin on 2222')
})
Upvotes: 1
Reputation: 818
High-quality YouTube videos just don't have sound included. Generally, you have to download separate video and audio and mux the two files as you have said.
You want to mux the two files in real-time as they are downloading rather than at the end of downloading.
Well, FFmpeg can do that if you provide matching video and audio URLs from info. formats in place of downloaded filenames, you can then save the muxed output to file, pipe, or stream it to whatever or wherever. The time to completion will be much longer but you can theoretically start consuming the output immediately as if you were watching it on YouTube. But then, I suppose the question is, why not just watch it on YouTube?
Some Example:
FFmpeg with streams: https://github.com/fent/node-ytdl-core/blob/master/example/ffmpeg.js
Muxed stream: https://www.npmjs.com/package/ytdl-core-muxer
Upvotes: 2