To add on to answer: OP did not mention the video he was downloading had to be from YouTube. To_command_print=$(date -u "+%T" -d - $from_pre)))$(grep -o "\.*" <<< $3)Ĭommand+="-ss $from_pre_command_print -i $uri "Ĭommand+="-ss $from_command_print -to $to_command_print $4"Įcho "downloading with the following command:" I made a script implementing answer here #!/bin/bashįrom_pre_command_print=$(date -u "+%T" -d -u "+%T" -d - $from_pre)))$(grep -o "\.*" <<< $2)
We can also download only the initial part of the audio (2nd-URL) in a similar fashion (content-length would differ but total seconds would remain same).ĭownloading any middle portion from the video should also be possible in this way but is going probably way much trickier because YouTube places the metadata at the beginning of the stream (in the first few bytes) and without it being present in the downloaded media, the stream won't play at all.ĮDIT: This will only work on websites with resume support, say YouTube. The downloaded file should be able to play but best let FFmpeg fix the incorrect metadata: $ ffmpeg -i ten_secs.mp4 -c copy corrected_ten_secs.mp4 This should only download the first 10 secs. (we add one to also roughly account for extra space taken by metadata which is placed at the beginning of the stream)įor example to fetch approximately the first 10 seconds, you will need to fetch the first 260650 * 11 = 2867150 bytes, so we make a request with the Range header: $ curl "1st-URL" -H "Range: bytes=0-2867150" -o ten_secs.mp4 We multiply this value with (number of seconds we want to fetch from the beginning + 1) Now, we divide this total content length by total seconds in video (the YouTube video has a duration of 4 min and 7 secs which is 247 seconds.) to approximately get the content length of 1 second: Now send a head request to the first URL (which links to the video stream) to fetch the total content length of this stream: $ curl "1st-URL" -sI | grep Content-Length This should output two URLs (each for video and audio streams).
We first fetch the stream URLs: $ youtube-dl -g Since YouTube provides resume support, we could request for partial content using the Range header. This doesn't completely answer OP's question but there is way to download a stream from beginning to a specific duration without having to download the complete stream. # The first URLįfmpeg -ss 42:30 -i "$video_url" -ss 42:30 -i "$audio_url" -map 0:v -map 1:a -ss 30 -t 7:10 -c:v libx264 -c:a aac gog-vs-triv.mkvĬredit to Jakub Vrána for the -youtube-skip-dash-manifest solution. I'll then use map to map the video 0:v and audio 1:a (0 means first input, which is the video and 1 means the second input, which is the audio) and then choose my encoding options. I wanted to cut from 43:00 to 50:10 so I'm going to do -ss 42:30 (giving me a few seconds to catch a good keyframe) on both inputs and then do a -ss 30 after the inputs to start at 43:00.
Video youtube-dl -youtube-skip-dash-manifest -g Here's a real example using one of my youtube videos. I also recommend doing it about 30 seconds earlier and then using another -ss 30 to avoid losing any key frames. You'll need to use the -ss option for each stream. Press enter to confirm your selection when it asks.Use youtube-dl -youtube-skip-dash-manifest -g "URL" to get the video and audio streams. It will show a huge list of packages to be installed. When you type the password, nothing is displayed on the screen. When you enter the command, you’ll be asked to enter your password.
#UBUNTU DOWNLOAD YOUTUBE INSTALL#
You may want to update the package cache if you are not running Ubuntu (Ubuntu does it automatically): sudo apt updateĪnd then you can install it in Ubuntu default edition using this command: sudo apt install ubuntu-restricted-extras Since ubuntu-restrcited-extras package is available in the multiverse repository, you should verify that the multiverse repository is enabled on your system: sudo add-apt-repository multiverse Open a terminal in Ubuntu by searching for it in the menu or using the terminal keyboard shortcut Ctrl+Alt+T. In any case, you can install the package using command line and it’s very simple.
#UBUNTU DOWNLOAD YOUTUBE SOFTWARE#
I find it surprising that the software center doesn’t list Ubuntu Restricted Extras.