node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

Playable partial stream

Open gooca opened this issue 7 years ago • 8 comments

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?

gooca avatar Aug 30 '18 15:08 gooca

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)

fent avatar Sep 02 '18 03:09 fent

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?

gooca avatar Sep 03 '18 21:09 gooca

Should be possible as youtube does exactly that right? With buffering starting at a specific time?

DapperMickie avatar Sep 03 '18 22:09 DapperMickie

There's begin but it's not very reliable. We might want to investigate this a bit more and see how Youtube does this.

fent avatar Sep 04 '18 00:09 fent

Hello @fent ! Do you still plan on working on an improved start / end feature ?

michael-dm avatar Sep 01 '20 21:09 michael-dm

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.

fent avatar Sep 01 '20 23:09 fent

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.

redbrain avatar Dec 11 '20 14:12 redbrain

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.

Edqe14 avatar Jan 19 '21 02:01 Edqe14