I'd like to be able to download a portion of a video only. For example, being able to specify a start and/or end time for downloading. So, when a user inputs a start and end time of a video, it should only download the portion of the clip within the time stamps. Would this be possible?
There is indeed a plethora of techniques available online to accomplish this. One fairly basic technique is the following one liner which works well enough on my system with a YouTube clip:
ffmpeg -i $(youtube-dl -f 18 --get-url https://www.youtube.com/watch?v=ZbZSe6N_BXs) \ -ss 00:00:10 -t 00:00:30 -c:v copy -c:a copy \ happy.mp4
The 2 sections which govern the clip start and end in this example are:
- -ss 00:00:10: Placed after the input file this encodes and discards samples up until the 10 second mark. This is slower and less efficient than placing the seek options before the input file (input seeking) but works better in this example (in particular when copying audio and video streams)
- -t 00:00:30: This specifies the duration of the encode, in this case 30 seconds only
I have tested this extensively with YouTube and all works well on my own system...
--postprocessor-args parameter to pass the audio/video output to
ffmpeg to be edited (the processor). Apparently,
ffmpeg is needed to be installed.
--postprocessor-args takes 3 arguments & values (this is just an example, check manual page of
man ffmpeg for more):
-ss HH:MM:SS: start time to take
-to HH:MM:SS: end time
-t HH:MM:SS: time length to take
Start encoding at 15 seconds and stop at 1 minutes 20 seconds:
$ youtube-dl --postprocessor-args "-ss 0:0:15 -to 0:1:20" '[video_URL]'
Start encoding at 15 seconds and take only the next 3 minutes 5 seconds:
$ youtube-dl --postprocessor-args "-ss 0:0:15 -t 0:3:5" '[video_URL]'
youtube-dl will download the entire media before processing it, and will remove it after.
The plumber tool allows you to do this easily. Install the application with:
snap install plumber
After installation, it will appear in your applications menu.
When you run the application, paste your desired youtube link in the box (highlighted in red in the screenshot below), or use the built-in youtube search feature, by clicking the youtube icon (highlighted in yellow).
I followed andrew.46's answer. However, you'd like to put
-i for proper seeking. Otherwise, you'll download more than you want.
-t specifies duration and
-to specifies the output point; be careful as they are different)
In the manual of ffmpeg, we are told to use
-i. However, based on my experience with ffmpeg,
-to does not work after
-i; it will be recognized as
My example command is: (to download the cart sliding part of "Coffee Run")
ffmpeg -ss 00:00:37 -to 00:00:44 -i "$(youtube-dl -f best --get-url 'https://youtu.be/PVGeM40dABA')" -c:v copy -c:a copy coffee_sliding.mp4