This question already has an answer here:

Currently I'm converting .flv flash files to .webm and .mp4 files to be used with an HTML5 video player.


I use this ffmpeg command for WEBM: ffmpeg -i filename.flv -vcodec libvpx -acodec libvorbis filename.webm which works great and the file size stays relatively the same (imporatant).


For MP4 I'm using the following: ffmpeg -i filename.flv -sameq -ar 22050 filename.mp4

It converts to .mp4 fine and prevents any quality loss but the file size almost triples in size.

What ffmpeg formula could be used to convert to MP4 without losing too much quality and preventing a much higher file size?

marked as duplicate by Nifle, BenjiWiebe, Kevin Panko, mdpc, DavidPostill Jan 8 '15 at 9:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jul 26 '13 at 13:48

This question came from our site for professional and enthusiast programmers.

ffmpeg -i filename.flv -c:v libx264 -crf 19 -strict experimental filename.mp4

You must specify the video codec used. In your command you don't specify -vcodec or -c:v so ffmpeg uses the default codec for MP4 (mpeg4) which doesn't have very good compression efficiency. Try using libx264 instead and setting the CRF, which is the quality level (lower is better, default is 23, and sane values are between 18 and 28).

Encoding with libx264 is kind of complex, so you should look up the H.264 encoding guide.

You also need to specify -strict experimental otherwise you might get : " The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it."

  • 1
    This takes so much time and the resulting mp4 is very distorted, pixels lost etc.. Any ideas why that could be so? :/ – trainoasis Nov 4 '15 at 9:23
  • The default video codec for mp4 format is not necessarily mpeg4. According to the output of ffmpeg --help muxer=mp4 on my machine, ffmpeg uses h264 as mp4's default video codec. – doubleDown Dec 12 '15 at 13:18
  • 1
    @doubleDown My answer is old - from 2011. They probably changed the defaults at some point since then. – sashoalm Dec 14 '15 at 9:38

This command only changes container without reencoding

ffmpeg -i input.flv -codec copy output.mp4
  • would you know a way to make a script for batch conversion of many videos in the same folder ? – ttoine Jul 8 '15 at 9:05
  • yes, on windows create file convert.bat and put this code in it: for %%a in ("*.flv") do ffmpeg -i "%%a" -codec copy "%%~na.mp4", then execute convert.bat in folder with *.flv files – c97 Jul 8 '15 at 11:32
  • 1
    For me this throws Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument. Any ideas? :/ – trainoasis Nov 4 '15 at 9:21
  • 2
    @trainoasis your .flv does not contain H.264 video and AAC audio. Copying the audio/video data untouched with -codec copy to an .mp4 file only works in the very rare case where the audio and video are already encoded with H.264 and AAC. See superuser.com/a/1009539/390946 and addpipe.com/blog/flv-to-mp4 . – Octavian Naicu May 25 '16 at 14:17

avconv and ffmpeg are essentially the same thing. [as of VERY recently there is SOME divergence, but not really much to write home about if you compile your own ffmpeg [the one provided in Ubuntu repos for instance is OLD and suffers from that video size is not a blah blah blah deal [basically tries to tell you the video has wrong proportions], but if you bother to read the ffmpeg compile guide and compile it from git it has none of the issues of the older versions that come stock in most OSes. the depreciation warning referring to avconv is telling you that they have created a newer util to try and replace ffmpeg, BUT it is SO extensively used that even if they tried to cut it off we would all be creating softlinks from avconv to ffmpeg anyways so they are not going to stop work and drop it.]]

It is not a bad thing to use avconv, I just saw the one reply mentioning the depreciation warning which is essentially an empty message should be more of for an alternative to ffpmeg you could try avconv which is more true to the case here.

avconv -i inputfile.flv -map 0 -c:v libx264 -c:a copy outputfile.mp4

is really the SAME as

ffmpeg -i filename.flv -vcodec libvpx -acodec libvorbis

essentially in the first you are using the shorter-handed options and in the second is the more written out variety.

ALSO -map 0 is referring to audio tracks so if using something like mp4a which can handle multi audio tracks just fine you can leave this off to copy all audio streams to the resulting file. This is only required if using a codec which does not support multiple audio tracks in the same file then you would want to map the needed audio and not all. Of course if trying to minimize space used you could specify just one to try and knock a little bit of size off the file [audio is like maybe a 1/3 the size of the video track [and that's being generous]].

-c:v = codec(video) so: -c:v libx264 is same as using: -vcodec libx264 FYI; same with this example: -c:v copy = -vcodec copy

and furthermore for FLVs be careful the flv file is the same as an avi in that it is a container which can contain any number of codecs for either video or audio. You would want to first use media inspection utility of choice to see what is used within the file itself before you choose to either just copy the video and/or audio stream or if you would want to transmux it from whatever it was to something new. So the command that works best for one FLV may not be the same for another FLV [of course USUALLY if getting multiple FLVs from same source they will be encoded the same way but it is never a guarantee].

Not trying to nit pick just ran across this in web search and wanted to try to help clarify things for folks a little.

Again as this answer states for the reply below this one YES running ffmpeg will always post that message it is essentially hollow as these 2 utils are really still just the same util with very little difference. You should in almost all cases get the exact same results using either command. This is not necessarily going to result in a full re-transcode, why? A, if it is not needed it saves a ton of time, and B if you re-transcode a file it has already been compressed in to a video codec you are essentially running a compression routine against something that is already compressed and will always result in less quality than the source. Most newer codecs are somewhat cross compatible [not all] like for instance an flv could techinically be an MP4 within an FLV wrapper since FLVs like AVIs are just containers of other codecs. So, it depends on what the source flv has for the video and ausio codec compared to what you are converting it to as to whether it needs to be transcoded at all. If within the FLV they used the H264 MP4 video and MP4a for audio you would not need to re-transcode the thing you would only need to copy it out and adjust the file headers so it is read as a true MP4 instead of an MP4 video inside an FLV file.


According to this guide, the proper command to convert FLV to MP4 without any AV recoding is this:

ffmpeg -i input.flv -c copy -copyts output.mp4

It worked perfectly for me in all cases with AVC video and AAC or MP3 audio.


When using ffmpeg I got deprecation warning to use avconv. Using avconv I got nice results:

avconv -i inputfile.flv -map 0 -c:v libx264 -c:a copy outputfile.mp4

Read man avconv for more information.

  • 1
    ffmpeg itself is not deprecated. The reason it looks good is because you specify the x264 encoder which has nice default settings for quality. – slhck Mar 1 '15 at 9:33

I suggest you create a shell script for that called video_flv_to_mp4 with the following content :

ffmpeg -i $1 -sameq -ar 22050 -vcodec libx264 $1.mp4 

Then run it like this :

$ video_flv_to_mp4 video.flv

It will give you a video.flv.mp4 file.

  • 4
    -sameq is not a valid option for ffmpeg anymore. It also doesn't mean "same quality". See also this post. – slhck Mar 1 '15 at 9:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.