trimVideo

March 28, 2026 · View on GitHub

Trim a video file to a specific time range. By default copies streams without re-encoding (instant, lossless).

Usage

openGyver trimVideo <input-file> [flags]

Arguments

ArgumentRequiredDescription
<input-file>YesPath to the video file to trim

Flags

FlagShortTypeDefaultDescription
--start-sstringStart time (HH:MM:SS, HH:MM:SS.ms, or seconds)
--end-estringEnd time (alternative to --duration)
--duration-dstringDuration to extract (alternative to --end)
--output-ostringinput_trimmed.extOutput file path
--codecstringcopyVideo codec. copy = no re-encoding (instant). Use libx264, libx265, etc. to re-encode
--quiet-qboolfalseSuppress output messages
--json-jboolfalseOutput as JSON

Requirements

Requires ffmpeg installed and in PATH.

# macOS
brew install ffmpeg

# Linux
apt install ffmpeg

Time Format

FormatExampleDescription
Seconds901 minute 30 seconds
HH:MM:SS00:01:301 minute 30 seconds
HH:MM:SS.ms00:01:30.5001 minute 30.5 seconds

Examples

# Trim from 1:00 to 2:30
openGyver trimVideo input.mp4 -s 00:01:00 -e 00:02:30

# Take 60 seconds starting at 30s mark
openGyver trimVideo input.mp4 -s 30 -d 60 -o clip.mp4

# Extract a scene from a movie, convert to MP4
openGyver trimVideo movie.mkv -s 00:10:00 -e 00:15:00 -o scene.mp4

# First 10 seconds with re-encoding
openGyver trimVideo input.mp4 -s 0 -d 10 --codec libx264

# First 10 seconds, keep original format (default: stream copy)
openGyver trimVideo input.mp4 -d 10

# Trim and convert AVI to WebM
openGyver trimVideo input.avi -s 00:05:00 -e 00:10:00 -o clip.webm

# Quiet mode for scripting
openGyver trimVideo input.mp4 -s 0 -d 30 -o intro.mp4 -q

# JSON output
openGyver trimVideo input.mp4 -s 60 -d 30 -j

JSON Output Format

{
  "success": true,
  "input": "input.mp4",
  "output": "clip.mp4",
  "start": "00:01:00",
  "end": "00:02:30",
  "duration": "",
  "codec": "copy"
}

Notes

  • Default mode is stream copy (-c copy) — no re-encoding, instant, lossless. The output format matches the input.
  • When using stream copy, cut points may not be frame-exact (keyframe-aligned). Use --codec libx264 for frame-exact cuts.
  • The output format is determined by the -o file extension. Use this to convert during trimming (e.g., .mkv input → .mp4 output).
  • --start + --end and --start + --duration are two ways to specify the range. Don't use both --end and --duration.