Playing With Youtube Videos in Linux

In this short post I’ll introduce a csh script I wrote recently. I wrote it for a certain purpose and it’s definitely not “general purpose”. I’m posting it here so you/I can use it as a reference.

The script uses these programs:

1. youtube-dl    (In ubuntu, you can get it by typing : sudo apt-get install youtube-dl).

2. ffmpeg   (Again: sudo apt-get install ffmpeg)

3. avimerge (part of the transcode package: sudo apt-get install transcode)

The script will download videos from youtube, convert them into avi files, and finally merge them into one avi video.

To use the script, you need call it from inside a directory with only one file in it: file name needs to be “links” and it should include the URLs of the videos you want to download from youtube, one URL per line, in the order you want them to appear in the merged video. The output will be a file “all.avi” in the same directory. Of course, you’re free to modify this script to let be more flexible etc…

Here is the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/tcsh

# download movies
set x = 1
foreach line (`cat links`)
        youtube-dl -o vid$x.flv "$line"
        @ x = $x + 1
end

# convert from flv to avi
foreach file ( *.flv )
        ffmpeg -i "$file" -ab 56 -ar 22050 -b 500 -s 320x240 -vcodec copy -acodec copy "$file".avi
end

# merge all avi files into one file
avimerge -i *.avi -o all.avi

# remove intermediate files
/bin/rm vid*.avi vid*.flv

Please ignore the “BASH” title of the script, it’s because GeSHi doesn’t support csh, and as far as I know bash is the closest thing to csh

Hope it helps somebody :)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: , ,

Monday, January 26th, 2009 Shell Scripts

2 Comments to Playing With Youtube Videos in Linux

  • Zach says:

    I got this when running it (the first error happens a few times before also):

    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    ffmpeg: missing argument for option ‘-vcodec’
    [AmirWatad: Log removed. Please don't post Long Error Logs in comments]

  • Amir Watad says:

    Strange, it works fine for me. Please share the solution with us if you find it.

  • Leave a Reply

    my email
    my photo
    Hi,
    My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
    I'm a Verification Engineer in Mellanox Technologies Ltd.
    I love Linux, the Command Line and the OpenSource Community.
    I used to write Poems (Arabic) when I was able to find time for this.
    January 2009
    S M T W T F S
    « Dec   Feb »
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
    SEO Powered by Platinum SEO from Techblissonline

    Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.