node-ytdl-core
node-ytdl-core copied to clipboard
Playable partial stream
Is it possible to use ffmpeg with ytdl-core to stream only a certain part of a video? Like if I'm trying to download 30 seconds in the middle of an hour long video, would this be possible?
Yeah, just pass the stream to ffmpeg. I've used the following modules before
https://www.npmjs.com/package/fluent-ffmpeg (see seekInput() and duration()
https://www.npmjs.com/package/ffmpeg-binaries (using the -ss and -t arguments)
Currently I'm running
const fs = require('fs');
const ytdl = require('ytdl-core');
const ffmpeg = require('fluent-ffmpeg');
url = videoID = "6YNZlXfW6Ho"
outStream = fs.createWriteStream('video.webm');
ffmpeg().input(
ytdl(url, {filter: function(format) {
if( format.container == 'webm' && format.resolution === null){return format}
}})
)
.format('webm')
.seekInput(120)
.duration(3)
.pipe(outStream);
to get the 3 seconds of audio in the middle of a song. However, it is taking longer than I would hope to download 3 seconds of audio, is the code downloading the entire song and then cutting it with ffmpeg? If so, would there be any way to only get exactly what I need/ download more efficiently?
Should be possible as youtube does exactly that right? With buffering starting at a specific time?
There's begin but it's not very reliable. We might want to investigate this a bit more and see how Youtube does this.
Hello @fent ! Do you still plan on working on an improved start / end feature ?
yes but I currently don't have much free time to put into open source. so it'll be a while before i look into it.
I've looked for how other scrapers do this; it seems they all download it fully and cut it later with ffmpeg or the equivalent.
I couldn't find much on YouTube's begin and it seemed weird to try to use; probably just not very consistent.
Please talk to me in Discord if you have experience/information with any of that; I have some time now so I can attempt a PR.
I found a project called youtube-dl and it can download partial content using Range header when requesting to the video url. From this, maybe you can calculate the byte range and use it to get partial content.