Sunday, March 4, 2012

How To Download Youtube Videos in Linux in Desired Format

What say? 
In this tutorial I will show you how you can download Youtube videos in your desired format, batch download videos from a file, or extract the audio only from the downloaded video in Linux (Ubuntu, Fedora Arch Linux etc).

As everyone knows Youtube is the largest source of online videos in the world. There are many Youtube Video downloaders available in Windows platform, but most of them don't work or are slow or require you to pay for downloading videos. Today I will show how you can download a Youtube  video  in  your  Linux  machine  for free also in desired format using a open source software known as youtube-dl. This will work on all popular Linux distros such as Ubuntu, Fedora, Arch Linux, Linux Mint etc.

Sesmoweb.com offers relaible hostins solutions starting at $4.95 per month. With it you will get 99.9% uptime gurantee, great customer support and more. Great offer for our readers. Get a semoweb coupon and with semoweb coupon code and semoweb promo code, you will get great discounts at sesmoweb hosting.

Installing youtube-dl

Check your distro's repositories if youtube-dl is available there. For Debian based distros such as Ubuntu or Linux Mint, you can use the following command.

sudo apt-get install youtube-dl

For RPM based
sudo yum install youtube-dl

Arch Linux users can use pacman to install it as follows

sudo pacman -S youtube-dl

You can also compile from source by downloading it from this page.

Using youtube-dl : Downloading videos, Pausing and Resuming downloads

To download a video, go to youtube.com and search the video you want to download. Open the video page and copy the URL from the address bar as shown below.

Copying Youtube URL
Make sure you have installed youtube-dl using the above steps. Issue the following command to start downloading the video

youtube-dl <video URL>

eg. if the video URL is http://www.youtube.com/watch?v=Yc0CVEuUvRs, type

youtube-dl http://www.youtube.com/watch?v=Yc0CVEuUvRs

You will see some information as shown in the screenshot below, after which the video will start downloading and you will see the current speed and time remaining.

Downloading Youtube videos using youtube-dl
To pause or cancel the download, use Control-C. You can resume downloading the video using the following command

youtube-dl -c <video URL>

Batch Downloading Youtube Videos from a file

You can also write URLs of the videos in a file to be downloaded and issue a single command to download it at once. To do that, search all the videos you want to download and copy paste the URLs in a text file, each URL in a separate line. Then issue this command to download all the videos at once. This is especially useful if you want to download a lot of videos and don't have time enough to issue the command separately.

youtube-dl -a filename.txt

Where filename.txt is the file where the video URLs are saved.

Batch Download Youtube videos from a file -youtube-dl

Downloading Youtube videos in Preferred format

Often it may happen that you may want to download a video in a format different from the default one, or in a different resolution. To know what format a video is availiable, use the following command.

youtube-dl -F <video URL>

Make sure you typed capital F. It will display the formats and resolutions the video is available in and their specific code in the first column.

Download video in a different format - youtube-dl
To download the file in your preferred format, type

youtube-dl -f <format code> <video url>

Eg. I want to download the file in .flv format with resolution 240x400, so I use this command

youtube-dl -f 5 http://www.youtube.com/watch?v=Yc0CVEuUvRs

The lower the resolution, the smaller will be the size of the file hence will save your data usage. By default, youtube-dl downloads the file in the best quality format.

Extracting Audio of Youtube Videos

If you just want the audio of the youtube video, you can issue this command to get it.

youtube-dl <video URL> --extract-audio

This will extract the audio in best format available. You can also specify your preferred format such as .mp3 as follows:

youtube-dl <video URL> --audio-format mp3

To specify the quality or bit-rate of the audio

youtube-dl <video URL> --audio-quality 256k

The default is 128kbps. If you want to keep the video file too after the audio has been extracted, you can use the -k option. Hence all together to download my video http://www.youtube.com/watch?v=Yc0CVEuUvRs and extract the audio in mp3 format with a bitrate of 176kbps and keep the video, I use:

youtube-dl http://www.youtube.com/watch?v=Yc0CVEuUvRs --audio-format mp3 --audio-quality 176 -k

For more options, type
 youtube-dl -h
Disclaimer: This is an affiliate post. Learn why?
 

--Saurav Modak
Liked it? Please consider +1 it below.
Help Freedom Grow. Subscribe to our RSS Feeds and Like Us in Facebook. Also you can leave a comment below.


9 comments:

  1. cool! This was the only method that actually worked!

    ReplyDelete
  2. Thanks! Works great. FYI: as of right now (01-28-2013) there is a problem. Youtube changed something to make it incompatible with youtube-dl, it's been fixed in the latest version. According to this post http://leeunderwood.org/r/07 you will need to do the following to update youtube-dl until the package system gets the updated version (i.e., you will need to do it a few times):

    sudo youtube-dl -U

    ReplyDelete
  3. Thank a lot it worked perfectly

    ReplyDelete
  4. But I receive error message...
    Unable to download video

    ReplyDelete
  5. Not Working :
    [youtube] Setting language
    [youtube] Yc0CVEuUvRs: Downloading video info webpage
    [youtube] Yc0CVEuUvRs: Extracting video information
    ERROR: format not available for video

    ReplyDelete
    Replies
    1. Make sure you provided the correct format code

      Delete

Thanks a lot for commenting. You can also subscribe to our RSS Feeds and Like Us in Facebook Follow Me on Twitter

Related Posts Plugin for WordPress, Blogger...

ShareThis