Converting Audio and Videos using FFMPEG

I was simply ignoring writing this articles but after writing articles on Installing FFMPEG on Linux i couldn’t resist on writing this article. Anyways this article will guide you on how you can convert audio video formats using FFMPEG.

This articles in divided in various sections

  • Parameter Used
  • Command Line Syntax
  • Conversion Examples

Parameter Used:
Common Parameters

-i ‘filename’ Filename will be the Path of Source Filename
-y Overwrite the existing output file without prompting
-an disable audio

Video Related Parameters

-aspect ‘aspect ratio’ Set Aspect Ratio for the video (4:3, 16:9 or 1.3333, 1.7777)
-r ‘rate’ set frame rate in Hz for the video
-s ‘size’ set video resolution size (Width x Height)
-sameq use same video quality as source

Audio Related Parameters

-ar ‘rate’ set audio sampling rate (in Hz)
-acodec ‘codec’ force audio codec E.g. mp3
-vol ‘volume’ change audio volume (256=normal)
-ab ‘rate’ set audio bit rate (in bits/s)

Advanced Parameters

-map_meta_data output file:input file Copy the Metadata from Input File to Converted output file

Command Line Syntax
ffmpeg –i ‘input filename’ ‘output filename’

  • Syntax Example:
    [root@linux /]# ffmpeg -i demo.mpg demo.flv
    Here FFMPEG will convert demo.mpg file to demo.flv

Conversion Examples:

Video Examples:

  • Converting MOV to FLV using FFMPEG
    ffmpeg -i movie1.flv
    This will convert file to movie1.flv
  • Converting Mpeg to FLV using FFMPEG
    ffmpeg -i movie1.mpeg movie1.flv
    This will convert movie1.mpeg file to movie1.flv
  • Converting AVI to FLV using FFMPEG
    ffmpeg -i movie1.avi -s 500×500 movie1.flv
    This will convert movie1.avi file to movie1.flv and will resize the video resolution to 500×500
  • Converting 3GP to FLV using FFMPEG
    ffmpeg -i movie1.3gp -sameq -an movie1.flv
    This will convert movie1.3gp file to movie1.flv and will keep the original file settings and will disable the audio content
  • Converting MPEG to 3GP using FFMPEG
    ffmpeg -i movie1.mpeg -ab 8.85k -acodec libamr_wb -ac 1 -ar 16000 -vcodec h263 -s qcif movie2.3gp

Audio Examples:

  • Converting aac to mp3 using FFMPEG with MetaData
    ffmpeg -i audio1.aac -ar 22050 -ab 32 -map_meta_data audio1.mp3:audio1.aac audio1.mp3
    This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz and will copy the meta data from .aac file to .mp3 file
  • Converting WMV to MP3 using FFMPEG
    ffmpeg -i audio1.wmv audio1.mp3
    This will convert audio1.wmv file to audio1.mp3
  • Converting WMV to FLV using FFMPEG
    ffmpeg -i audio1.wmv audio1.flv
    This will convert audio1.wmv file to audio1.flv, this will generate only audio content
  • Converting AMR to MP3 using FFMPEG
    ffmpeg -i audio1.amr -ar 22050 audio1.mp3
    This will convert audio1.amr file to audio1.mp3 having audio rate 22.05 Khz
  • Converting aac to mp3 using FFMPEG
    ffmpeg -i audio1.aac -ar 22050 -ab 32 audio1.mp3
    This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz
Tagged . Bookmark the permalink.

69 Responses to Converting Audio and Videos using FFMPEG

  1. zorg says:

    This is by far the best guide for ffmpeg on the web.

    Thank you very much!

  2. pravin k says:

    How to convert a file in two different audio bit rates (eg 64 kb and 128 kb)in one command. What is the -map_meta_data can you explain it in details.

    Pravin k.

  3. Hi Pravin,
    You can convert only one file at a time. Also -map_meta_data will copy all the meta data content i.e. genre, artist etc from the source file to the converted file.

  4. pravin k says:

    I think we can convert the in multiple bit rate in one command.That is workable but I did not understand the -map 0:0 -map 0:0 part in the
    ffmpeg -i /tmp/a.wav -ab 64k /tmp/a.mp2 -ab 128k /tmp/b.mp2 -map 0:0 -map 0:0
    can u explain it …


  5. Daniel says:

    Hi, i am trying to convert some mp4 files captured from a mobile phone. It works fine with -an command (no sound) but i need sound too.
    Thank You

  6. Daniel says:

    sorry it was my fault. the audio bit rate for that file was not included in ffmpeg default audio rates; so a command like
    ffmpeg -i 11122007012.mp4 -ar 11025 test.flv
    worked very nice.
    Thank you for this great tutorial

  7. litak says:

    Can I convert a WMV file to MPEG4 format file with the audio as it was. I have used the following command -
    >ffmpeg -i Bear.wmv -b 600 -s 320×240 -vcodec mpeg4 -acodec copy -f mp4 Bear.mp4

    But unfortunately the output is not good. Audio is absent and the video quality is very poor. Could you please suggest me what is wrong in this command.


  8. srinivasan says:

    can you explain how to convert multi wav file to mp3

  9. sandy says:


    for Converting 3GP to FLV using FFMPEG as per your above example following command will convert video but without sound.
    ffmpeg -i movie1.3gp -sameq -an movie1.flv

    But i want to convert video with sound. Sound should be remain as it is. Can anybody please give me proper command to convert 3gp to flv.

    Thanks in advance.

  10. Java Developer says:


    I am trying to extract meta data from .flv, .wmv and .rm file.

    What I need to extract from these files is:

    1. Width
    2. Height
    3. Bit rate
    4. FileSize
    5. Duration
    6. MimeType

    Is there any way I can get this using Java + FFmpeg libs? If yes then please share from where to start?

    Any help or comments on this would highly appreciated.

  11. I don’t know about java but you can get the above details using FFMPEG-PHP which is PHP based Library. If you are still unable to find libs for java than:
    1) install FFMPEG-PHP,
    2) write php script that will use FFMPEG-PHP Library to extract the meta data.
    3) Call this php script from shell script and extract the content 4) Call the shell script using runtime class in java.

  12. Robert Trendall says:

    Hi there

    Sorry I am sooo confused its frigtning … trying to do all sort of demuxing and muxing for my archos 5.

    What would be of untold help, is if someone can give me the basic command to convert ac3 to aac.

    many many thanks in advance

  13. KiloVision says:

    ffmpeg -i input.ac3 -acodec aac output.aac

    Great tutorial. One thing that should be mentioned is that the order of the parameters is important. Parameters are applied sequentially. If you put the “-acodec” parameter before the “-i” parameter, ffmpeg will apply the codec to your input file, and your conversion won’t work.

  14. Roshan says:

    hi thanks for ur tuts can u help me how to get output file in VBR format for mp3 files i m using this command ffmpeg -ab 160k -i source.mp3 destination.mp3 but it converts the source.mp3 to 160kbps in CBR not in VBR. Kindly tell me the option to do so… plz Thank you.

  15. Nishad Aliyar says:

    I need to get the video in the same quality of input file after video conversion and the size of the converted file near or same to the input file.
    Can anyone help me please?, I lost more time in this.

    This is the code I used for conversion
    exec(“../ffmpeg -i -sameq -f flv -vcodec flv -b 400kb -s 614×400 -qmin 1 -qmax 31 -acodec libmp3lame -ar 22050 -ac 1 1.flv”);

    After conversion quality of the video is ok, but the size of the flv file (1.flv) converted is large in size.
    If I remove the -sameq from the above syntax , problem of huge size of converted flv file
    (1.flv) will solve , then the quality of the video is poor.

  16. vinod says:

    i want to convert all audio file to mp3 file.that is working……but problem is that mp3 file not support to flash player. that file play on vlc and media player giving error..The file you are attempting to play has an extension (.mp3) that does not match the file format. Playing the file may result in unexpected behavior.

    plz give me any suge…

  17. Michael Berende says:

    IS it ffmpeg useful to transcode other videos into WMV format ?

  18. sudip says:

    Hi Hitesh,
    I need one help from you. I have a ffmpeg server hosting. When I am trying to convert my mp4/3gp file into flv file, the script create a .flv file but its a 0(Zero) byte file. I have checked the folder permission and all other possibilities, but not recognized the actual problem. I have used the simplest command
    ffmpeg -i src/movie1.mp4 dest/movie1.flv

    Can you plz help?

  19. Pingback: Converting Audio/Videos using FFMPEG | Techie Zone | Video Software Site

  20. Sandhya says:

    I have converted any video format to 3gp file format using ffmpeg on one server. But on another server it not works.

    Following is my script:

    exec(“ffmpeg -i test.flv -sameq -acodec libmp3lame -ar 22050 -ab 96000
    -deinterlace -nr 500 -s 320×240 -aspect 4:3 -r 20 -g 500 -me_range 20
    -b 270k -deinterlace -f flv -y test.3gp “);
    Can anyone tell me what is wrong in script?

    Following is my ffmpeg setting:

    root@ninja [~]# ffmpeg -formats ffmpeg version CVS, build 3277056, Copyright (c) 2000-2004 Fabrice Bellard configuration: –enable-mp3lame –enable-libogg –enable-gpl –disable-mmx –enable-shared built on Jun 17 2009 10:51:43, gcc: 4.1.2 20080704 (Red Hat 4.1.2-44)

  21. newbie boy says:

    has anyone got the solution on



    for Converting 3GP to FLV using FFMPEG as per your above example following command will convert video but without sound.
    ffmpeg -i movie1.3gp -sameq -an movie1.flv

    But i want to convert video with sound. Sound should be remain as it is. Can anybody please give me proper command to convert 3gp to flv.

    Thanks in advance.

  22. Venkat says:

    Hi hitesh,

    Is it possible to convert an swf to avi or flv or mpg using ffmpeg…in linux…???
    if so pls give some info on this for me..!!!

    thanks in advance,

  23. Makki says:

    kindly help me with the command to convert flv video to mp3

  24. Venkat says:

    Hi hitesh
    I am asking about swf to avi or flv not video conversion
    Please gimme a procedure to convert from linux terminal

    Thanks in advance

  25. hi,
    -map_meta_data output file:input file
    is not working.
    when i converted any media file into flv.orignal file have metadata duration is mention correct but in flv file durtion is mention 00:00:00. please send me solution how can i set duration if flv file.
    Rana Muhammad Saleem

  26. Taruna says:


    I am using ffmpeg for play audio/video in Mobile.

    I converted from .WMV to .FLV or .3GP(get 0 size), or in MP4 but do not able to play in mobile when same file play properly in desktop Real Player.

    I tried Command in following way:
    ffmpeg -y -i c:movie1.wmv -sameq -an movie1.mp4

    Where is the problem you know that?

    Thanks in Advance

  27. Sri says:

    Hi Hitesh,
    I am using ffmpeg in my java code. I am able to converting a wave file into mp3 file. But problem is when i am giving my inputfile and output as static it is giving me output ok. But i am giving inputfile name as a variable from my code and output file name also a variable from my code it is not working. Can you please helpme out.

    my code is like this.

    String cmd[]={“cmd.exe”, “/C”, “c:\ffmpeg -ab 48k -ar 44100 -i c:\capture.wav -y c:\capture.mp3 “}; — works fine if I am giving like this means

    String cmd[]={“cmd.exe”, “/C”, “c:\ffmpeg -ab 48k -ar 44100 -i c:\capture.wav -y c:\’”+filename+”‘ “}; — not working if I am giving like this.

  28. sri says:

    Hi Hitesh,

    Thank you very much… It resolved my problem.

    Thanks & Regards

  29. Sri says:

    Hi Hitesh…
    I am recording voice using jmf as a web application. When run from client machine it is saves record on the server but i am not able to run more than one client at a time. Your help would be appreciated.

    Thanks & Regards

  30. FranKaiser says:

    any ideas on how to convert mp3 to flv???

  31. malli says:

    i m converting the wav file to mp3 it is not working mp3 is not working
    Please replay me


    • Hi Malli,
      Converting from wav to mp3 using ffmpeg is straight forward: “ffmpeg -i test.wav test.mp3″

      You need to have libmp3lame installed on your system and ffmpeg is compiled with libmp3lame enabled.

      Hitesh Agarwal

  32. avinash says:

    Hi, hope you can help me out.
    I got lots of queries :-)
    to begain with, is there any size limitation on source file to be converted to flv?

  33. avinash says:

    avinash :Hi,New Year’s best wishes to You and All.
    and hope you can help me out.I got lots of queries to begain with, is there any size limitation on source file to be converted to flv?

  34. sunsiva says:

    ffmpeg -i -acodec libmp3lame -ab 160kb -ac 2 -ar 44100

    The Above command executed and 0 byte mp3 file is created always. Can anybody tell me what might be the reason?

    Thanks in advance.

  35. sri says:

    Hi Hitesh,
    I am trying to convert wav to mp3 using java, i am able to do conversion but my problem is it is getting struck while running the program if i click on ctrl+c on my code it is getting the correct size, otherwise it is getting struck at somepoint.

  36. srikanth says:

    @Hitesh Agrawal
    yes.. Hitesh.. I am using Runtime.getRuntime().exec call to ffmpeg…


  37. srikanth says:

    hi hitesh,
    Yes, I am using Runtime.getRuntime().exec call only…,


  38. Pingback: 21 « Ntw1103’s Weblog

  39. CocoaDev says:

    Hi Friend,

    I have to convert AAC file to Mp3 in my project for detecting BPM.

    I installed FFMPEG and i added all the library and i am not getting any compiler error but it crashes when i run the project.

    I am getting following error,

    [Session started at 2010-02-23 19:22:13 +0530.]
    2010-02-23 19:22:14.641 New Decode[7170:10b] *** _NSAutoreleaseNoPool(): Object 0x20a2d0 of class NSCFData autoreleased with no pool in place – just leaking
    Stack: (0x967a8f4f 0x966b5432 0x966c9b25 0x966c9701 0x2eb2 0x28de)
    2010-02-23 19:22:14.649 New Decode[7170:10b] *** _NSAutoreleaseNoPool(): Object 0x20bcf0 of class NSCFData autoreleased with no pool in place – just leaking
    Stack: (0x967a8f4f 0x966b5432 0x966c9b25 0x966c9701 0x2ed5 0x28de)
    Audio decoding
    [aac @ 0x1802000]channel element 1.0 is not allocated
    Error while decoding

    The Debugger has exited with status 1.The Debugger has exited with status 1.

    Does any one have idea about it?.


  40. Nidaan says:

    I want to convert flv files mp4 format.
    Can you please tell me the command for this and audio codecs required for this?

  41. Pingback: zero byte files

  42. Carlos Suarez says:

    the -ab parameter is in bytes, so if you put 256, its wrong, then you need to multiply for 1024, and the result 262144 put in that parameter.

  43. pranoy sinha says:


    I have read the article.. really helpful.. Interested readers/coders also suggested to view this URL.. .. This is really a great help for me when i was trying to integrate this in one of my websites.

  44. Samir Trivedi says:


    We converted files and were using JW Player unlicensed copy to play the files then I bought license copy but the same files which use to play with unlicensed copy of JW player is not playing in license version. we convert video files through ffmpeg so we are using the same commands to convert files. I contacted to jw player and said it might be because our files are missing metadata and we need to inject metadata through ffmpeg!

    question is what kind of metadata our file might be missing? if that is the fact then why it was running under unlicensed version of jw player? so lets say now we want to try to use metadata. can anyone pls tell me how exactly the metadata can be injected while converting files? what can happen if the file is really missing metadata? (right now when you click on player it keeps shows that round thing! videos are not playing)

  45. Renuka says:

    I am unable to convert a .mp4 to a .flv file by using this argument – “ffmpeg.exe -i filename.mp4″ -ar 22050 filename.flv”. I get an Unhandled exception. I have tried various values for the -ar parameter like 11025, 22050, and 44100. Any help is appreciated. Thanks!

  46. Samir says:


    How to convert mp3 to midi (midi polyphonic) with FFmpeg or other technology???

    plz help…
    waiting for your kind reply…


  47. mcc says:

    it is very very usefull document.
    Thank u very much…

  48. Riaz says:

    Can this be possible that we upload an MPEG file and it should be converted into FLV at run-time? Please reply I am in great need of such technique.


  49. tulio says:

    Please, how to convert from flv to mp4 or 3gp? if fails all times

  50. Pingback: RealTime - Questions: "Is it possible to play 320*240 3gp videos?"

  51. jeevan says:

    hi..I need to add two source files audio(.wav) and video (.avi) file into One final output file (.avi or any other format) in java using ffmpeg……Please give me reply soon…i need code in java …..

  52. FDisk says:

    @Nishad Aliyar
    try this:
    exec(“../ffmpeg -i -sameq 1.flv”);

  53. vijesh says:

    hi tulio,

    Try the following command to convert FLV to 3gp

    ffmpeg -i input.flv -acodec libfaac -ab 12.65k -ac 1 -ar 16000 -vcodec h263 -s qcif -r 15 outfile.3gp

    Vijesh Vijayan

  54. blackoutworm says:

    Some people don’t know this, but this isn’t converting.
    You don’t convert anything by copying the file with a new extension at the end.
    Yes, -i is the comment for converting, but in order to convert something you need to include the codecs info, bitrate / quality, and all that.
    If you don’t put in the bitrate or quality, the resolution will be the same.
    But you still need to tell ffmpeg what codec it can use for this.

  55. crossgun says:


    Is it a must that some codecs must be installed for ffmpeg to properly convert a video? I’m trying to convert videos into h.264 mp4 formats but I’m not successful at all even though I tried many things that I got from the web. I have this following installed on my ffmpeg:

    libavutil 50. 3. 0 / 50. 3. 0
    libavcodec 52.37. 0 / 52.37. 0
    libavformat 52.39. 1 / 52.39. 1
    libavdevice 52. 2. 0 / 52. 2. 0
    libswscale 0. 7. 1 / 0. 7. 1

    Am I missing something?

  56. Thomas says:


    Command used to convert wav file to mp3 format: ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 output.mp3
    To know more visit:

  57. Thunder says:

    On Windows default ffmpeg settings are enough to convert from any format to another. Following is a simple example

    ffmpeg -i audio1.wmv audio1.flv

    Although you may need to add few additional parameters like bitrate, frame rate etc. to preserve quality. In Linux, such parameters are sometimes mandatory to convert properly.

  58. D4eRc says:

    @ Thunder
    ffmpeg parameters do not differ between windows and linux. When the same codecs are installed as well on linux and on the windows side, using no additional parameters will produce nearly the same file.
    If this is not the case, give me a proof.

  59. Pingback: Converting 3gp to xvid using Linux and ffmpeg | The Internet made me do it!

  60. Pingback: Creating a FLV Video File on Mac OS X : Steven Winterhalter

Leave a Reply