How To install and encode with mpv-webm script in MPV in Windows and Linux

One of the most important features of MPV is the support of various scripts and plugins. Developers can add additional features, make it easier and more convenient. In this article we will look at the installation and configuration of mpv-webm script, which allows us to encode a fragment of a video in webm and mp4 format right inside MPV itself!

Let’s do it!

At first we should download a script. Follow this link:

https://github.com/ekisu/mpv-webm/tree/master/build

Then follow this instructions:

  1. Click on “webm.lua
  2. Then in the upper right corner click “Raw”
  3. After the script text appears right click and “Save page as…”
  4. Then save it as webm.lua and put it in your scripts directory, see directory location below:

For Linux users: ~/.config/mpv/scripts/

and for Windows users: C:\users{USERNAME}\AppData\Roaming\mpv\scripts\

or it may be directory where mpv is installed: C:\Program Files\mpv\scripts

Let’s make sure it works.

Open any video in MPV, pause it and then press Shift + W

If it works, the script menu will appear as on the picture below.

Mpv-webm main menu. You can just press Shift + w to enter into it
Main menu of mpv-webm. It can be called by pressing Shift + W

How many options!

What is crop? We can crop a video by width and height. So, you can select a particular object in the scene. Press c to follow to crop menu. Here’s what it looks like:

Set point a and point b then press enter to confirm
Video Crop Menu

It is based on the position of your cursor. Coordinates are taken from the cursor. Place your cursor somewhere on the top left and press 1. Coordinates saved. Then move cursor somewhere bottom right and press 2. The coordinates of the second point are saved. You see how it works. To reset the coordinates on any of the stages, press r. When done, press Enter to save the parameters(confirm crop) or press Escape to refuse this option(cancel crop).

Mpv-webm main menu. You can just press Shift + w to enter into it
Main menu, again

To select a fragment from a video, jump to the supposed start and press 1 then jump to the supposed end and press 2. So we set the start and end point of a video fragment. We can reset these parameters at any time by pressing 1 and 2.

Create your webm fragment by setting the time with keys 1 and 2
Determine video fragment by timeline setting

Press o and we will see a list of options. I recommend always to use two passes, this increases the quality of the video, but the encoding takes longer

Options of mpv-webm. Here are all the basic settings that affect the coding process.
Options. Just another menu of mpv-webm. I recommend always to use two passes.

As you can see, this script is capable to encode not only vp8 codec.

You can also choose h264 in output video format
Creating .mp4 videos with mpv-webm
You can encode your webm with using VP9 codec
VP9 encoding is also available.

When finished with the settings, press Enter to save options. Then we’ll return to the main menu.

Mpv-webm main menu. You can just press Shift + w to enter into it
Main menu, press e to start encoding process

Press e and the encoding process will begin. If you set two passes in options, the process passes through 2 stages. I.e. You wait once when the digit increases to 100 percent, and then the second. So, you’re waiting for 200% instead of 100% with two passes set. On my four core processor, the script runs on four threads. But it can be changed in the script code, by searching for the keyword “threads”.

set our own value for threads count in mpv-webm script
Number of threads in mpv-webm

If you don’t want processor to work at full power, change this number to less. I chose the number 1. This is a good script that automates the boring process with simple and clear keyboard shortcuts. Good luck and have fun.

2 Comments

Add a Comment
  1. Neat, clear, quick & dirty intro to mpv scripting. Tnx!

    1. Tnx. I will try to make it better

Leave a Reply

Your email address will not be published.