How to make an MPEG2 video file with the highest quality possible using FFMPEG?

Solution 1:

The problem is that the default bitrate for the MPEG-2 is rather low (as with most other video encoders in ffmpeg, the H.264 one being an exception). MPEG-2 is also not the best choice as a codec these days.

Better quality for MPEG-2

You have a few options if you want to stick with MPEG-2:

  • Increase the bitrate. You're now using -b:v 2500k. If it's HD video, you will not get far with only 2.5 MBit/s. You need at least double that or even more to make the result look good. For example, use -b:v 6000k -target pal-dvd.

    For 720p, I think that you should still use a higher bitrate. Remember that DVDs use MPEG-2 and come in about 4.7 GB for 2hrs of movie, so you end up with around 5–8 MBit/s. MPEG-2 is really not very compression-efficient and works better at higher bitrates.

  • Use a specific quality setting. Change -b:v … to -qscale:v 2. The number here ranges from 1 to 31 and higher means lower quality. There's no point going beyond 4 or 5. If you don't care for the bitrate start with 2 and see if that works for you.

Messing with the number of B-frames, motion estimation method or GOP size may tweak the quality a little but won't result in big changes.

Silent audio

Use -f lavfi -i aevalsrc=0 to generate a silent audio stream. For example:

ffmpeg -i "in.wmv" -f lavfi -i aevalsrc=0 -shortest -c:v mpeg2video -qscale:v 2 -c:a libmp3lame "out.mpg"

You may need to add -target pal-dvd to the above command to force a certain buffer size.

I chose MP3 as codec. MPEG files cannot contain audio other than MPEG Layer I and II audio as well as PCM streams, so using a silent Ogg Vorbis file will not work unless you convert the audio stream as well (which is not what you're doing when you use -c:a copy).

Use a different video codec

I'm surprised that a TV that plays video files will read MPEG-2 but not anything else. At least MPEG-4 Part II video should be supported (that's what you know as "DivX" – an MPEG-4 Part II encoder). So you could try:

ffmpeg -i "in.wmv" -f lavfi -i aevalsrc=0 -shortest -c:v libxvid -qscale:v 2 -c:a libmp3lame "out.mp4"

Your TV might actually also support H.264, but only a certain profile. Try using the baseline profile, for example:

ffmpeg -i "in.wmv" -f lavfi -i aevalsrc=0 -shortest -c:v libx264 -profile:v baseline -crf 23 -c:a aac -strict experimental "out.mp4"

In the above example I've used the CRF option to set the quality instead of qscale. See the H.264 encoding guide for more.