I am using Ubuntu, and youtube-dl command is working absolutely fine.
I want to download only portion the video that is too long. So I want to download only few minutes portion of the video. Example from 13 minutes to 17 minutes.
After that the video will be processed and you be presented with a Download Link, Just use that link to download the video and you have just downloaded the specific part of that video. ClipConverter also has various other options you can just play around with them for fun, I have not mentioned those as those things are not related here. However, there are problems that arise when you only need to download and/convert a specific part of videos. Usually, you need to download full video and then you can just edit the specific part of it that you want. With that, you will need a site that allows you to download and edit video. How to convert Specific parts of Youtube video.
Is there any way to do that
7 Answers
I don't believe youtube-dl
alone will do what you want. However you can combine it with a command line utility like ffmpeg.
First acquire the actual URL using youtube-dl:
Copy the output of the command and paste it as part of the -i
parameter of the next command:
The -ss
parameter in this position states to discard all input up until 15 seconds into the video. The -t
option states to capture for 10 seconds. The rest of the command tells it to store as an mp4.
ffmpeg is a popular tool and should be in any of the popular OS repositories/package managers.
This feature request is not yet implemented in youtube-dl. See #622 issue and many duplicates of it on github.
Adding to Johnnie's answer:
Use youtube-dl -g 'URL'
to get the video and audio streams.
Now use:
You'll need to use the -ss
option for each stream. I also recommend doing it about 30 seconds earlier and then using another -ss 30
to avoid losing any key frames. Here's a real example using one of my youtube videos.
Output:
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.
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.
youtube-dl
supports passing arguments to the underlying postprocessor (tested with version 2017.08.27.1):
youtube-dl -x --postprocessor-args '-ss 00:13:00.00 -t 00:04:00.00' https://youtu.be/...
This is basically the same as doing the postprocessing with ffmpeg
yourself after downloading the file first.
You can download from the start up to a point without downloading the whole thing and editing. That's half of what this question asks:
interrupt the download with ^C
- I've only tried this with
mp4
- won't work with separate video and audio, you need a format with both. By default ytdl often gets separate video and audio, then merges them. Use
-F
to see the formats available, and choose anmp4
that has both. e.g.-f18
or-f22
are usually there. - you'll have to estimate from percentage downloaded (which isn't linear; the compression rate varies over time).
Yes. It's a hack.
Further question: if you do want the separate video and audio formats, could you download part of each separately (using ^c
as here), and then merge them manually? I don't think it willl work for some formats.
![Download Download](https://static.makeuseof.com/wp-content/uploads/2011/05/play-part-of-video-youtube.jpg)
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. Since YouTube provides resume support, we could request for partial content using the Range
header.
We first fetch the stream URLs:
This should output two URLs (each for video and audio streams).
Now send a head request to the first URL (which links to the video stream) to fetch the total content length of this stream:
Now, we divide this total content length by total seconds in video (the YouTube video has a duration of 4 min and 7 secs which is 247 seconds.) to approximately get the content length of 1 second:
64380504 / 247 ≈ 260650
We multiply this value with (number of seconds we want to fetch from the beginning + 1)
(we add one to also roughly account for extra space taken by metadata which is placed at the beginning of the stream)
For example to fetch approximately the first 10 seconds, you will need to fetch the first 260650 * 11 = 2867150
bytes, so we make a request with the Range
header:
This should only download the first 10 secs. The downloaded file should be able to play but best let FFmpeg fix the incorrect metadata:
We can also download only the initial part of the audio (2nd-URL) in a similar fashion (content-length would differ but total seconds would remain same).
Downloading any middle portion from the video should also be possible in this way but is going probably way much trickier because YouTube places the metadata at the beginning of the stream (in the first few bytes) and without it being present in the downloaded media, the stream won't play at all.
EDIT: This will only work on websites with resume support, say YouTube. It won't work for other websites.