mpv script to create a "precise" clip of audio / video files without transcoding.
Differences from the other similar scripts
- trim.lua is aimed only for extraction of clips with no-transcoding. Encodings will never be occured.
In short, trim.lua turns mpv into a simple audio / video trimmer.
curl https://raw.githubusercontent.com/fogsaturate/trim.lua/master/trim.lua >> ~/.config/mpv/scripts/trim.luaffmpeg
- If your shell has
PATHtoffmpegyou're ready to use.- If not, rewrite
ffmpeg_binaccordingly.
- If not, rewrite
- All Windows users likely have to specify full path to
ffmpeg.- Or copy the standalone binary into the script directory (not tested).
-- trim.lua
-- macOS, *nix
ffmpeg_bin = "ffmpeg"
-- Windows
ffmpeg_bin = "ffmpeg.exe"- h or k
If initialized with h, default trim positions will be:
Current time positiontoEnd of file.
If initialized with k, default trim positions will be:Head of filetoCurrent time position.
Stripping metadata can fix certain corrupted files.
- t
Can let you change the resolution, framerate, and CRF (bitrate or quality)
-
;
Toggle resolution to 720p or 1080p (1080p default) -
'
Toggle FPS to 30 or 60 (60fps default) -
shift + ;
Decrease the CRF by 1 -
shift + '
Increase the CRF by 1
To write out a clip, press either of the keys twice with the same start / end position.
To quit Trim Mode, close mpv instance.
- h
Save Trim Start Keyframe - k
Save Trim End Position
Seek to saved positions
- shift + h
Seek to the saved Trim start position - shift + k
Seek to the saved Trim end position
With video file
- LEFT
Seek backward by keyframe (Minimum distance) - RIGHT
Seek forward by keyframe (Minimum distance) - UP
Seek forward by keyframe (Larger distance) - DOWN
Seek backward by keyframe (Larger distance) - shift+LEFT
Seek backward exactly by seconds (-0.1 seconds) - shift+RIGHT
Seek forward exactly by seconds (0.1 seconds) - shift+UP
Seek forward exactly by seconds (0.5 seconds) - shift+DOWN
Seek backward exactly by seconds (-0.5 seconds)
With audio file
- LEFT
Seek backward by seconds (-1 seconds) - RIGHT
Seek forward by seconds (1 seconds) - UP
Seek forward by seconds (5 seconds) - DOWN
Seek backward by seconds (-5 seconds) - shift+LEFT
Seek backward by seconds (-10 seconds) - shift+RIGHT
Seek forward by seconds (10 seconds) - shift+UP
Seek forward by seconds (30 seconds) - shift+DOWN
Seek backward by seconds (-30 seconds)
- Beggining of the trim position must be a keyframe.
- End position can be any point.
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"- Any embedded media other than video / audio will be lost, such as embedded subtitles. This will unlikely be fixed.