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

nickjj1 pts0 comments

Visually Create Video Clips with mpv, FFmpeg and a Lua Extension — Nick JanetakisLearn Docker With My Newest Course<br>Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples.<br>Start Learning Docker &rarr;

Updated on June 23, 2026<br>in<br>#linux<br>Visually Create Video Clips with mpv, FFmpeg and a Lua Extension

We'll take advantage of using temporary mpv chapter markers and FFmpeg to<br>avoid needing to re-encode the video.<br>Quick Jump:<br>Want to jump straight to the demo video? Here it is on<br>YouTube.<br>I&rsquo;m a big fan of using mpv for playing back<br>videos and viewing images. Now I also use it to quickly cut up videos to create<br>clips in seconds thanks to its Lua extension feature.<br>Years ago I wrote a shell script around FFmpeg to create clips on the command<br>line.<br>It has served me well for quickly creating video clips. The TL;DR is you can<br>supply the file name, time stamp range and a clip suffix (such as -1, -2)<br>and it will create separate video files.<br>Near the end of 2025 I switched to using Linux on the desktop and really<br>focused on the idea of not making compromises for workflows I do regularly. The<br>CLI script worked nicely but after I discovered how good and customizable mpv<br>is I thought to myself &ldquo;what if I combined mpv and FFmpeg to do this<br>visually?&rdquo;.<br>The mpv extension requires no dependencies other than FFmpeg.

How it Works<br>It&rsquo;s powered by an mpv custom Lua script, here&rsquo;s the high level pieces:<br>mpv chapter markersVisual indicators that let you mark points on the seek bar<br>This is IMO more user friendly to use than A/B markers but both would work

4 custom key bindsOne to set the chapter &ldquo;start&rdquo; mark<br>One to set the chapter &ldquo;end&rdquo; mark<br>One to create the clip between the start and end markers<br>One to clear all markers (optional but nice to have)

FFmpegQuickly create the clip without re-encoding the video<br>Called when pressing the create clip key bind

If you&rsquo;re using DotFriedRice you<br>already have access to the extension.<br>If you&rsquo;re not using DotFriedRice you can get the extension<br>here<br>and place it in ~/.config/mpv/scripts/mkclip.lua, then set these key binds in<br>your ~/.config/mpv/input.conf to use it. You can of course customize the<br>keys:<br>F1 script-binding mkclip_mark_start<br>F2 script-binding mkclip_mark_end<br>F3 script-binding mkclip_create<br>F4 script-binding mkclip_clear_marks

Quality of Life Features<br>I&rsquo;ve created tons of clips with it and landed on the following features:<br>If the video is playing and you press F1 to start a mark, the video will<br>continue playing. This is handy because chances are you want to set a stop mark<br>X seconds afterwards. You can continue pressing F1 to overwrite the previous<br>start mark too.<br>If the video is playing and you press F2 to end a mark, the video will stop<br>because now your intent is likely to create the clip. The clip isn&rsquo;t<br>automatically created because you might want to adjust your markers first while<br>the video is stopped.<br>Whenever a start or end mark is created, an on-screen-display message will show<br>you the time stamp and if you have both a start and end it will show you the<br>duration so you know how long the clip will be.<br>While there&rsquo;s dedicated keys to have a start and end marker, behind the scenes<br>the script will allow you to set the end time before the start time. Really<br>this gives you the end game solution of having 2 markers to create a range. The<br>order of the markers doesn&rsquo;t matter, this is nice because your brain only needs<br>to see the visual markers and you know for sure the clip will be created within<br>that range.<br>It uses your original file name and appends -1, -2, etc. to the end of the<br>file name. There&rsquo;s also multiple layers of defense to avoid ever accidentally<br>overwriting your original file in case the script ever contains a bug with this<br>logic.<br>It also sets the clip&rsquo;s create and modified time to match the original clip.<br>This way if you have 1 big directory of videos sorted by last modified, the<br>clips you create from the original video will retain their original timestamp.<br>I&rsquo;m really happy with this. It&rsquo;s another example of molding your tools to your<br>liking, mpv is a gift that keeps on giving.<br>The video below shows how it all works and briefly goes over the code.

Demo Video

Timestamps<br>0:18 – Visually create clips in mpv<br>1:34 – Taking a look at the key binds<br>1:52 – Going over the Lua script<br>2:39 – Setting the chapter markers<br>3:47 – Pausing the video after the end mark<br>4:59 – Clearing the marks<br>5:21 – Creating the clip<br>5:29 – Normalize the start and end times into a valid range<br>6:40 – Safely auto-increment the clip file name<br>7:18 – Calling out to FFmpeg<br>8:25 – Handling errors<br>9:09 – Not clearing the marks after the clip on purpose<br>9:45 – Set the clip&rsquo;s timestamp to match the original video<br>Will you be using this extension? Let me know below.

Never Miss a Tip, Trick or...

video create rsquo clip start script

Related Articles