Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 653
vamsi Avatar asked Feb 10 '15 03:02

vamsi


1 Answers

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.

like image 92
G. Mass Avatar answered Oct 30 '22 20:10

G. Mass