Converting Audio/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
















This is by far the best guide for ffmpeg on the web.
Thank you very much!
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.
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.
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
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
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
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
can you explain how to convert multi wav file to mp3
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.
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.
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.
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
@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.
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.
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.
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…
IS it ffmpeg useful to transcode other videos into WMV format ?
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?
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)
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.
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.
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
kindly help me with the command to convert flv video to mp3
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
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
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
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
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.
Hi Sri,
You are passing single quote in the output file. Remove the single quote and it will work.
Thanks,
Hitesh Agarwal
Hi Hitesh,
Thank you very much… It resolved my problem.
Thanks & Regards
Srikanth
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
Hi Sri,
No idea on Java Media Framework.
Thanks,
Hitesh Agarwal
any ideas on how to convert mp3 to flv???
i m converting the wav file to mp3 it is not working mp3 is not working
Please replay me
Thanks
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
Try “ffmpeg -i test.mp3 test.flv”
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?
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.