How to Convert .FLV Files to MPG or MP3

By chris

If you have ffmpeg and lame installed, you can easily convert flash video files (.flv) such as youtube videos to mpeg or mp3 files. Ok, in case you don’t know where these videos are stored. Firefox has a Cache directory. Under In Linux, you have a good chance of finding it under .mozilla/firefox/=somealphanumeric=.default/Cache This is where the Flash videos are usually stored. They won’t have the .flv ending though! To convert an flv file to mp3, use ffmpeg. I guess, you will also need lame in order to encode mp3 correctly, ffmpeg has tons of options. I used i (inputfile), ar (sample rate), ab (audio bitrate) and ac (audio channels).

Note: In more receent ffmpeg version you might need to add an extra “k” for kilobyte, e.g. “-ab 160k

[chris@hismachine:~]$ ffmpeg -i flashvideo.flv -ar 44100 -ab 160k -ac 2 output.mp3

In order to convert an flv file to mpeg, you can use something like this.

[chris@hismachine:~]$ ffmpeg -i flashvideo.flv -s 352x288 -b 512 -ab 128 output.mpg

The options here are s (size) and b (video bitrate). Play around with ffmpeg’s options and try different bitrates etc. However, bear in mind that if the input video is bad quality then the output won’t be any better ;)

Tags: , , , , , , ,

18 Responses to “How to Convert .FLV Files to MPG or MP3”

  1. convert flv to mp3 | kholis@home Says:

    [...] taken from here [...]

  2. Bio Says:

    Hi,

    I tried your example with an flv file but I seem to have a problem, the output file is tiny and doesn’t play.

    Here’s what I entered:

    ffmpeg -i Linkin-Park_Given-Up.flv -ar 44100 -ab 160 -ac 2 Linkin-Park_Given-Up.mp3

    And here’s the output:

    Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 12.00 (12/1)
    Input #0, flv, from ‘Linkin-Park_Given-Up.flv’:
    Duration: 00:03:11.8, start: 0.000000, bitrate: 64 kb/s
    Stream #0.0: Video: flv, yuv420p, 320×240, 12.00 fps(r)
    Stream #0.1: Audio: mp3, 44100 Hz, mono, 64 kb/s
    Output #0, mp2, to ‘Linkin-Park_Given-Up.mp3′:
    Stream #0.0: Audio: mp2, 44100 Hz, stereo, 0 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Press [q] to stop encoding
    size= 79kB time=191.7 bitrate= 3.4kbits/s
    video:0kB audio:79kB global headers:0kB muxing overhead 0.000000%

    I don’t mean to be a pain in the ass, but I have no idea how to use ffmpeg. Any help you can provide will be appreciated.

  3. chris Says:

    Hmm… it works fine for me, I used the command you quoted. Maybe try a newer ffmpeg version, that might do the trick. http://ffmpeg.mplayerhq.hu/
    Let us know how it goes…

  4. test Says:

    My code:
    ffmpeg -i 28593.flv -ar 4100 -ab 500 -ac 2 test.mp3

    I am also tried your example but i got the following error. The converted mp3 file is very small..

    FFmpeg version SVN-r12312, Copyright (c) 2000-2008 Fabrice Bellard, et al.
    configuration: –enable-gpl –enable-pthreads –enable-libx264 –enable-libamr-nb –enable-libamr-wb –enable-nonfree
    libavutil version: 49.6.0
    libavcodec version: 51.50.1
    libavformat version: 52.7.0
    libavdevice version: 52.0.0
    built on Mar 4 2008 21:54:37, gcc: 4.1.2 20070626 (Red Hat 4.1.2-14)
    Input #0, flv, from ‘/home/dev5/public_html/flash/fortesting/QuickcamRecorder/28593.flv’:
    Duration: 00:00:17.4, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: flv, yuv420p, 160×120 [PAR 0:1 DAR 0:1], 1000.00 tb(r)
    Stream #0.1: Audio: nellymoser, 8000 Hz, mono
    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    Output #0, mp2, to ‘/home/dev5/public_html/flash/fortesting/QuickcamRecorder/test.mp3′:
    Stream #0.0: Audio: mp2, 44100 Hz, stereo, 0 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Press [q] to stop encoding
    size= 7kB time=17.4 bitrate= 3.4kbits/s
    video:0kB audio:7kB global headers:0kB muxing overhead 0.000000%

  5. chris Says:

    looks like you have a very small audio “ar”, try this one:
    ffmpeg -i 28593.flv -ar 44100 -ab 160 -ac 2 test.mp3

  6. test Says:

    i have also tried this one
    ffmpeg -i 28593.flv -ar 44100 -ab 160 -ac 2 test.mp3

    But i got the same error.. can you please help me..

  7. Lucian Says:

    Do you have lame installed? My ffmpeg is compiled with:
    –prefix=/usr –enable-shared –libdir=/usr/lib –enable-liba52 –enable-pp –enable-gpl –enable-pthreads –enable-libnut –enable-libtheora –enable-libvorbis –enable-x11grab –enable-dirac –enable-libmp3lame –enable-libfaad –enable-libfaac –enable-libx264 –enable-libxvid –enable-libamr_nb –enable-libamr_wb
    (default mandriva rpm)

  8. Domm Says:

    I Used This Script + Modified for a .Bash
    $ ffmpeg -i Input.flv OutPut.mp3
    -ar and -ab is completely uneccarsary, They Are Mainly Used for Lowering Quality hence lowering the file size
    Im 11 And I was Able to edit and use, I wonder what a 15 year old maybe capapble of or even a 20-year-old.
    Thanks For Share.

  9. chris Says:

    No, they are not unnecessary! Without the options you will encode a 64kbit file with low quality. Of course, if the source .flv file already is low quality you cannot improve it but omitting the options might lower the quality. Try it with two files and listen to the difference. For example, I tried it with this one:
    http://uk.youtube.com/watch?v=PU7J5MSIr6U
    Without the option you will get a 1.9M file with lousy quality. Adding “-ar 44100 -ab 160″ the quality of the file is much better (size 4.7M).

  10. shadowwraith Says:

    I am not 11 or 15 or 20, *sigh* I am 38…er I think, I can’t remember. Somewhere between 35-38 or so. But I think I am getting the error as well.

    The file is 93kb and its not working. What is odd is it starts to encode the audio, and you think “Cool, its going to work.” but then it craps out. I do get a warning before it starts to encode which might be an indicator of the problem.

    “WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s”

    How can you set this?

    Just to be thorough here is the whole kitten kaboodle…

    ffmpeg -i crap.flv -ar 44100 -ab 160 -ac 2 crappy.mp3
    FFmpeg version r11872+debian_3:0.svn20080206-12ubuntu3, Copyright (c) 2000-2008 Fabrice Bellard, et al.
    configuration: –enable-gpl –enable-pp –enable-swscaler –enable-x11grab –prefix=/usr –enable-libgsm –enable-libtheora –enable-libvorbis –enable-pthreads –disable-strip –enable-libfaad –enable-libfaadbin –enable-liba52 –enable-liba52bin –enable-libdc1394 –disable-armv5te –disable-armv6 –disable-altivec –disable-vis –enable-shared –disable-static
    libavutil version: 49.6.0
    libavcodec version: 51.50.0
    libavformat version: 52.7.0
    libavdevice version: 52.0.0
    built on Oct 3 2008 22:40:31, gcc: 4.3.2

    Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 25.00 (25/1)
    Input #0, flv, from ‘crap.flv’:
    Duration: 00:03:45.0, start: 0.000000, bitrate: 64 kb/s
    Stream #0.0: Video: flv, yuv420p, 320×240 [PAR 0:1 DAR 0:1], 25.00 tb(r)
    Stream #0.1: Audio: mp3, 22050 Hz, mono, 64 kb/s
    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    File ‘crappy.mp3′ already exists. Overwrite ? [y/N] y
    Output #0, mp2, to ‘crappy.mp3′:
    Stream #0.0: Audio: mp2, 44100 Hz, stereo, 0 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Press [q] to stop encoding
    size= 93kB time=225.0 bitrate= 3.4kbits/s
    video:0kB audio:93kB global headers:0kB muxing overhead 0.000000%

  11. shadowwraith Says:

    hmm I think I figured it out. Try…

    ffmpeg -i crap.flv -ar 44100 -ab 160000 -ac 2 crappy.mp3

    I missed the hint the programmer was trying to give me…

    “It takes bits/s as argument, not kbits/s”

    so 160 should actually be 160000

    :P

    That’s one for the old fogey and zip for the the 11 year old, right?

  12. chris Says:

    that’s weird, maybe they changed it in the more recent versions, my manpage entry for ffmpeg (built Jan07) still says:

    -ab bitrate
    Set the audio bitrate in kbit/s (default = 64).

  13. estebandido Says:

    You need to put the “k” at the end of 160

    ffmpeg -i crap.flv -ar 44100 -ab 160k -ac 2 crappy.mp3

    And also if you don put the -ac or -ab or -ar by default u will get a mono audio file with 64k quality

  14. chris Says:

    Yes, that is the case for more recent versions of ffmpeg, originally you did not, I will add it to the post, thanks!

  15. estebandido Says:

    Hey chris, put it also on the command line, people usually copy from it to use it :)

  16. jamie Says:

    Hey Domm,

    Nice one. Spout off and then show your 11 year old ignorance. Ha,ha..

  17. Laurie Says:

    Yes, I must agree Jamie.

    When you get to the serene age of 15, Domm, you’ll learn that what ever you post on a blog’s comment section will make you look stupid, no matter what the content.

  18. Marcus Says:

    Thanks for the post! Helped a lot!

Leave a Reply