Home

Awesome

✂️ trim.lua

mpv script to create a "precise" clip of audio / video files without transcoding.

Overview

Differences from the other similar scripts

In short, trim.lua turns mpv into a simple lossless audio / video editor.

Install

curl https://raw.githubusercontent.com/aerobounce/trim.lua/master/trim.lua >> ~/.config/mpv/scripts/trim.lua

Requirements

ffmpeg

-- trim.lua

-- macOS, *nix
ffmpeg_bin = "ffmpeg"

-- Windows
ffmpeg_bin = "ffmpeg.exe"

Usage

Enable trim mode

If initialized with <kbd>h</kbd>, default trim positions will be: Current time position to End of file.<br> If initialized with <kbd>k</kbd>, default trim positions will be: Head of file to Current time position.

Toggle strip metadata mode (After initializing trim mode)

Stripping metadata can fix certain corrupted files.

Save Trim Positions

To write out a clip, press either of the keys twice with the same start / end position.<br> To quit Trim Mode, close mpv instance.

Seeking

Seek to saved positions

With video file

With audio file

To create a valid video file

Concat with 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"

Known Issue