Visually Create Video Clips with mpv, FFmpeg and a Lua Extension

We'll take advantage of using temporary mpv chapter markers and FFmpeg to avoid needing to re-encode the video.
Want to jump straight to the demo video? Here it is on YouTube.
I’m a big fan of using mpv for playing back videos and viewing images. Now I also use it to quickly cut up videos to create clips in seconds thanks to its Lua extension feature.
Years ago I wrote a shell script around FFmpeg to create clips on the command
line.
It has served me well for quickly creating video clips. The TL;DR is you can
supply the file name, time stamp range and a clip suffix (such as -1, -2)
and it will create separate video files.
Near the end of 2025 I switched to using Linux on the desktop and really focused on the idea of not making compromises for workflows I do regularly. The CLI script worked nicely but after I discovered how good and customizable mpv is I thought to myself “what if I combined mpv and FFmpeg to do this visually?”.
The mpv extension requires no dependencies other than FFmpeg.
# How it Works
It’s powered by an mpv custom Lua script, here’s the high level pieces:
- mpv chapter markers
- Visual indicators that let you mark points on the seek bar
- This is IMO more user friendly to use than A/B points but both would work
- 4 custom key binds
- One to set the chapter “start” mark
- One to set the chapter “end” mark
- One to create the clip between the start and end markers
- One to clear all markers (optional but nice to have)
- FFmpeg
- Quickly create the clip without re-encoding the video
- Called when pressing the create clip key bind
If you’re using DotFriedRice you already have access to the extension.
If you’re not using DotFriedRice you can get the extension
here
and place it in ~/.config/mpv/scripts/mkclip.lua, then set these key binds in
your ~/.config/mpv/input.conf to use it. You can of course customize the
keys:
F1 script-binding mkclip_mark_start
F2 script-binding mkclip_mark_end
F3 script-binding mkclip_create
F4 script-binding mkclip_clear_marks
# Quality of Life Features
I’ve created tons of clips with it and landed on the following features:
If the video is playing and you press F1 to start a mark, the video will continue playing. This is handy because chances are you want to set a stop mark X seconds afterwards. You can continue pressing F1 to overwrite the previous start mark too.
If the video is playing and you press F2 to end a mark, the video will stop because now your intent is likely to create the clip. The clip isn’t automatically created because you might want to adjust your markers first while the video is stopped.
Whenever a start or end mark is created, an on-screen-display message will show you the time stamp and if you have both a start and end it will show you the duration so you know how long the clip will be.
While there’s dedicated keys to have a start and end marker, behind the scenes the script will allow you to set the end time before the start time. Really this gives you the end game solution of having 2 markers to create a range. The order of the markers doesn’t matter, this is nice because your brain only needs to see the visual markers and you know for sure the clip will be created within that range.
It uses your original file name and appends -1, -2, etc. to the end of the
file name. There’s also multiple layers of defense to avoid ever accidentally
overwriting your original file in case the script ever contains a bug with this
logic.
It also sets the clip’s create and modified time to match the original clip. This way if you have 1 big directory of videos sorted by last modified, the clips you create from the original video will retain their original timestamp.
I’m really happy with this. It’s another example of molding your tools to your liking, mpv is a gift that keeps on giving.
The video below shows how it all works and briefly goes over the code.
# Demo Video
Timestamps
- 0:18 – Visually create clips in mpv
- 1:34 – Taking a look at the key binds
- 1:52 – Going over the Lua script
- 2:39 – Setting the chapter markers
- 3:47 – Pausing the video after the end mark
- 4:59 – Clearing the marks
- 5:21 – Creating the clip
- 5:29 – Normalize the start and end times into a valid range
- 6:40 – Safely auto-increment the clip file name
- 7:18 – Calling out to FFmpeg
- 8:25 – Handling errors
- 9:09 – Not clearing the marks after the clip on purpose
- 9:45 – Set the clip’s timestamp to match the original video
Will you be using this extension? Let me know below.