

Now send a head request to the first URL (which links to the video stream) to fetch the total content length of this stream: $ curl "1st-URL" -sI | grep Content-Length This should output two URLs (each for video and audio streams). We first fetch the stream URLs: $ youtube-dl -g Since YouTube provides resume support, we could request for partial content using the Range header. This doesn't completely answer OP's question but there is way to download a stream from beginning to a specific duration without having to download the complete stream. #Arguments: URL, Time stamp -5 seconds, length of clip, video file name I've moved from youtube-dl to yt-dlp for reasons that aren't super important for this post, but you can replace yt-dlp with youtube-dl if you want to continue using it. # The first URLįfmpeg -ss 42:30 -i "$video_url" -ss 42:30 -i "$audio_url" -map 0:v -map 1:a -ss 30 -t 7:10 -c:v libx264 -c:a aac gog-vs-triv.mkvĬredit to Jakub Vrána for the -youtube-skip-dash-manifest solution.ĮDIT: I do this so often I've created a script that I will include here. I'll then use map to map the video 0:v and audio 1:a (0 means first input, which is the video and 1 means the second input, which is the audio) and then choose my encoding options.

I wanted to cut from 43:00 to 50:10 so I'm going to do -ss 42:30 (giving me a few seconds to catch a good keyframe) on both inputs and then do a -ss 30 after the inputs to start at 43:00. Video youtube-dl -youtube-skip-dash-manifest -g Here's a real example using one of my youtube videos.

I also recommend doing it about 30 seconds earlier and then using another -ss 30 to avoid losing any key frames. You'll need to use the -ss option for each stream. Use youtube-dl -youtube-skip-dash-manifest -g "URL" to get the video and audio streams.
