youtube-dl: can I download only a portion of the video?
I would like to download only part of a video with youtube-dl, but can't figure out how from the man page. There is that section "Video Selection," but it seems to concern only downloading entire videos within a playlist. I want or more sections within one video. (If I mayy download only one at a time, no problem.) It sounds like something that should be possible...
I habitually download the audio from Youtube videos of services at my church (that is, I youtube-dl -x them); and the only way I know how to separate parts of the audio is to tediously work on it in Audacity. It would save a good lot of time if I could download only the parts I wanted. |
You can do that in multiple ways.
Let me get an example, dogs barking. (You did say audio.) Code:
yt-dlp -F https://m.youtube.com/watch?v=muAiqLbblVQ From 00:01:00 to 00:01:20 in the audio Code:
url=$(yt-dlp -g -f 140 https://m.youtube.com/watch?v=muAiqLbblVQ) |
And of course, I would script that.
Basic example: Code:
#!/usr/bin/bash |
The key thing to point out in the above is that "-g" is short for "--get-url" - i.e. the above is using youtube-dl (or yt-dlp) to retrieve the URL of the video/audio file, then using ffmpeg to do the actual downloading.
Also, if the order of the arguments is correct (i.e. the offset and duration come before the URL), ffmpeg will only download the relevant section, but with incorrect argument ordering it will download the full thing first. According to the youtube-dl help, it should be possible to do all this with a single command via "--external-downloader=ffmpeg" and "--external-downloader-args='-ss 00:01:00 -t 00:00:20'", but in the quick test I did, youtube-dl seems to ignore them and download too much (but is still parsing the args because it errors if they're incorrect). |
Just a quick thought (no research done): can youtube-dl or yt-dlp be configured to respect the &t= part of a youtube url?
E.g. https://youtube.com/watch?v=muAiqLbblVQ&t=60 would be 1 minute into the video. |
I never thought of that.
Lets see... Code:
yt-dlp -f 140 "https://youtube.com/watch?v=muAiqLbblVQ&t=10" -o test1.m4a It's hard to beat ffmpeg for video/audio manipulation. ffmpeg is my first goto for that. The problem that the @OP will have is, you'll have to know where the breaks that you want are before you start to download the segments. So you'll have to get the whole audio to start with anyway. Unless you have some kind of notes on the video because you were there when it was made. Otherwise, I don't see how one could know where the segments should start/stop. And if you are playing it over and over to determine that, you'll use more bandwidth than if you downloaded it once, and then worked on that local file. You can make a script easy enough to get time stamps for where it should be cut. Play the local video once and mark it while you play it. Example: There was a sitcom that I caught from TV tuner to file, overnight. My machine awakened, caught the video, went back to sleep. And that gave me a 34 min long transport stream. mpeg2 video, ac3 audio. It had 4 segments that I wanted to keep, and get rid of the commercial breaks. First thing that I wanted was to run it through ffmpeg to make a mp4 out of the transport stream so that it had an accurate time base for ffmpeg to work with. A transport stream does not, there is no way to cut a video on time stamps with a file.ts, because it doesn't have one. I wanted to be able to play the video quickly and mark the start and stop of the segments that I wanted to keep, cut them out with ffmpeg into separate files, then put all of them together in to one video. Done. Here are a few snippets of it. Make a mp4 out of it if wanted. Code:
read -p "Enter/Paste file.ts for editing :" vid Code:
vid="MyVideo.mp4" Code:
echo "${tstamp[@]}" Code:
#Loop through array and use ffmpeg to make video segments. Code:
#Put the segments together. Code:
ffprobe Tv_finished.mp4 |
Yeah I guess it always downloads the whole video first, no matter what.
Analog to what boughtonp suggested, you could also try --postprocessor-args (this from 'man yt-dlp'). |
All times are GMT -5. The time now is 05:05 PM. |