Home > FFMPEG > Converting Audio and Videos using FFMPEG

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.mov movie1.flv
    This will convert movie1.mov 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


Custom Search

Popular Articles:

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • IndianPad
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • RSS
  • Technorati
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Reddit
  • Add to favorites
  • PDF
  • Twitter
Categories: FFMPEG Tags:
  1. zorg
    January 10th, 2008 at 13:27 | #1

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

    Thank you very much!

  2. pravin k
    February 5th, 2008 at 05:49 | #2

    hi,
    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.

    Thanks,
    Pravin k.

  3. February 5th, 2008 at 22:30 | #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
    February 11th, 2008 at 21:28 | #4

    hi,
    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 …

    -pravin

  5. Daniel
    February 14th, 2008 at 01:33 | #5

    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
    February 14th, 2008 at 02:15 | #6

    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
    February 18th, 2008 at 21:44 | #7

    Hi,
    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.

    Regards
    litak

  8. srinivasan
    June 9th, 2008 at 22:12 | #8

    can you explain how to convert multi wav file to mp3

  9. July 31st, 2008 at 05:02 | #9

    hi,

    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
    December 22nd, 2008 at 12:28 | #10

    Hi,

    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. December 22nd, 2008 at 22:45 | #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
    January 8th, 2009 at 01:41 | #12

    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
    January 9th, 2009 at 13:27 | #13

    @Robert:
    s/b:
    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
    January 22nd, 2009 at 08:23 | #14

    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
    February 10th, 2009 at 00:46 | #15

    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 1.mov -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. April 3rd, 2009 at 11:11 | #16

    hi
    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
    May 14th, 2009 at 07:42 | #17

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

  18. sudip
    May 19th, 2009 at 23:12 | #18

    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. Sandhya
    June 25th, 2009 at 00:12 | #19

    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)

  20. newbie boy
    July 28th, 2009 at 21:12 | #20

    has anyone got the solution on

    sandy

    hi,

    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.

  21. Venkat
    August 4th, 2009 at 05:28 | #21

    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,
    Venkat.

    • August 4th, 2009 at 05:52 | #22

      Hi Venkat,
      It is possible to covert video formats you have specified in linux using FFMPEG. For that you will have to install FFMPEg on linux, i have listed the tutorial for FFMPEG Installation on my site; you can got through it and install FFMPEG on linux.

      Thanks,
      Hitesh Agarwal

  22. Makki
    August 7th, 2009 at 10:29 | #23

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

  23. Venkat
    August 12th, 2009 at 10:34 | #24

    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
    Venkat

    • August 15th, 2009 at 23:21 | #25

      Hi Venkat,
      You can use FFMPEG to convert swf to FLV or AVI from command console just any other video format conversion.

      Thanks,
      Hitesh agarwal

  24. September 28th, 2009 at 04:20 | #26

    hi,
    -map_meta_data output file:input file
    is not working.
    when i converted any media file into flv.orignal file have metadata.in 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.
    thanks
    Rana Muhammad Saleem

  25. Taruna
    September 29th, 2009 at 05:47 | #27

    Hi

    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
    Taruna

  26. Sri
    November 3rd, 2009 at 23:19 | #28

    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.

    • November 4th, 2009 at 05:59 | #29

      Hi Sri,
      You are passing single quote in the output file. Remove the single quote and it will work.

      Thanks,
      Hitesh Agarwal

  27. sri
    November 4th, 2009 at 20:00 | #30

    Hi Hitesh,

    Thank you very much… It resolved my problem.

    Thanks & Regards
    Srikanth

  28. Sri
    November 5th, 2009 at 19:10 | #31

    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
    Sri

  29. November 6th, 2009 at 09:23 | #33

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

  30. malli
    November 6th, 2009 at 17:44 | #35

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

    Thanks

    • November 6th, 2009 at 21:52 | #36

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

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

      Thanks,
      Hitesh Agarwal

  31. avinash
    January 3rd, 2010 at 10:26 | #37

    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?

  32. avinash
    January 3rd, 2010 at 10:32 | #38

    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?

  33. sunsiva
    February 8th, 2010 at 08:35 | #39

    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.

  34. sri
    February 18th, 2010 at 21:42 | #40

    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.

    • February 18th, 2010 at 21:48 | #41

      Hi Sri,
      Are you using Runtime.getRuntime().exec call to ffmpeg for performing audio conversion in java.

  35. srikanth
    February 19th, 2010 at 20:43 | #42

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

    Thanks

  36. srikanth
    February 20th, 2010 at 01:26 | #43

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

    Thanks

  37. CocoaDev
    February 23rd, 2010 at 06:54 | #44

    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?.

    Regards,
    CocoaDev.

  38. Nidaan
    March 2nd, 2010 at 23:01 | #45

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

    • March 2nd, 2010 at 23:08 | #46

      Hi Nidaan,
      For mp4 you would require H 264 codec. I have not tried mp4 conversion in ffmpeg :( .

      Thanks,
      Hitesh Agarwal

  39. Carlos Suarez
    March 22nd, 2010 at 12:44 | #47

    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.

  40. pranoy sinha
    April 6th, 2010 at 01:24 | #48

    Hi,

    I have read the article.. really helpful.. Interested readers/coders also suggested to view this URL..http://www.apachefriends.org/f/viewtopic.php?f=16&t=32688 .. This is really a great help for me when i was trying to integrate this in one of my websites.

  41. Samir Trivedi
    June 12th, 2010 at 17:44 | #49

    Hi,

    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)

  42. Renuka
    July 21st, 2010 at 11:39 | #50

    @Daniel
    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!

  43. Samir
    July 28th, 2010 at 01:01 | #51

    Dears,

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

    plz help…
    waiting for your kind reply…

    regards,
    samir

  44. mcc
    September 2nd, 2010 at 00:43 | #52

    hi,
    it is very very usefull document.
    Thank u very much…
    mcc

  1. May 27th, 2009 at 09:41 | #1
  2. February 22nd, 2010 at 11:55 | #2
  3. March 4th, 2010 at 12:22 | #3