Script to get the timestamps, cropping coordinates, and file path of the playing video, for ffmpeg, all from within mpv.
The script currently only supports Linux, and depends on xclip
or wl-clipboard
to copy the data to the primary/clipboard selections. To install, change directory to your mpv scripts folder, and git clone this repository. An appropriate folder will be created:
$ cd ~/.config/mpv/scripts
$ git clone https://github.com/4ndrs/PureMPV.git
Or if just the script is preferred without downloading the whole source code, downloading the main.js
file from the repository (or one of GitHub's automatic releases) and putting it in your mpv scripts folder is enough.
Note: the main.js
in the repository does not get updated on every commit. For a bleeding-edge release of the file, click here, or if cloned, see Building.
It would probably be advisable to rename the main.js
file when downloaded individually to avoid conflicts with other scripts in the folder.
usage_preview.webm
The script by default registers the start and end times by pressing ctrl + e, and waits until the user presses ctrl + w to copy the data to the primary selection.
The script can copy the following by default (PureMode):
- Start & end time - ctrl + e
- End time - ctrl + shift + e
- Cropping coordinates - c
- File path - ctrl + w
To copy in this mode, triggering the file path combination is necessary. If none of the above key combinations are omitted (or cancelled), the copied string will be formatted like the following:
ffmpeg -ss hh:mm:ss -to hh:mm:ss -i "/path/to/file" -lavfi crop=w:h:x:y
When omitting key combinations, the resulting string will have the values omitted as well, for example triggering just start time, and then the file path will yield the following string:
ffmpeg -ss hh:mm:ss -i "/path/to/file"
To get just the end time the ctrl+shift+e key combination must be pressed with PureMode activated.
The default mode, and the selection to copy to can be changed creating a configuration file under $HOME/.config/mpv/script-opts/
with the name PureMPV.conf, and inserting the following:
pure_mode=no
selection=clipboard
With the PureMode deactivated, the script will copy the resulting value of the key combination right away, without "ffmpeg -i", for example triggering ctrl + e will copy just the current timestamp, the ctrl + w will copy just the file path, and c will copy just the cropping coordinates.
Cropping coordinates, and set start & end times, can be cancelled by pressing their own key combination a third time.
A preview of the currently set settings can be generated pressing ctrl+shift+w in PureMode.
Output seeking can be enabled inserting input_seeking=no
in the configuration file.
To crop, it is necessary to put the mouse pointer in the starting position of the crop. After that, pressing the keybinding c will start the cropping mode; position the mouse to the desired location to generate the cropping coordinates. To stop the cropping mode, press the keybinding again. The cropbox will be set if PureMode is on, and just copied if it is off.
Other scripts can access PureMPV's internal data (cropbox and timestamps), which is available using mpv's user-data
property. It can be requested any time using mp.get_property_native("user-data/PureMPV")
. The returned object will have the following properties:
interface PureMPVData {
cropbox: {
w: number | null;
h: number | null;
x: number | null;
y: number | null;
};
timestamps: {
start: string | null;
end: string | null;
};
}
An example of its usage can be seen in pwebm-helper, which uses PureMPV's data to encode video segments.
Keybinding | Name | Action |
---|---|---|
ctrl + p | toggle-puremode |
Activate/deactivate PureMode. |
ctrl + w | get-file-path |
Copy the file path with no formatting. PureMode: copy the currently set parameters formatted with ffmpeg. |
ctrl + shift + w | generate-preview |
PureMode: Generate a preview of the currently set parameters. |
ctrl + e | get-timestamp |
Copy the current time position with the format HH:MM:SS. PureMode: Set the start time parameter if it is not set to the current time position, otherwise set the end time. |
ctrl + shift + e | set-endtime |
PureMode: Set the end time parameter regardless of whether start time is set or not. |
c | get-crop |
Trigger cropping mode, and copy the cropped coordinates in the format W:H:X:Y. PureMode: Trigger cropping mode, and set the cropbox parameter. |
Keybindings can be changed using the names in this table and modifying your input.conf
, or changing the relevant option key in the configuration file.
The configuration file is located in $HOME/.config/mpv/script-opts/PureMPV.conf
, and with it, it is possible to change the following options:
Option key | Values | Details |
---|---|---|
pure_mode | yes no |
Specifies if PureMode will be activated when running. Default is yes. |
executable | executable | Specifies which program to prepend to the copied string in PureMode. Default is ffmpeg. |
ffmpeg_params | params | Specifies which params to append to the copied string. Default is empty. |
selection | primary clipboard |
Specifies where to copy the string. Default is primary. |
copy_utility | detect xclip wl-copy |
Specifies which utility to use to copy the string. Default is detect. |
hide_osc_on_crop | yes no |
Specifies if the OSC (On Screen Controller) should be hidden when cropping. Default is no. |
input_seeking | yes no |
Specifies if input seeking should be assumed when formatting the timestamps with the inputs. Default is yes. |
box_color | hex color | Specifies the color of the cropbox represented as an #RRGGBB hexadecimal value. Default is #FF1493. |
Option key | Details |
---|---|
key_crop | default: c |
key_preview | default: ctrl+shift+w |
key_pure_mode | default: ctrl+p |
key_file_path | default: ctrl+w |
key_timestamp | default: ctrl+e |
key_timestamp_end | default: ctrl+shift+e |
An example of the content of a configuration file could be the following:
# ~/.config/mpv/script-opts/PureMPV.conf
executable=ffmpeg
pure_mode=yes
selection=primary
input_seeking=yes
hide_osc_on_crop=yes
ffmpeg_params=-map_metadata -1 -map_chapters -1 -f webm -row-mt 1 -speed 0 -c:v libvpx-vp9 -map 0:v -crf 10 -b:v 0 -pass 1 /dev/null -y&&\
key_crop=ctrl+c
For building, having npm installed is necessary. To generate the main.js
file with the latest changes, proceed with the following:
$ npm ci
$ npm run build