vamsi
vamsi

Reputation: 2995

Download part of the youtube video using python

Is it possible to download part of the youtube video?

Ex: out of 6 min length video, download only first 2 min or any time frame ?

Upvotes: 6

Views: 10721

Answers (1)

G. Mass
G. Mass

Reputation: 83

This workaround might answer your question for now: https://github.com/rg3/youtube-dl/issues/622#issuecomment-320962680

  1. Extract the url with youtube-dl -g
  2. Use sed to prepends -ss STARTTIME -i to each line of output from youtube-dl -g
  3. Set duration using the ffmpeg argument -t
  4. Set the codec output to copy using -c copy

For example:

ffmpeg $(youtube-dl -g 'https://www.youtube.com/watch?v=NnW5EjwtE2U' | sed "s/.*/-ss 10 -i &/") -t 60 -c copy test3.mkv

To get from 00:10 to 01:10 of this week's Last Week Tonight segment.

Upvotes: 8

Related Questions