Downloading and Converting YouTube Videos for Mobile Phones

Viewing, Downloading, Converting YouTube Video Files


Youtube is one the popular social networking website , but unlike Google Videos which include link for downloading videos Youtube provides no such link here in this article we try to look at ways of downloading videos on to hard disk , Playing them and converting them to a format suitable for them to be played on Mobile Phones . All these would be done underLinux.

Tools needed : -
For converting video from FLV format to 3GP (To be used to be played on mobile phones) following tools are needed : -
1. MPlayer (with all associated libraries installed)
2. FFmpeg source code
3. Active Internet Connection

Downloading Videos from YouTube

There are number of ways of downloading videos form youtube


1. Youtube-dl script : -
There is a handy python script called youtube-dl that can download videos from the youtube website and works as a Linux console application . The script can be found here : -
http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl

First you need to note/copy the address of the youtube clip you want to save then supply the address to youtube-dl program which downloads the clip.

use : youtube-dl -o filename.flv "Entire path to youtube clip(ex:- http://www.youtube.com/watch?v=foobar ) where foobar would be actual code of the clip"

If the file needs a user-name and password as it is classified under mature section then following command can be used for downloading the video clip.

use : youtube-dl -u username -p password "Entire path to youtube clip(ex:- http://www.youtube.com/watch?v=foobar ) where foobar would be actual code of the clip" -o filename.flv


2. Using FireFox extension : -

First one hast to install GreaseMonkey on FireFox which enables custom java scripts to run under FireFox browser. Greasemonkey can be found here in this location : -
https://addons.mozilla.org/firefox/748/
On clicking the install button the GreaseMonkey install itself on the firefox browser , and the GreaseMonkey can be used after restarting the Mozilla FireFox browser .
A Dialog showing installation of the Script

After restarting the Mozilla FireFox browser type the following address in the address-bar , "http://www.joshkinberg.com/blog/files/youtube_to_me.user.js" , on typing the address the script install automatically. Now whenever anyYouTube video is loaded in the browser a link with red background is provided at top of web browser allowing for downloading of the file . After downloading the file rename the file as filename.flv where filename is name of file that you want to have.

A Windows showing a red bar at top providing link
for downloading of Youtube Videos


3.Use Third Party websites allowing download of youtube videos

There are website which allows saving of youtube videos to computer ,first go to the page of the clip you want to download , copy the address of the clip then go to keepvid.com paste the link , click on the link and download the file. Rename the downloaded file to file's name.flv
Here are some of the Websites : -

http://javimoya.com/blog/youtube_en.php
http://keepvid.com
http://www.youtubex.com/
http://www.viloader.net/


PLAYING FLV FILES

FLV file can be played on the Linux operating system using the MPlayer video player or VLC Video player .
Both can be found here : -

MPlayer : - http://www.mplayerhq.hu/
VLC Player : - http://www.videolan.org/vlc/


use : mplayer filename.flv at the console for playing the flv file .

If you dont know about MPlayer or VLC Player better look at this post : - http://linuxondesktop.blogspot.com/2007/01/playing-audiovideo-files-under-linux.html

ENCODING FLV FILE TO 3GP

3gp is a common media format used on mobile phones allowing playback of video . 3gp video is encoded in H.263 or H.264 and audio is encoded in AMR-NB or AAC format . So FLV file has to be converted to these video encoding

mencoder is a good tool for converting one media file format to another , it can convert any media supported by MPlayer from one format to other . It can be downloaded with MPlayer and can be used for encoding the video and audio encoding from FLV to AVI. So that video could be played on mobile phones.

Here are the steps for converting FLV file to 3gp FILE : -

1. First we will extract video from the FLV file and save it as a AVI file which would be combined with audio stream using FFmpeg program .

mencoder Filename.flv -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:-2 -o temp.avi -ofps 15


Here in the above command Filename.flv is the name of the video file you want to convert to mobile phone format and temp.avi would be the file in which the converted video would be written. 176:144 Is the size of mobile screen of the phone to which we want to resize the video clip. -ofps 15 specifies the frame rate per second.


Now we extract a audio stream from the FLV movie and store it in a external wav file soundump.wav


mplayer -vo null -ao pcm -af resample=8000,volume=+4db:sc filename.flv


This extracts the audio from the file filename.flv and resamples the sound to 8 kHz It also applies a soft clip filter. The result is a file called audiodump.wav that contains the sound. We need to extract sound as 8Khz since FFmpeg wont encode our file if it is higher.


Now a major problem (maybe some legal issue because of proprietary media format) is that because of some reasons the FFmpeg binary that comes dosent include the files to handle the AMR file that is used by 3gp files for storing audio , hence we need to recompile the FFmpeg library to include support for the AMR file.


So first download FFmpeg source-code from Source Code can be obtained from this website : - http://ffmpeg.mplayerhq.hu/ . Extract the source-code to a suitable directory and go to that directory and chdir to doc here you would find a .texi file FFmpeg-doc open that file in text editor or convert the texi file to dvi using tex program and search for AMR you would find a section like this :-


Section of texi file ffmpeg-doc.texi

@item For AMR WB floating-point download TS26.204 V5.1.0 from
@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-510.zip}
and extract the source to @file{libavcodec/amrwb_float/}.

@item For AMR NB floating-point download TS26.104 REL-5 V5.1.0 from
@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip}
and extract the source to @file{libavcodec/amr_float/}.
If you try this on Alpha, you may need to change @code{Word32} to
@code{int} in @file{amr/typedef.h}.

@item For AMR NB fixed-point download TS26.073 REL-5 V5.1.0 from
@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-510.zip}
and extract the source to @file{libavcodec/amr}.
You must also add @code{-DMMS_IO} and remove @code{-pedantic-errors}
to/from @code{CFLAGS} in @file{libavcodec/amr/makefile}, i.e.
``@code{CFLAGS = -Wall -I. \$(CFLAGS_\$(MODE)) -D\$(VAD) -DMMS_IO}''.



Here copy the address for AMR NB loating point download the file http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip extract it in a temporary directory . Create a directory ffmpegsourcecode-directory/libavcodec/amr_float and extract the zip file contained in it in the newly created directory ffmpegsourcecode-direcotry/libavcodec/amr_float .


Now go to the main directory where the FFmpeg source code is extracted and execute configure script with --enable-amr_nb argument. Example "./configure --enable-amr_nb "

Now make to compile the source code

and make install to install the compiled files.



Now if everything went fine in above steps . FFmpeg should be configured to encode 3gp files properly, now we combine the two pieces to create a one 3gp file using FFmpeg


ffmpeg -i temp.avi -i audiodump.wav -b 48 -ac 1 -ab 12 -map 0.0 -map 1.0 filename.flv


After this command the flv file should be ready to be transferred to a mobile device , and should work fine on any phone capable of playing the 3gp format.


Article Written by Ambuj Varshney <> for Linux On Desktop (http://linuxondesktop.blogspot.com)
(C) 2006 , Ambuj Varshney

Comments

  1. Great blog congratulations!come visit our site and see amazing free on line movies www.zigbr.com

    ReplyDelete
  2. Anonymous7:00 PM

    Thanks for the nice post!

    ReplyDelete
  3. Anonymous3:36 PM

    The Firefox JS plugin does not work with Youtube. Perhaps earlier, but....

    ReplyDelete

Post a Comment

Amazon Ads