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

videoyoutube-dl

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?

Best Answer

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: