Intro Link to heading
I am a 40+ software engineer and recreational Jiu Jitsu practitioner, struggling with vast amount of information related to the sport. I decided to make use of my `computer` skills to aid me in the process of taming this new skill.
This post is going to demonstrate how to use mplayer for watching Jiu Jitsu instructionals, in order to:
- Capture notes
- Create bookmarks
- Create animated gifs demonstrating techniques
This post will cover the fundamentals and will be the base for future posts that will demonstrate integrations with ohter tools.
What is mplayer ? Link to heading
mplayer as the name implies is a video player. It’s free & opensource and available for most operationg systems. It’s pretty minimal but powerful and is often used by other players as a backend.
There are two main features that make it stand out from the rest of the available players.
Slave mode Link to heading
When mplayer is run on slave mode, it allows other programs to communicate with it, through a file. Programs append commands to the file and mplayer can pick them up. So, other programs can
- start / stop
- go to a specific timestamp
- extract player information
Custom key bindngs and commands Link to heading
With custom keybindings and commands users are able to easily invoke external scripts, which is very handy as we will see later on.
Why we need mplayer ? Link to heading
In previous parts in the series, we saw how we could do things like creating animated gifs. While technically it was pretty straight forward, it was not very user frindly as the user had to manually keep track of the file name and start/stop timestamps.
mplayer running on slave mode can easily helps us create a user friendly solution to this problem.
Sometimes we just want to bookmark the video currently playing so that we can resume later on. Other times we just want to have bookmarks as a reference in our notes. Again mplayer can provide an elegant solution to these problems.
Installing mplayer Link to heading
This section describes how to install it based on your operating system.
Linux Link to heading
If you are using linux chances are that you don’t really need me to tell you how to install it.
Fedora Link to heading
|
|
Ubuntu Link to heading
|
|
OSX Link to heading
|
|
Windows Link to heading
Windows users will have to install and get familiar with wsl, first. Then:
|
|
From now on all command we provide will need to go via wsl unless explicitly specified.
Slave mode Link to heading
To start mplayer in slave mode:
|
|
Now you can enter commands in the console and read the output from there.
Or you can use a fifo file instead:
|
|
However, it’s much simler if you just configure mplayer to always run in slave mode (by adding the config below to `.mplayer/config`):
|
|
This assumes that you’ve created up front a fifo file:
|
|
Note: You can use whatever path for the fifo file.
Using the slave mode Link to heading
We will start mplayer in slave mode and redirect it’s output in a temporary file so that we can process the command output:
|
|
Now we can start executing commands:
Getting the file name Link to heading
We are going to send `get_file_name` to player in order to get the file name:
|
|
Getting the timestamp Link to heading
We are going to send `get_time_pos` to player in order to get the time position:
|
|
Full list of available commands Link to heading
You can find a complete reference of commands at: http://www.mplayerhq.hu/DOCS/tech/slave.txt
Putting the commands together Link to heading
Let’s combine the commands above in order to easily create an animated gif. The idea is to have a command to:
- mark the beggining
- mark the end
- create the animated gif
The following scripts will assume that the fifo file can be found at: `~/.local/share/mplayer/fifo` and the output is redirected to `~/.local/share/mplayer/output`.
Mark the beggining of a subsection Link to heading
We can use the slave mode in order to ask the player which file is currently playing and which is the currrent position in the file. We will save those under `.local/share/mplayer/filename` and `.local/share/mplayer/beginning`.
|
|
Mark the end of a subsection Link to heading
In the same spirit we can use `.local/share/mplayer/end` in order to mark the end of a subsection.
|
|
Bookmarking Link to heading
The scripts above pretty much create bookmarks to the beginning and the end of a section within the video. So, we can use those bookmarks to resume playback to the desired bookmark. Let’s see how we can create a small script that will read `.local/share/mplayer/beginning` and `.local/share/mplayer/end` to resume playback.
|
|
Create an animated gif Link to heading
|
|
Key bindings Link to heading
It’s possible to define custom keybindings so that we assign bindings for the commands we created. mplayer allows users to define bindings via the `.mplayer/input.conf`.
For example:
|
|
This will save the path of the currently played file each time `CTRL-f` is pressed.
Using custom key bindings to create animated gifs Link to heading
Let’s combine the commands created so far with keybindings so that we can invoke them directly from the player:
|
|
Thoughts Link to heading
So far we’ve seen how we can easily split really large instructionals in smaller chunks, how to use our player in order to bookmark/resume playback and how to easily create animated gifs. Most importantly we’ve seen how to interact with the player from external projects, which opens up the way for many different integrations. Future posts in the series will focus on the note taking part which in my opinion is really important in the process of studying Jiu Jitsu.
Post index Link to heading
- Hackers guide to Jiu Jitsu: intro wordpress version github version
- Hackers guide to Jiu Jitsu: ffmpeg wordpress version github version
- Hackers guide to Jiu Jitsu: mplayer wordpress version github version
- Hackers guide to Jiu Jitsu: markdown wiki wordpress version github version
- Hackers guide to Jiu Jitsu: flowcharts wordpress version github version