Trim mode for mpv — Turn mpv into Lossless Audio / Video Editor
mpv script to create a "precise" clip of audio / video files without transcoding.
Differences from the other similar scripts
In short, trim.lua
turns mpv into a simple lossless audio / video editor.
curl https://raw.githubusercontent.com/aerobounce/trim.lua/master/trim.lua >> ~/.config/mpv/scripts/trim.lua
ffmpeg
PATH
to ffmpeg
you're ready to use.
ffmpeg_bin
accordingly.ffmpeg
.
-- trim.lua
-- macOS, *nix
ffmpeg_bin = "ffmpeg"
-- Windows
ffmpeg_bin = "ffmpeg.exe"
If initialized with h, default trim positions will be:
Current time position
toEnd of file
.
If initialized with k, default trim positions will be:Head of file
toCurrent time position
.
Stripping metadata can fix certain corrupted files.
To write out a clip, press either of the keys twice with the same start / end position.
To quit Trim Mode, close mpv instance.
Save Trim Start Keyframe
Save Trim End Position
Seek to saved positions
Seek to the saved Trim start position
Seek to the saved Trim end position
With video file
Seek backward by keyframe (Minimum distance)
Seek forward by keyframe (Minimum distance)
Seek forward by keyframe (Larger distance)
Seek backward by keyframe (Larger distance)
Seek backward exactly by seconds (-0.1 seconds)
Seek forward exactly by seconds (0.1 seconds)
Seek forward exactly by seconds (0.5 seconds)
Seek backward exactly by seconds (-0.5 seconds)
With audio file
Seek backward by seconds (-1 seconds)
Seek forward by seconds (1 seconds)
Seek forward by seconds (5 seconds)
Seek backward by seconds (-5 seconds)
Seek backward by seconds (-10 seconds)
Seek forward by seconds (10 seconds)
Seek forward by seconds (30 seconds)
Seek backward by seconds (-30 seconds)
ffmpeg
After splitting, you can concat them with a script something like this.
CLIPS=("example_1.mp4" "example_2.mp4")
DESTINATION="concat_example.mp4"
ffmpeg \
-hide_banner \
-loglevel verbose \
-f concat \
-safe 0 \
-auto_convert 0 \
-err_detect ignore_err \
-i <(
while read -r; do
echo "file '$REPLY'"
done <<< "${CLIPS[*]}"
) \
-copy_unknown \
-map_chapters 0 \
-c copy \
"$DESTINATION"