0

I know its a "lame" question, but: lets say, I have a wmv, avi, etc BIG file. I want to convert it to .MP4, with the possible smallest file size, and of course with the same quality with audio/video. How to? What codec should I use? Im using FFmpeg

  • 1
    You... can't. Shrinking the file will reduce quality. This is how video files are made smaller. H.264 is an encoding that has the least-noticeable quality loss. – Darth Android Jun 26 '15 at 21:09
5

You can try to encode with libx264 crf 18. It is well known for producing a (arguably) "visually lossless" result.

ffmpeg -i input.avi -vcodec libx264 -x264-params crf=18 -preset veryslow -acodec copy out.mp4

Notice that I used a veryslow preset which will give you the smallest file possible. Also, I decided to copy the audio track instead of reencoding it, mainly because I assume it's already AAC/MP3 stereo in your sample.

If the output is too big for you, try with a higher crf value (up to 23) but the quality will suffer.

  • Why suggest using -x264-params crf=18 instead of simply -crf 18? – llogan Jun 28 '15 at 6:57
  • Old habits die hard. – Ely Jun 28 '15 at 12:02
4

Getting the smallest video with the least amount of quality lost is more of a challenge than anything else. There are guides scattered among the Web that will recommend you settings to use on FFmpeg for things like game captures, streams, DVD rips, etc.

If you want lossless lossless, try this:

ffmpeg -i input.mp4 -c:v libx264 -crf 0 output.mp4

The important part is the -crf 0 part which sets it to lossless. However, the output file will generally be very large. You could change it to -crf 18 which would give you something that is acceptable in quality and free from most artifacts.

  • FYI - according to the FFmpeg wiki - using -qp 0 is recommended for lossless libx264 over -crf 0 due to some difference between 8bit and 10bit x264. Probably not a big deal either way, but I've defaulted to using -qp 0 with good results. That all said, it is not truly "lossless"... There are minute differences between the libx264 outputs and the originals that generated them. Impossible to see with the naked eye, but they are measurable differences... - For above wiki reference, see: trac.ffmpeg.org/wiki/Encode/H.264#LosslessH.264 – occvtech Jul 1 '15 at 15:43
  • I don't know where you got that last part, but x264 lossless is mathematically lossless. Try running an md5sum on a raw input and the decoded lossless H.264 stream, they'll be identical. – Ely Jul 2 '15 at 1:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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