Laboratorium Komputerowe Progmar

We are using cookies in the page. If you use the page you agree for the cookies.      Close

Downloading video from Youtube in Ubuntu

First install needed programmes: sudo apt-get install mplayer2 ffmpeg Make sure that you have youtube-dl programm in the newest version: sudo apt-get remove -y youtube-dl
sudo wget -O /usr/local/bin/youtube-dl
sudo chmod a+x /usr/local/bin/youtube-dl
hash -r

If following command: youtube-dl -g "" outputs error: ERROR: Signature extraction failed, then probably you haven't the youtube-dl in the latest version. If you have, then the video file could not be downloaded from Youtube (until the author applies needed changes to the programm to support last changes in Youtube service).

Now in /usr/local/bin directory create a file with following content:


rm -rf video.url
rm -rf audio.url

for url in $(youtube-dl -g "$1"); do
    if [ ! -r ]; then
        echo $url > video.url
        cat video.url | xargs curl -L >
    if [ ! -r ]; then
        echo $url > audio.url
        cat audio.url | xargs curl -L >

ffmpeg -i -i -vcodec copy -acodec copy "$"
if [ -r "$" ]; then
    rm -rf video.url
    rm -rf audio.url

ls -al

Change the file attributes to grant execute privileges: sudo chmod 755 /usr/local/bin/

From now you can download the film by issuing command: youtube_video_code The script downloads a film in two separate files: video and audio. After download finishes they are mixed together into a single audio-video file.

The script sometimes returns error: moov atom not found Invalid data found when processing input
This means that one of files mentioned above or both of them are not successfully downloaded. In that case try download them again. In most cases it finishes with success. If you try to download film a few times and you always end with failure then the film can't be downloaded. In the case you have in current directory files,, audio.url and video.url, which you can investigate to get know what is the reason of the failure.

Downloading video from other services in Ubuntu

Install required programme: sudo apt-get install mplayer2 If a video file is served by http protocol, you can download it with command below: mplayer http://url-of-page-containing-video -dumpstream -dumpfile output-filename.flv

In order you to feel comfortable, below there is a short script for downloading videos. You can save it and execute with one parameter - full url of the page containing video. It extracts last part of the url and transforms it into output filename. If the file does not exist in current directory then the file will be downloaded:



if [ ! -r "./$fname" ]; then
    mplayer $url -dumpstream -dumpfile $fname