February 6, 2023

mpv

The mpv program is a great media player.

Really, you should definetly try it.

I use it most of the times to play audio, but it supports videos as well.

You just use it like this:

mpv file.mp3

That’s it.

It’s scriptable and supports a large number of formats.

Cool features I didn’t know

There are some killer features I wasn’t aware I found in the man page.

Resuming playback

Sometimes it’s nice to resume playing from where you left off, expecially whith long tracks or movies.

In mpv the watch later feature does just that.

The manual says:

RESUMING PLAYBACK

mpv is capable of storing the playback position of the currently
playing file and resume from there the next time that file is played.
This is done with the commands quit-watch-later (bound to Shift+Q by
default) and write-watch-later-config, and with the
--save-position-on-quit option.

The difference between always quitting with a key bound to
quit-watch-later and using --save-position-on-quit is that the latter
will save the playback position even when mpv is closed with a method
other than a keybinding, for example if you shutdown your system
without closing mpv beforehand, unless of course mpv is terminated
abruptly and doesn't have the time to save (e.g. with the KILL Unix
signal).

mpv also stores options other than the playback position when they have
been modified after playback began, for example the volume and the
fullscreen state, and restores their values the next time the file is
played. Which options are saved can be configured with the
--watch-later-options option.

When playing multiple playlist entries, mpv checks if one them has a
resume config file associated, and if it finds one it restarts playback
from it. For example, if you use quit-watch-later on the 5th episode of
a show, and later play all the episodes, mpv will automatically resume
playback from episode 5.

More options to configure this functionality are listed in Watch Later.

Basically you can tell mpv to remember where to start when playing a file again. It stores the position when exiting in a file named as a hash in a specific directory (~/.config/mpv/watch_later).

You can exit using Q, use the --save-position-on-quit or put it in the configuration file to enable it permanently.

Controlling when to start and end playing

To tell mpv when to start and optionally stop reproducing a file there are the --start, --stopand --length options.

Here’s a man page extract about them:

Playback Control

   --start=<relative time>
          Seek to given time position.

          The general format for times is [+|-][[hh:]mm:]ss[.ms]. If the
          time is prefixed with -, the time is considered relative from
          the end of the file (as signaled by the demuxer/the file). A +
          is usually ignored (but see below).

          The following alternative time specifications are recognized:

          pp% seeks to percent position pp (0-100).

          #c seeks to chapter number c. (Chapters start from 1.)

          none resets any previously set option (useful for libmpv).

          If --rebase-start-time=no is given, then prefixing times with +
          makes the time relative to the start of the file. A timestamp
          without prefix is considered an absolute time, i.e. should seek
          to a frame with a timestamp as the file contains it. As a bug,
          but also a hidden feature, putting 1 or more spaces before the +
          or - always interprets the time as absolute, which can be used
          to seek to negative timestamps (useful for debugging at most).

             Examples

             --start=+56, --start=00:56
                    Seeks to the start time + 56 seconds.

             --start=-56, --start=-00:56
                    Seeks to the end time - 56 seconds.

             --start=01:10:00
                    Seeks to 1 hour 10 min.

             --start=50%
                    Seeks to the middle of the file.

             --start=30 --end=40
                    Seeks to 30 seconds, plays 10 seconds, and exits.

             --start=-3:20 --length=10
                    Seeks to 3 minutes and 20 seconds before the end of
                    the file, plays 10 seconds, and exits.

             --start='#2' --end='#4'
                    Plays chapters 2 and 3, and exits.

It’ pretty cool, and I guess it’s also used internally by the watch-later feature.

Playing remote stuff

You can play something directly from an URI, just call it with it’s url like this:

mpv "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

All the features are available as far as I can tell.

© Mauro Scomparin 2020 - 2023

Powered by Hugo & Kiss.