Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

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

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

5 Answers 5

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.

share|improve this answer

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.

share|improve this answer

I use this command, it only changes container without reencoding

ffmpeg -i input.flv -vcodec copy -acodec copy output.mp4
share|improve this answer

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.

share|improve this answer
ffmpeg -i filename.flv -qscale 0 -ar 22050 -vcodec libx264 filename.mp4

You must specify the video codec used. In your command you don't specify -vcodec so ffmpeg uses the default codec for MP4 which doesn't have very good compression. Try using libx264 instead.

share|improve this answer
2  
-vcodec libx264 –  Xeoncross Aug 21 '12 at 18:03
4  
-qscale has no effect for libx264 – this is wrong. You'd need to use -crf instead if you want variable bitrate. –  slhck Jul 26 '13 at 6:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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