I have got a WMV (v9 (WMV3), 960x720, 30.000030 fps, planar 4:2:0 YUV, produced by PowerPoint 2010) file and need to convert it to MPEG2 - the only format my TVset can read from an USB flash drive (I have also tried MP4/h.264, AVI/XVID - nothing but MPEG2 works).

I have managed to to the job with simple

ffmpeg -i "in.wmv" -c:v mpeg2video "out.mpg"

but the quality of the result is dreadful (clearly visible visual distortions are introduced) and the playback is not smooth (too slow at some moments).

I have also tried

ffmpeg -i "in.wmv" -c:v mpeg2video -pix_fmt yuv420p -me_method epzs -threads 4 -r 30.000030 -g 45 -bf 2 -trellis 2 -cmp 2 -subcmp 2 -s 960x720 -b 2500k -bt 300k -async 1 -y "out.mpg"

(I have found this somewhere in the Internet and modified a little bit - changed the resoultion, the refresh rate and the output format (from VOB to bare MPG)) succesfully but the quality is still too bad.

What parameters do I have to use to save as much quality as possible? Compression ratio doesn't matter at all, even increase in file size is acceptable.

Anther thing I actually need (I have chosen not to include it in the question title to avoid making it too specific but I'd appreciate it being considered in the answers) is adding pure silence as a sound track - there is no sound in the original but the TV set complains about it and I'd like to get rid of this complain. I have generated a same-length (second-precise) silence OGG Vorbis file using Audacity but I can't manage to merge it with the video:

ffmpeg -i in.mpg -i silence.ogg -c:v copy -c:a libmp3lame out.mpg

and even bare

ffmpeg -i in.mpg -c:v copy -out.mpg

gives "buffer underflow" and "packet too large" errors. (in.mpg are the files produced by the same FFMPEG binary and the same source WMV file using the first two commands in the question).

I am using a Zeranoe FFMPEG build on Windows 7.

  • 1
    Someone is going to ask you for a full output log. – dstob Nov 4 '14 at 18:01
  • What TV set exactly? It might be able to read H.264, just a different profile. – slhck Nov 4 '14 at 18:06
  • @slhck The TV set is Philips 42PFL3606H/58, I am encoding to H.264 with ffmpeg -i "in.wmv" -sws_flags lanczos+accurate_rnd -c:v libx264 -crf 20 -preset slow -profile:v baseline -level 3.0 -pix_fmt yuv420p -tune fastdecode -x264-params keyint=240:min-keyint=20 "out.mp4" - the profile is the lowest I know and even more tweaks are used to make playing the resulting file an easier task. – Ivan Nov 4 '14 at 18:29
  • 1
    According to the manual the TV supports MPEG-4 Visual and H.264. If Baseline profile doesn't work, I'm not sure what does. But TVs are very picky. – slhck Nov 4 '14 at 18:45

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.

  • "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." - may I just make every frame a B-frame and use no motion estimation with MPEG2? The video has a lot of VERY dynamic parts. – Ivan Nov 5 '14 at 2:46
  • I have tried the first command line you suggest (ffmpeg -i "in.wmv" -f lavfi -i aevalsrc=0 -shortest -c:v libxvid -qscale:v 2 -c:a libmp3lame "out.mp4") - it encodes about 100 frames and then starts flooding the screen with errors like [mpeg @ 02f69ba0] buffer underflow i=0 bufi=235538 size=239761 and [mpeg @ 02f69ba0] packet too large, ignoring buffer limits to mux it. – Ivan Nov 5 '14 at 2:48
  • @Ivan You change the bitrate with -b:v. Added it to my answer. Regarding the encoder settings: You can't make every frame a B-frame. Also, you need motion estimation – the more exhaustive the method, the better the compression. But if it's a dynamic video, the first thing you will want is increase the bitrate significantly. The encoding settings really do not have much of an impact. As for your error, are you sure this is the error to the correct command? An [mpeg] error can only happen if your output file is .mpg, not when it's .mp4. – slhck Nov 5 '14 at 8:15
  • I have copy=pasted a wrong part, @slhck, I am using ffmpeg -i "in.wmv" -f lavfi -i aevalsrc=0 -shortest -c:v mpeg2video -qscale:v 2 -c:a libmp3lame "out.mpg" of course. – Ivan Nov 5 '14 at 10:13
  • 1
    -target pal-dvd solves the problem, -bufsize dosn't work (I have tried -b:v 7M -bufsize 7M -maxrate 7M). – Ivan Nov 5 '14 at 12:43

I would immediately say if file-size doesn't really matter then just experiment with increasing the bit-rate.

For the silent audio you may just want to use ffmpeg, I do not know enough about Audacity to give any sort of comment. I have used this before.

ffmpeg.exe -f lavfi -i aevalsrc=0:0::duration=YOUR_DESIRED_DURATION -ab 10k YourAudioName.aac

This won't work for you though since you are using mpg container so you may want to try.(mp3 container)

ffmpeg.exe -f lavfi -i aevalsrc=0:0::duration=YOUR_DESIRED_DURATION -ab 10k YourAudioName.mp3

It seemed to work for me.

  • Setting the duration is not necessary, as ffmpeg will just use whatever is necessary for the video. – slhck Nov 4 '14 at 18:25
  • I kept things to the two step process as Ivan had done. If you leave out the duration in my command then I do not know how long ffmpeg would run (likely longer than you would want). – dstob Nov 4 '14 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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