Nodes/video-crop-trim/Video Crop & Trim (FFmpeg)
ComfyUI Node

Video Crop & Trim (FFmpeg)

Crop and trim video in ComfyUI without opening a video editor

By RiverSide71·Created 4 months ago·Updated 12 days ago· 2
Video Crop & Trim (FFmpeg)
  • images
  • audio
  • frames
  • audio
crop_x0
crop_y0
crop_width512
crop_height512
trim_modeseconds
trim_start0.00
trim_end0.00
video_duration0.00
output_formatmp4
codeclibx264
quality23
audio_modeextract
video_path
fps30.000
extra_ffmpeg_args

The most annoying gap in a video workflow isn't the model - it's the five seconds of clip you need to surgically cut out of the middle, or the corner of the frame you want to keep while everything else goes. Normally that means leaving ComfyUI, opening a video editor, exporting, and importing back. Video Crop & Trim (FFmpeg) is a single node that does the crop and trim in the graph, with a mouse instead of a calculator. It's the utility step you didn't know you were missing, sitting right there in the video/processing section of the node menu.

It's a small pack - this node is the whole pack - but it earns its slot. The pitch: load a video, drag a crop rectangle directly on a live preview of the first frame, trim by seconds or by frame number, and hand the result to a downstream VHS Video Combine. If you've ever eyeballed crop_width by trial and error, this is the fix.

How it works

The work is done by FFmpeg, driven through the ffmpeg-python bindings, in three passes. First it resolves your input: either the video_path string (absolute, or relative to ComfyUI's input/ folder) or, if you connect an IMAGE tensor to the video input, it writes those frames to temporary PNGs and encodes them to a temp file first. Then it runs the real encode - a crop filter for your region and a ss/to seek for the trim - and finally decodes every frame of the result back into a (B, H, W, C) float32 tensor. Everything happens in a temp directory, so you never touch a file on disk.

The visual part is a custom frontend widget backed by two tiny HTTP endpoints: one that extracts the first frame for the preview, one that streams the source file for the in-node playback bar. Drag on empty canvas to draw a crop, drag inside to move it, corner handles to resize, double-click to reset. There's even a rule-of-thirds grid baked into the crop box.

The inputs that matter

The canvas is the real input, but it just writes four numbers that stay in sync with the widgets: crop_x, crop_y, crop_width, crop_height. They step by 2 for a reason - most codecs need even dimensions - and the node rounds odd values down by one pixel for you.

  • trim_mode - none, seconds, or frames. In frames mode, trim_start/trim_end are divided by fps to get time. Either way, trim_end = 0 means "to the end of the file".
  • audio_mode - strip (default) discards audio; extract trims the audio to match the clip and returns it on the audio output as a standard ComfyUI AUDIO tensor. That's the one that makes the two-output setup with VHS Video Combine work.
  • output_format / codec / quality - mp4/webm/avi/mov, libx264/libx265/libvpx-vp9/prores, and a CRF value (lower = better, default 23). The defaults are sensible; leave them alone until you know why you're changing them.
  • video vs video_path - connecting an IMAGE tensor takes priority over the path. Fair warning: a tensor has no audio, so if you go that route set audio_mode to strip or the audio output comes back None.

Outputs are frames (IMAGE) and audio (AUDIO, None when stripped or absent). Wire both into VHS Video Combine to re-save a clip with synchronized sound.

Installing it

ComfyUI Manager: search Video Crop & Trim and hit Install. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/RiverSide71/comfyui-video-crop-trim

Then restart ComfyUI. No model downloads - but there is one system dependency Manager won't get for you: a real ffmpeg binary on your $PATH. ffmpeg-python is just bindings that shell out to it.

pip install ffmpeg-python Pillow numpy   # Python deps
brew install ffmpeg                      # macOS
sudo apt install ffmpeg                  # Ubuntu/Debian
# Windows: grab a build from ffmpeg.org and add bin/ to PATH

Gotchas

The classic failure is "ffmpeg not found" - the bindings are installed, the binary isn't, and every run dies. Install the system binary first. Two others from the README worth remembering: audio_mode=extract on a file with no audio stream just warns and returns None (check the info bar - it shows the detected codec, channels, and sample rate), and if you hit a widget-order validation error after an update, delete the node and re-add it rather than fighting it.

This is a young, small pack with no community footprint yet - expect to read the README, not a r/comfyui thread, when something breaks.

Categoryvideo/processing

Inputs (17)

NameTypeDefaultDescription
crop_xINT00–8192Left edge of the crop region (pixels, even numbers only)
crop_yINT00–8192Top edge of the crop region (pixels, even numbers only)
crop_widthINT5122–8192Width of the crop region (pixels, even numbers only)
crop_heightINT5122–8192Height of the crop region (pixels, even numbers only)
trim_modeCOMBOsecondsHow trim_start / trim_end are interpreted
trim_startFLOAT0.000–86400Start of the kept region (seconds or frame index)
trim_endFLOAT0.000–86400End of the kept region (seconds or frame index). 0 = until end of video.
video_durationFLOAT0.000–86400Total duration of the source video in seconds. Written automatically by the frontend UI when a video is loaded; used as the timeline range for the trim scrubber.
output_formatCOMBOmp4Container format for the encoded output video file.
codecCOMBOlibx264Video codec used to encode the output: libx264 – H.264, broad compatibility libx265 – H.265/HEVC, smaller files at equal quality libvpx-vp9 – VP9, used for webm output prores – ProRes 422, editing-friendly
qualityINT230–51CRF value - lower = better quality / larger file
audio_modeCOMBOextractstrip – discard audio entirely (video frames only). extract – trim audio to match the video clip and output it as a separate AUDIO tensor compatible with VHS Video Combine.
imagesoptIMAGEConnect IMAGE frames here — e.g. the 'images' output of a 'Get Video Components' node (takes priority over video_path)
audiooptAUDIOConnect AUDIO here — e.g. the 'audio' output of a 'Get Video Components' node. Trimmed to match the kept video window when audio_mode='extract'.
video_pathoptSTRINGVideo file path. Can be filled automatically using the Upload Your Video button.
fpsoptFLOAT30.0001–240Output framerate (also used to convert frame-based trim values)
extra_ffmpeg_argsoptSTRINGExtra ffmpeg output arguments passed verbatim

Outputs (2)

NameTypeDescription
framesIMAGECropped and trimmed video frames.
audioAUDIOAudio trimmed to match the kept video window. None when audio_mode='strip' or no audio was available.