Linux Tutorial Blog

Your regular Linux tutorial source!

Solution: Creating an mpeg with mencoder that plays on Windows Media Player

rechosen | 24 May, 2007 15:27

This solution contains some options for the mencoder command that will result in an mpeg video file that will play on pretty much all players, even Windows Media Player.

This has been tested with Windows Media Player 6.4 and 10. If you can confirm that it also works on other versions (or if it doesn't work), please leave a comment.

A simple example

Let's have a look at a rather simple mencoder command that should create a WMP-compatible MPEG file:

[rechosen@localhost ~]$  mencoder <input> -oac lavc -ovc lavc -lavcopts acodec=mp2:vcodec=mpeg2video:mbd=1:vbitrate=1800 -of mpeg -o <outputfile>

Replace "<input>" with the video source (for example a file or a DVD scene) and "<outputfile>" with the file you want the output to be written to (e.g. "samplemovie.mpg" or "dvdbackup.mpeg"). You can also replace the value after "vbitrate=" with a higher or lower bitrate, depending on the desired quality of the outputfile (you could also leave it away entirely, but it will then default to 800, which is quite low and therefore pretty much only suitable for very low resolution movies).

Note that the above example will try to encode the movie at the same resolution and fps as the source. However, this does not always work correctly and also isn't always what you want. Furthermore, the above example doesn't use two-pass encoding. Two-pass encoding is useful because it results in a higher quality outputfile with about the same size (it needs to read the source twice, though).

A more feature-rich example

The next example features rescaling (adapting the resolution), specifies a framerate for the outputfile and encodes in two passes.

[rechosen@localhost ~]$  for i in {1,2}; do mencoder <input> -oac lavc -ovc lavc -lavcopts acodec=mp2:vcodec=mpeg2video:mbd=1:vpass=$i:vbitrate=1800 -of mpeg -ofps 25 -vf scale=640:480 -o <outputfile>; done

Replace "<input>" with any source that can be read twice (a file or a DVD scene) and "<outputfile>" with the file you want the encoded data to be written to. You can alter the values after "-ofps=" and "-vf scale=" to change the framerate and the resolution of the outputfile, respectively (and of course you can alter the vbitrate again, too).

One more handy trick: you can set only the width of the encoded video and let mencoder determine the height, keeping the right aspect ratio:

[rechosen@localhost ~]$  for i in {1,2}; do mencoder <input> -oac lavc -ovc lavc -lavcopts acodec=mp2:vcodec=mpeg2video:mbd=1:vpass=$i:vbitrate=1800 -of mpeg -ofps 25 -vf scale -zoom -xy 640 -o <outputfile>; done

Again, replace "<input>" with any source that can be read twice (a file or a DVD scene) and "<outputfile>" with the file you want the encoded data to be written to. You can alter the value after "-ofps=" again to change the framerate of the outputted data, and after "-zoom -xy " is the value to change if you want a different width (note that values less than or equal to 8 will be interpreted as scaling factors, not as the width of the outputted video).

Disclaimer:

I do not guarantee that this works as told. All information in this article is provided as-is, without any warranty.

That was the legal stuff =). If it didn't work for you, or if I'm doing something that's considered bad practice, please leave a comment! I'll be glad to try to help you or to correct what I did wrong.

Comments

Re: Solution: Creating an mpeg with mencoder that plays on Windows Media Player

re | 02/03/2009, 08:12

It might work if an mpeg2 video codec is installed. Unfortunately, it does not come with Windows XP.

http://lists.mplayerhq.hu/pipermail/mencoder-users/2006-November/004570.html

News Media

News Media | 06/03/2009, 08:25

Its a better solution on to support more than one platform. If it support MPEG file with Media player 10 then it is more valuable for me.

Add comment

(optional, will not be published)
(optional)

<><