How to download a portion of a video with youtube-dl OR something else?

Solution 1:

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:

  1. -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)
  2. -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...

References:

  • youtube-dl Download Range: Great discussion of the possibilities, some a little misguided :)
  • FFmpeg: Seeking A solid outline of seeking, cutting and the correct time unit syntax

Solution 2:

Use the --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 ffmpeg with 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

Examples:

  • 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]'
    

PS: youtube-dl will download the entire media before processing it, and will remove it after.