FFMPEG is a most popular command line tool to convert media files such as audio, video and images from one format to another. We are going to learn ffmpeg command usage to convert other media format to current most popular streaming FLV format. FFMPEG is cross platform tool and does not require any Gui, support several command line options to control your conversion. The other video format can not be played directly in web browser. A right way to publish your videos for viewing in a browser is using FLV wide acceptable format.

How to convert / FFMPEG usage command

Convert other video format to FLV

ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320×240 video.flv

-i input file name
-ar audio sampling rate in Hz
-ab audio bit rate in kbit/s
-f output format
-s output dimension

Convert other video to FLV with metadata

This require flvtool2 tool to be installed on your box.

ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320×240 – | flvtool2 -U stdin video.flv

Convert FLV vidoe to jpg image sequence

This command used to extract frame image sequence.

ffmpeg -i video.flv -an -r 1 -y -s 320×240 video%d.jpg

-i Input file name
-an disable audio
-r fps
-y overwrite file
-s output dimension

Convert particular frame to jpg

Return one particular jpeg image of the frame based on start and end time.

ffmpeg -i video.flv -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 320×240 video%d.jpg

-ss record start time
-t record end time last for

Return first frame of video as jpeg image.

ffmpeg -i video.flv -vcodec png -vframes 1 -an -f rawvideo -s 320×240 video%d.jpg


Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.

This article has 42 comments

  1. sfsf

    hi
    i follwed the steps of compiling FFmpeg for windows and it works fine whithout errors
    put whine i type the convert commant
    (ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320×240 video.flv)

    i have this message
    ‘ffmpeg’ is not recognized as an internal or external command,
    operable program or batch file.

    ??????

  2. Bala Krishna

    This simply mean ffmpeg command not available within the environment path. Please try command with full path of ffmpeg like (c:\ffmpeg\ffmpeg.exe -i video.avi -ar 22050 -ab 32 -f flv -s 320×240 video.flv) or you can add ffmpeg path in environment path setting under windows.

    Hope this help you.

    Bala Krishna

  3. sfsf

    thanks for replay but
    (
    The system cannot find the path specified)

    i searched the c:\
    and i didn’t find any ffmpeg.exe
    just i found the folder?

  4. sandeepsingh

    hi dear i am using this uber uploader on linux uploading is gone mysql daainseration we are doing i have seen all commands to convert files but i want t know that inwhich file of uberuploader we need to plance these files.
    thanks

  5. Bala Krishna

    Hi Sandeep,

    Uber uploader only used to upload files on your server with progress bar. you need to write these command on file on which you are transferring control after upload finish. Usually, this file name and path defined in uber config file. look at uber config file in cgi-bin directory with .pbm extension.

    Thanks

  6. raj416

    we have implemented this concept . but the problem retains in the clarity of the video … the original video which we have played in windows media player is 100% video size and it looks good…

    after we have converted to flv and played it in flash player… it has been tampered…

    we suspect the ffmpeg is capturing the video file with fullscreen mode of windows media player , because when we
    played the original video with full screen mode in windows media player , the output of the video was blurred.

    could you please tell me how to overcome this issue.

  7. mani8php

    hello,

    Iam converting the .mov fie to .flv file.

    But the problem is, it can not be convert to flv .No output comes.

    Just an empty page come.

    I checked my php.ini.the FFMPEG must be enabled.

    Iam using the following code for conversion.

    function converttoflv( $in, $out )
    {
    $cmd = exec(“ffmpeg -i $in -deinterlace -ar 44100 -r 25 -qmin 3 -qmax 6 $out”);
    }

    Please I need the quick and Kind reply as soon as possible…

    Thanks and regards

    Manikandan.T

  8. ww_anowar

    I am trying to convert vedio file to swf/flv using ffmpeg in asp.net but it is not generating any swf/flv and image file. Can you please help me. my code is below:

    protected void btnsub_Click(object sender, EventArgs e)
    {
    if (FileUpload1 != null || FileUpload1.PostedFile != null)
    {
    postedfilename = FileUpload1.PostedFile.FileName;
    SavePath = AppDomain.CurrentDomain.BaseDirectory + “Video\\”;
    string NewFName = postedfilename;
    NewFName = NewFName.Substring(NewFName.LastIndexOf(“\\”) + 1, NewFName.Length – NewFName.LastIndexOf(“.”)) +”.”+ NewFName.Substring(NewFName.LastIndexOf(“.”) + 1);
    Filenamewithpath = SavePath + NewFName;

    //Save The file
    FileUpload1.PostedFile.SaveAs(Filenamewithpath);

    //Start Converting
    string inputfile, outputfile, filargs;
    string withoutext;

    //Get the file name without Extension
    withoutext = Path.GetFileNameWithoutExtension(Filenamewithpath);

    //Input file path of uploaded image
    inputfile = SavePath + NewFName;

    //output file format in swf
    outputfile = SavePath + “SWF\\” + withoutext + “.swf”;
    //file orguments for FFMEPG
    filargs = “-i ” + inputfile + ” -ar 22050 ” + outputfile;

    string spath;
    spath = Server.MapPath(“.”);
    Process proc;
    proc = new Process();
    proc.StartInfo.FileName = spath + “\\ffmpeg\\ffmpeg.exe”;
    proc.StartInfo.Arguments = filargs;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.CreateNoWindow = false;
    proc.StartInfo.RedirectStandardOutput = false;
    try
    {

    proc.Start();

    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    proc.WaitForExit();
    proc.Close();

    //Create Thumbs

    string thumbpath, thumbname;
    string thumbargs;
    string thumbre;
    thumbpath = AppDomain.CurrentDomain.BaseDirectory + “Video\\Thumb\\”;

    thumbname = thumbpath + withoutext + “%d” + “.jpg”;
    thumbargs = “-i ” + inputfile + ” -vframes 1 -ss 00:00:07 -s 150×150 ” + thumbname;
    Process thumbproc = new Process();
    thumbproc = new Process();
    thumbproc.StartInfo.FileName = spath + “\\ffmpeg\\ffmpeg.exe”;
    thumbproc.StartInfo.Arguments = thumbargs;
    thumbproc.StartInfo.UseShellExecute = false;
    thumbproc.StartInfo.CreateNoWindow = false;
    thumbproc.StartInfo.RedirectStandardOutput = false;
    try
    {

    thumbproc.Start();

    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    thumbproc.WaitForExit();
    thumbproc.Close();

    File.Delete(inputfile);
    Savedetails();
    lblmsg.Text = “Video Uploaded Successfully”;
    hyp.Visible = true;
    hyp.NavigateUrl = “Play.aspx”;
    }
    }

    Regards

    ww_anowar

  9. jsarao

    Any hints for converting a directory of JPEG (*.jpg) to FLV?

  10. Nishad Aliyar

    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.

  11. rohit

    Hey
    I am using the ffmpeg to convert the video from other format to flv. It is not working well it buffers too much in the player.some time it stop for some time. Please help me to set it

    Thanks
    Rohit

    • Bala Krishna

      Hi Rohit,

      Thanks for you comments. There is nothing to do with ffmpeg in this regards. There are several reason to buffer video continuously. 1) slower web server response time. 2) Play with you video player setting.

      FFMPEG only used to convert video from one format to another format and video encoding purpose. It does not play any role in video playing.

  12. Sandeep Kumar Jain

    I want to make screenshot of a ‘.mov’ file on a regular time interval. for example if movies is 10 minute long then I want to make its 60 screenshots on every 10 second duration. Kindly help

  13. Rohit

    Hey
    Any tell me how i can get good quality of video. I have used ffmpeg in iceagevideo.com. Picture is some pixled in this, it is not clear , Any one tell me how i can get the good quality of video

  14. krishan

    hello friends,

    when I run the following command on linux comand prompt I get the flv file output but when I run this command using php’s exec or system function, then there is no output file in the specified directory.

    > ffmpeg -i /var/www/html/Project/app/webroot/files/videos/20090319900790169Sample.avi -ar 22050 -ab 32 -f flv -s 320×240 /var/www/html/Project/app/webroot/files/videos/testyimvf.flv

    Here is what I get when run command through linux command prompt..

    ——————————————————————————————————————————————————————————
    [root@CentOS52 ~]# ffmpeg -i /var/www/html/Project/app/webroot/files/videos/20090319900790169Sample.avi -ar 22050 -ab 32 -f flv -s 320×240 /var/www/html/Project/app/webroot/files/videos/test.flv
    FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2006 Fabrice Bellard, et al.
    configuration: –prefix=/usr –libdir=/usr/lib –mandir=/usr/share/man –incdir=/usr/include/ffmpeg –enable-mp3lame –enable-libogg –enable-vorbis –enable-faad –enable-faac –enable-libgsm –enable-xvid –enable-x264 –enable-a52 –enable-a52bin –enable-dts –enable-pp –enable-shared –enable-pthreads –enable -gpl –disable-strip
    libavutil version: 49.1.0
    libavcodec version: 51.28.0
    libavformat version: 51.7.0
    built on Mar 29 2007 01:44:55, gcc: 4.1.1 20070105 (Red Hat 4.1.1-52)

    Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 25.00 (25/1)
    Input #0, avi, from ‘/var/www/html/Project/app/webroot/files/videos/20090319900790169Sample.avi’:
    Duration: 00:00:46.5, start: 0.000000, bitrate: 902 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 608×272, 25.00 fps(r)
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
    Output #0, flv, to ‘/var/www/html/Project/app/webroot/files/videos/test.flv’:
    Stream #0.0: Video: flv, yuv420p, 320×240, q=2-31, 200 kb/s, 25.00 fps(c)
    Stream #0.1: Audio: mp3, 22050 Hz, stereo, 32 kb/s
    Stream mapping:
    Stream #0.0 -> #0.0
    Stream #0.1 -> #0.1
    Press [q] to stop encoding
    mdb:487, lastbuf:0 skiping granule 0
    mdb:487, lastbuf:0 skiping granule 0
    mdb:487, lastbuf:0 skiping granule 1
    mdb:487, lastbuf:0 skiping granule 1
    mdb:481, lastbuf:348 skiping granule 0
    mdb:481, lastbuf:348 skiping granule 0
    [mp3 @ 0x5ff2184]lame: output buffer too small (buffer index: 1986, free bytes:318)
    frame= 1163 q=19.4 Lsize= 1597kB time=46.5 bitrate= 281.2kbits/s
    video:1369kB audio:182kB global headers:0kB muxing overhead 2.983522%
    —————————————————————————————————————————————————————————————

    Does anyone knows why I am not getting the output file when I run the same command through Php’s exec() function. I do get “success” as a return value through this function but no output file.

    Thank you in advance

  15. ichard Williams

    Very good article and discussion. Sounds like a lot of people are being helped. I am not a video expert. There seem to be some questions about the command line – thought should offer a small thought. I use biterscripting (http://www.biterscripting.com/install.html for free install) for command line execution of anything these days.

    If I were to use Bala Krishna’s original command (ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320×240 video.flv), and call in in batch, I would use the following script.

    # Collect a list of .avi files.
    var str l ; lf -rn “*.avi” “some folder” > $l
    while ($l “”)
    do
    var str i ; lex “1” $l > $i
    # $i is input file. Create the corresponding .flv output file name.
    var str o ; sal -p “^.avi^l” “.flv” $i > $o
    # Input file is $i, output file is $o. Call ffmpeg.
    system ffmpeg ” -i ” (“\””+$i+”\””) -ar 22050 -ab 32 -f flv -s 320×240 (“\””+$o+”\””)
    done

    Richard

  16. Ujjwal Das

    Hello Bala,
    Very helpful article.

    I have incorporate it and .flv file is creadted in a server but the size is 0 KB.

    exec($ffmpegPath . ” -i ” . $srcFile . ” -ar ” . $srcAR . ” -ab ” . $srcAB . ” -f flv -s ” . $srcWidth . “x” . $srcHeight . ” ” . $destFile . ” | ” . $flvtool2Path . ” -U stdin ” . $destFile);

    exec($ffmpegPath . ” -i ” . $srcFile . ” -ar ” . $srcAR . ” -ab ” . $srcAB . ” -f flv -s ” . $srcWidth . “x” . $srcHeight . ” ” . $destFile );

    Can you tell me why the creating .flv file size is 0KB.

    It s a urgent.

    Thanks,
    Ujjwal,
    Kolkata, India

  17. Avik Pal

    I used “ffmpeg -i video.wmv -ar 22050 -ab 32 -f flv -s 320×240 video.flv” command to convert but I got this error message.

    FFmpeg version SVN-r15815, Copyright (c) 2000-2008 Fabrice Bellard, et al.
    configuration: –enable-memalign-hack –enable-postproc –enable-swscale –enable-gpl –enable-libfaac –enable-libfaad –enable-libgs
    enable-libvorbis –enable-libtheora –enable-libx264 –enable-libxvid –disable-ffserver –disable-vhook –enable-avisynth –enable-pthr
    libavutil 49.12. 0 / 49.12. 0
    libavcodec 52. 3. 0 / 52. 3. 0
    libavformat 52.23. 1 / 52.23. 1
    libavdevice 52. 1. 0 / 52. 1. 0
    libswscale 0. 6. 1 / 0. 6. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Nov 13 2008 10:28:29, gcc: 4.2.4 (TDM-1 for MinGW)

    Seems stream 2 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 25.00 (25/1)
    Input #0, asf, from ‘video.wmv’:
    Duration: 00:33:34.18, start: 3.417000, bitrate: 108 kb/s
    Stream #0.0: Audio: 0x000a, 16000 Hz, mono, s16, 12 kb/s
    Stream #0.1: Video: wmv3, yuv420p, 240×180, 17 kb/s, 1000.00 tb(r)
    Stream #0.2: Video: wmv3, yuv420p, 240×180, 81 kb/s, 25.00 tb(r)
    Stream #0.3: Data: 0x0000, 8 kb/s
    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    Output #0, flv, to ‘video.flv’:
    Stream #0.0: Video: flv, yuv420p, 320×240, q=2-31, 200 kb/s, 25.00 tb(c)
    Stream #0.1: Audio: libmp3lame, 22050 Hz, mono, s16, 0 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Stream #0.0 -> #0.1
    Unsupported codec (id=86055) for input stream #0.0

    Please help me.

  18. Joby Joseph

    Hi Bala,

    I have one flv file and I want to convert it to mp3. I tried it with ffmpeg and it shows segmentation fault. Then I tried another flv file which I downloaded from youtube. It worked fine and I got the correct mp3. The first flv file is one which I created by Flash Media Server. I wrote one AS program for recording sound from Microphone. That way, I got the flv file and I need to convert it to mp3. Can u plz help me in this matter?

  19. venkat

    hi,
    Is it possible to convert swf to flv or avi using ffmpeg if so could u please tell me how..!!??

    Thanks in advance,
    Venkat.

  20. Venkat

    Hi,
    Is it possible to convert swf to flv using ffmpeg..
    if so could you please tell me how
    for me it is saying that the swf i am trying to convert is unsupported compressed format…

    Please help
    thanks in advance,
    venkat

  21. pez

    Goo dpost. Well done mate. Spot on!!!!

    Keep up the good work!!

  22. Lucky

    Hi
    I need to convert swf in to flv and then make thumbnail of the same….we have managed to convert other formats into FLV but we need swf also to be converted…

  23. asma

    Hi
    When am running this command
    ffmpeg -i sample.avi -ar 22050 -ab 32 -f flv -s 320×240 | /usr/local/src/flvtool2 -Ustdout videosample.flv
    am getting thi errors
    bash: /usr/local/src/flvtool2: No such file or directory
    FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration:
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 0 / 52.20. 0
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    built on Apr 3 2009 16:20:21, gcc: 4.1.2 20071124 (Red Hat 4.1.2-42)
    Input #0, avi, from ‘sample.avi’:
    Duration: 00:02:00.52, start: 0.000000, bitrate: 1283 kb/s
    Stream #0.0: Video: msmpeg4, yuv420p, 384×288, 25 tbr, 25 tbn, 25 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s
    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    At least one output file must be specified

    please help me in resolving this error. thanks in advance !!

  24. convert video

    My friends often ask me the questions:which video converter should I choice?which video converter is best?when I listen to the questions,I don’t know how to answer them.But friends, I can give you some advice if you need convert video.

  25. Abdulla

    Hi,

    Here is my code
    &1″,$a);

    if ($targetFile!=””)
    echo $targetFile;
    else // Required to trigger onComplete function on Mac OSX
    echo ‘1’;
    }
    ?>

    If i creating FLV format File size is 0 kb. If any body knows help me please.

  26. Abdulla

    Here is my code

    $ffmpegObj = new ffmpeg_movie($targetFile);
    $audiofrequency =makeMultipleTwo(22050);
    $audiobitrate = makeMultipleTwo(32000);
    $videobitrate = makeMultipleTwo(104857200);
    $encodesize = makeMultipleTwo(480,360);

    $flvtool2Path=”/usr/bin/flvtool2″;
    exec(“ffmpeg -i “. $targetFile.” -ar “.$audiofrequency.” -ab “.$audiobitrate.” -b “.$videobitrate.” -f flv -y -s “.$encodesize.” “. $destFile . ” | ” . $flvtool2Path . ” -U stdin ” .$destFile.” 2>&1″,$a);

    Flv format size is 0 kb. pls help me

  27. kishore

    Hi,

    Here is my code

    exec(“C:/wamp/www/newtip/ffmpeg/ffmpeg -i C:/wamp/www/newtip/ffmpeg/videos/”.$name.” -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 320×240 C:/wamp/www/newtip/ffmpeg/images/”.$name_s.”%d.jpg”);

    exec(“C:/wamp/www/newtip/ffmpeg/ffmpeg -i C:/wamp/www/newtip/ffmpeg/videos/”.$name.” -ar 22050 -ab 32 -f flv -s 320×240 C:/wamp/www/newtip/ffmpeg/players/”.$name_s.”.flv”);

    It is working on local system but it is not working in server.

    Can anybody tell why it is not working in server(remote system)?
    help me….

    • Bala Krishna

      you should have permission to execute “exec” command on your server. Normally, this is normally disabled on hosting server.

  28. shan

    file size more than 1mb are not converting to flv.I have each of my php configuration setting correct as i can uplaod videos more than 2mb in size…plz help..

  29. ritu

    u may chk the runtime path .may b ur runtime can not get the bat file.put the file in the server’s runtime path.like if u r working on apache tomcat ,then put it into tomcat/bin

  30. Laraine Toh

    I tried grabbing the RSS Feed to your website and for some reason it ain’t properly displaying in Google Chrome. Any suggestions?

    • Bala Krishna

      Google chrome don’t have inbuilt rss feed viewer this is the reason you see rss feed in raw format. All feeds will looks same in chrome. Try to use in IE, FF or Opera for better viewing.

  31. anand

    to work flvtool2 you first need to convert any video to flv and then you can use flvtool2 on above created flv file.

    command for flvtoo2 is
    exec($flvtool2path -U $flvfilepath);
    this command overwrite the flv file and add metadata.

  32. Chauhan

    hi bala i have just install ffmpeg on easyphp in windows enviornment and am able to convert the file as well using php. The thing is when conversion start it displays cmd window for short while but i dont want to cmd window to be displayed. First question is this normal that cmd window popup if not any solution or idea ? waiting for your reply

    Thanks

  33. ishtiaq

    Hi, i want to convert first 15 sec of a video into different formats by using ffmpeg. complete video conversion is working fine.

    help me help me helpme

  34. Sandeep bhatt

    Hi,

    I am trying to watermark logo at top right corner of my videos in ffmpeg0.5 using command

    ffmpeg -i video4.mp4 -f flv -ar 22050 -s 655:484 -ab 64k -ac 1 -vf “movie=0:png:logo.png [logo]; [in][logo] overlay=580:20:1 [out]” out.flv

    but the logo is showing at left top corner .

    Plz help????

  35. Some Flv

    some flv file not converting it says 0kb and some flv file is converting so what i have to do the only problem is in flv so what i have to do

  36. vani

    Hi,

    while converting mov video file to flv. It encounterd encoding errors and asking to quit the prompt. The following query given.
    C:\Program Files\FFmpeg\win32-static\bin>ffmpeg.exe -i JN8AZ1MU0AW002413_audio_v
    ideo.mov -ar 22050 -ab 2048 -ps 2000000000 JN8AZ1MU0AW002413_audio_video.flv
    FFmpeg version SVN-r16573, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: –extra-cflags=-fno-common –enable-memalign-hack –enable-pthr
    eads –enable-libmp3lame –enable-libxvid –enable-libvorbis –enable-libtheora
    –enable-libspeex –enable-libfaac –enable-libgsm –enable-libx264 –enable-lib
    schroedinger –enable-avisynth –enable-swscale –enable-gpl
    libavutil 49.12. 0 / 49.12. 0
    libavcodec 52.10. 0 / 52.10. 0
    libavformat 52.23. 1 / 52.23. 1
    libavdevice 52. 1. 0 / 52. 1. 0
    libswscale 0. 6. 1 / 0. 6. 1
    built on Jan 13 2009 02:57:09, gcc: 4.2.4
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘JN8AZ1MU0AW002413_audio_video.mov’:
    Duration: 00:01:00.58, start: 0.000000, bitrate: 3856 kb/s
    Stream #0.0(eng): Audio: pcm_s16be, 16000 Hz, mono, s16, 256 kb/s
    Stream #0.1(eng): Video: mjpeg, yuvj420p, 640×480 [PAR 1:1 DAR 4:3], 20.00 t
    b(r)
    Output #0, flv, to ‘JN8AZ1MU0AW002413_audio_video.flv’:
    Stream #0.0(eng): Video: flv, yuv420p, 640×480 [PAR 1:1 DAR 4:3], q=2-31, 20
    0 kb/s, 20.00 tb(c)
    Stream #0.1(eng): Audio: libmp3lame, 22050 Hz, mono, s16, 2 kb/s
    Stream mapping:
    Stream #0.1 -> #0.0
    Stream #0.0 -> #0.1
    Press [q] to stop encoding
    frame= 54 fps= 0 q=2.0 size= 211kB time=2.70 bitrate= 639.8kbits/s
    C:\Program Files\FFmpeg\win32-static\bin>

    Please any body can help me.
    Thanks in advance.