How to Use the Command 'mpv' (with Examples)

How to Use the Command 'mpv' (with Examples)

MPV is a versatile and powerful media player based on MPlayer, offering efficient playback of both audio and video files. It supports various file formats and media types, making it a popular choice among users who require a robust media-playing experience. MPV can be operated through command-line instructions, allowing for precise control over media playback, speed adjustments, and other advanced features suitable for users and developers alike.

Use case 1: Play a video or audio from a URL or file

Code:

mpv url|path/to/file

Motivation:

You might want to play a media file directly from your computer or stream content from an online source without using a graphical interface. MPV provides the flexibility to do this using a simple command. This is particularly useful for users who prefer using the terminal or need to automate media playback as part of a larger script.

Explanation:

  • mpv: This is the command for the MPV media player.
  • url|path/to/file: This argument accepts either a URL, which can be an online stream, or a direct path to a media file stored on your local machine. Providing either type means MPV will begin playback immediately after the command is executed.

Example Output:

Upon executing the command, MPV’s window opens, and the video or audio begins to play. You’ll see the window displaying the media content without any traditional player interface controls unless specified in configuration or keybindings.

Use case 2: Jump backward/forward 5 seconds

Code:

LEFT <or> RIGHT

Motivation:

While watching a video or listening to audio, you might miss something crucial or want to repeat a segment. MPV allows for quick rewinds or forwards by a small margin (5 seconds), facilitating an efficient way to navigate through the content without needing to use a mouse or additional controls.

Explanation:

  • LEFT: Pressing this key while the MPV window is in focus will jump back by 5 seconds in the currently playing media.
  • RIGHT: Pressing this key will advance the playback by 5 seconds.

Example Output:

The video jumps backward or forward, skipping the specified amount of time and continuing playback from the new timestamp.

Use case 3: Jump backward/forward 1 minute

Code:

DOWN <or> UP

Motivation:

Sometimes, a larger segment needs to be navigated quickly, such as skipping commercial breaks or less engaging content. MPV lets you skip forward or backward by a minute, streamlining the navigation process within longer media files.

Explanation:

  • DOWN: Pressing this key skips the playback 1 minute backward.
  • UP: Pressing this key skips the playback 1 minute forward.

Example Output:

Upon pressing the respective key, the media timeline adjusts by a minute in the instructed direction and resumes playing from the new point.

Use case 4: Decrease or increase playback speed by 10%

Code:

[ <or> ]

Motivation:

Changing the playback speed can be particularly useful when reviewing content for detail, speeding through familiar areas, or for playback in educational or professional settings where controlling the speed can enhance information absorption.

Explanation:

  • [: Pressing this key decreases the playback speed by 10%, slowing down the media.
  • ]: Pressing this key increases the playback speed by 10%, speeding up the media.

Example Output:

Media plays at the adjusted speed immediately. If playback speed was decreased, dialog and actions occur slower, and the reverse happens if increased.

Use case 5: Take a screenshot of the current frame

Code:

s

Motivation:

Capturing still frames from videos can be useful for creating thumbnails, documenting or referencing a scene, or even for analysis in media studies. MPV allows users to take screenshots of the current frame easily.

Explanation:

  • s: With the MPV window in focus, pressing this key saves a screenshot of the currently displayed media frame, typically in the working directory with a filename format like mpv-shotNNNN.jpg.

Example Output:

After pressing ’s’, an image file (e.g., mpv-shot0001.jpg) appears in the directory where the MPV command was executed, capturing the exact frame displayed at that moment.

Use case 6: Play a file at a specified speed

Code:

mpv --speed 0.01..100 path/to/file

Motivation:

Sometimes precise control over playback speed is necessary, whether for in-depth analysis, creative editing, or when synchronizing media as part of a presentation. MPV offers this functionality through command-line options.

Explanation:

  • mpv: Initiates the media player.
  • --speed 0.01..100: Specifies the playback speed. Values less than 1 slow down playback, while values greater than 1 speed it up, allowing for a vast range of speed adjustments.
  • path/to/file: Directs MPV to the specific media file you wish to play.

Example Output:

Playback starts at the specified speed, affecting both audio and visual timelines in correspondence to the value provided, rendering the experience at the selected speed rate.

Use case 7: Play a file using a profile defined in the mpv.conf file

Code:

mpv --profile profile_name path/to/file

Motivation:

Using profiles defined in an MPV configuration file allows for applying a specific set of settings customized for different types of content or playback scenarios. This is useful for users who require specific audio-video configurations without manually adjusting them each time.

Explanation:

  • mpv: Initiates the MPV player.
  • --profile profile_name: Instructs MPV to use a specific profile from its configuration file, where individualized settings can be predefined.
  • path/to/file: Indicates the media file to be played with the designated settings.

Example Output:

The media is played incorporating all the settings specified in the profile_name, which might include adjustments to audio channels, video outputs, or other media attributes.

Use case 8: Display the output of a webcam or other video input device

Code:

mpv /dev/video0

Motivation:

MPV’s capability to render a webcam or video device stream could be advantageous in setups requiring video input visualization, such as monitoring, recording, or display in live presentation environments.

Explanation:

  • mpv: Starts the media player.
  • /dev/video0: Refers to the standard Linux path for video devices. This designates MPV to capture and display the feed from the first video source connected to the system.

Example Output:

MPV opens a new window displaying a live feed from the webcam or connected video source, updated in real-time as captured from the device.

Conclusion:

MPV provides a powerful, efficient media playback experience through its versatile command-line operations. Whether you’re playing local or streaming media, capturing screenshots, adjusting playback speed, or even displaying live video input, MPV covers a broad array of use cases, proving itself as an indispensable tool for both casual and proficient users.

Related Posts

How to Use the Command 'git rebase-patch' (with Examples)

How to Use the Command 'git rebase-patch' (with Examples)

The git rebase-patch command is a handy tool that is part of the git-extras toolkit.

Read More
How to use the command 'webpack' (with examples)

How to use the command 'webpack' (with examples)

Webpack is a static module bundler for modern JavaScript applications. It takes modules with dependencies and generates static assets representing those modules.

Read More
How to Use the Command 'doctl databases replica' (with examples)

How to Use the Command 'doctl databases replica' (with examples)

The doctl databases replica command is a component of the DigitalOcean command line tool (doctl) that allows users to manage read-only replicas associated with a database cluster.

Read More