ffmpeg video converter

In the few previous posts we have been downloading YouTube videos with Awk and Perl. What we ended up with were .flv (Flash Media Video) files which do not play with the usual video players like Windows Media Player which comes with Windows out-of-the-box.

To play these .flv's we either need a special video player which supports this video file format such as VLC Media Player or FLV Player, or get a good video codec pack (which I do not recommend since it eventually messes the whole multimedia subsystem up, not gonna even link to it), or get a ffdshow all-in-one video codec (I recommend it).

The ffdshow solution is pretty good and that is what I use myself together with the excellent Media Player Classic video player which replaces the horrific Windows Media Player once and forever.

Now suppose you wanted to send the video file to your friend who didn't know about all these video codecs and players and didn't want to have them installed. What would you do?

Or suppose you wanted to put the video on your brand new iPhone or video iPod, or your cellphone.

Let's learn how to convert the video to a better format such as windows media video (.wmv), .avi, mpeg or divx, or mobile phone's 3gp format (or even others).

The tool we are going to use is called ffmpeg. ffmpeg is a command line tool to convert one video and audio file format to another.

The official homepage of the tool is at ffmpeg.mplayerhq.hu which is more often down than not. The official download page is here, alternative download here.

I went to the alternative site, downloaded the latest version (ffmpeg.rev9767.7z) and extracted it with WinRar.

The other cool thing about ffmpeg is that it is a command line tool and it's cross platfrom, so you can run it anywhere and it does not need the GUI.

Once you have it downloaded, unpack it and run the tool without any command line options:

usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...
Hyper fast Audio and Video encoder

Main options:
-L                  show license
-h                  show help
-version            show version
-formats            show available formats, codecs, protocols, ...
-f fmt              force format
...

Okay, from the first usage line we now know that to convert a video we will run the tool as following:

> ffmpeg -i our_flash_video.flv ... options ... our_desired_video.avi (or .mpg, or whatever)

Besides this valuable information we also get hundreds of various options which do not yet make much sense to us.
We need documentation of the tool to understand it. Quickly typing 'ffmpeg documentation' into Google we find this ffmpeg documentation page.

Before going into documentation let's first just try converting the video:

> ffmpeg.exe -i youtube_flash_video.flv out.avi
FFmpeg version SVN-r9767, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-pp --enable-swscaler --enable-pthreads --
enable-liba52 --enable-avisynth --enable-libamr-nb --enable-libamr-wb --enable-l
ibfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --enable-libnut --en
able-libogg --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx
vid --cpu=i686 --enable-memalign-hack --extra-ldflags=-static
  libavutil version: 49.4.1
  libavcodec version: 51.40.4
  libavformat version: 51.12.1
  built on Jul 20 2007 18:03:34, gcc: 4.2.0

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000
/1) -> 15.00 (15/1)
Input #0, flv, from 'youtube_flash_video.flv':
  Duration: 00:01:23.9, start: 0.000000, bitrate: 64 kb/s
  Stream #0.0: Video: flv, yuv420p, 320x240, 15.00 fps(r)
  Stream #0.1: Audio: mp3, 22050 Hz, mono, 64 kb/s
Output #0, avi, to 'out.avi':
  Stream #0.0: Video: mpeg4, yuv420p, 320x240, q=2-31, 200 kb/s, 15.00 fps(c)
  Stream #0.1: Audio: mp2, 22050 Hz, mono, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 1259 fps=219 q=2.0 Lsize=    2780kB time=83.4 bitrate= 272.9kbits/s
video:2050kB audio:652kB global headers:0kB muxing overhead 2.860901%

Hey, wow! It worked, we just converted our .flv to an mpeg4 video! Also the sound got converted from mp3 to mp2.

We would like to have more control over these parameters, right?

Let's go through documentation and find how to change audio and video bitrate, video framerate, video and codecs and output video size.
For various video options there is a section in documentation called 'Video Options', there we find that '-b bitrate' option changes video bitrate, '-s wxh' changes video width and height, '-vcodec codec' changes the video codec and '-r framerate' changes the video frame rate.

The audio options are listed here and we find that to change the audio bitrate we need to specify '-ab bitrate' and '-acodec codec' to change the audio codec.

The other interesting option is '-formats' which lists the supported codecs and protocols.

The videos we get from YouTube are usually 320x240 in size and at 15 fps with 64kbit/s mp3 sound.

If we did not specify the vid size, framerate and other parameters the input video's ones would be used for output video.

Just to illustrate how to use those command options, let's convert a YouTube video to 3gp format for viewing on a mobile phone. What is this 3gp format? Looking in wikipedia for 3gp we find that this format stores video streams as MPEG-4 Part 2 or H.263 and audio streams as AMR-NB, AMR-WB, AMR-WB+ or AAC-LC.
Also it turned out that H.263 can only take a number of video sizes which are listed on this page.
All we have to do is just to specify the right command line flags - and voila!

> ffmpeg.exe -i youtube_flash_video.flv -r 15 -b 200kbit/s -s 176x144 -vcodec h263 -ar 8000Hz -ab 10.2k -acodec libamr_nb for_mobile.3gp

Yeap, it worked, I uploaded the file to my Nokia N73 and it played perfectly!

To convert it to DivX and leave all the other parameters as is, use the following simple command line:

> ffmpeg.exe -i youtube_flash_video.flv -vcodec mpeg4 divx_youtube_movie.avi

To convert to other formats, just look at the supported encoding formats via '-formats' command line option. For example, to convert a video to .wmv, you would specify '-vcodec wmv2' or '-vocdec wmv1', etc.

Now we know how to download youtube videos and how to convert them. It seems that a perfect time has come to create a free, quick and cool desktop software application which will do this job for us.

Thanks for reading and until next time!

Comments

December 13, 2007, 23:18

converting youtube download videos to be used in nokia mobiles phones

December 18, 2007, 10:27

I am trying to convert other video format to flv.. ffmpeg generating flv file but file does not play in flv player.. Can anybody know possible cause???

Thanks

January 01, 2008, 02:57

Suppose you want to download the top 5 most watched videos with title containing "FOOBAR" in category Music. Using the youtube feeds protocol you can do something like this:

GET "http://gdata.youtube.com/feeds/api/videos/-/Music/?vq=FOOBAR&orderby=viewCount&max-results=5" 
| xmllint --format -|grep "media:player"|cut -d\" -f2 |clive -y -s

xmllint --format will obviously format the downloaded XML file so we can easily extract the needed URL of the video located under the "media:player" tag.
Next we pipe the output the clive which will know how to handle the url and retrieve the flv file. Optionally you can pipe it to get_youtube_vids.awk if it accepts downloading multiple files, however clive has more options and can even encode the vids after download :)

March 10, 2008, 20:47

Hi,
I found your article quite nice and perhaps a little complex for a novice.
I think that the best way to convert this YOU TUBE files to most of the formats is by downloading WinFF which is freeware from http://www.topdrawerdownloads.com/download/104928.
The software has a GUI and its very easy to use for any person. Furthermore, it can convert to audio, mp3 and all.
Personally, I download the files using what I would say the easiest method, you just get the address of the you tube file and copy it at http://www.techcrunch.com/get-youtube-movie/ and within a few minutes the file is downloaded to your computer, from there on, I convert with the WinFF and I have all that I need.
Its a very easy way to get good quality music and video.

August 28, 2008, 23:34

Excellent article! Nice intro to basic ffmpeg encoding. Super fast speeds too! FPS exceeding 1200!!

Thanks a lot,
Dominique

October 14, 2008, 09:46

Free online flv converter---- http://www.convertdirect.com
Convert any online flv / youtube video to iPod / zune / PSP / MP3 / MP4 Portable player directly.it is full free!!

March 31, 2009, 22:42

I have tried different methods to download videos from youtube. I believe keepv is the best methods so far. You can download it here with no need to go to their website :

http://efiles.org/index.php/files/get/nASHvqWnUE/keepvflashconvertersetup.zip

Josh Permalink
May 26, 2009, 19:23

Thank you.............

But i found "Zillatube" program download video quickly, and also easy to play or convert those videos too.

found it at http://www.zillatube.com
====================================== :)

Salvio Permalink
November 26, 2009, 15:58

The best way I found to convert youtube videos was in www.freefileconvert.com . It is fast and easy, other good site is www.convertvideotoaudio.com, this one is for convert video to audio

Valdis Permalink
January 17, 2010, 19:35

Hi,
You can use Bender Converter - http://benderconverter.com - to download YouTube Videos as MP3, AVI, 3GP and many others. It very nice service!

February 17, 2010, 08:24

MP4 and MP4 HD are good formats for high quality YouTube conversions. All that's needed is VLC Player, which plays pretty much everything.

February 18, 2010, 12:52

Dooclip site provide direct download, visit http://www.dooclip.net you can chose videos format (mp4,3gp,flv) for download

May 18, 2010, 06:50

you chosen very interesting topic i like your concept it is useful for beginners.

Andre Permalink
June 23, 2010, 14:34

Download Youtube Videos in 3GP, MP4, or FLV format for free online at http://facebookvid.com

May 08, 2014, 02:25

I was looking for exactly this piece of software to help me.

July 17, 2014, 10:38

retwit,,

July 01, 2014, 05:53

It will be so amazing to use

July 17, 2014, 10:22

Awesome tool to converting youtube videos .

July 18, 2014, 05:49

Ok it will be so special

July 21, 2014, 12:44

Ok is fine idea

July 22, 2014, 06:07

That is so special idea

July 23, 2014, 13:20

Ok is super idea

July 24, 2014, 11:50

Ok seems to be interesting

August 02, 2014, 07:49

Ok it will be a future

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "server": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.

Advertisements