Files

139 lines
3.3 KiB
Markdown

# ComfyUI Video Trimmer
`ComfyUI Video Trimmer` is a lightweight custom node that trims a native ComfyUI `VIDEO` object by either timestamps or frame numbers.
It is designed to fit directly into standard video workflows:
`Load Video -> Video Trimmer -> Save Video`
## Features
- Accepts native `VIDEO` input from ComfyUI video loader nodes
- Outputs native `VIDEO` for downstream save/encode nodes
- Supports trimming by time in seconds or by frame range
- Preserves audio alignment when an audio track is present
- Returns useful metadata about the trimmed clip
## Installation
1. Place this folder inside your ComfyUI `custom_nodes` directory:
```text
ComfyUI/custom_nodes/ComfyUI_VideoCutter_CodexAPP
```
2. Restart ComfyUI.
3. Search for the node named `Video Trimmer` in the `Video Editing` category.
## Node Overview
### Node Name
`Video Trimmer`
### Category
`Video Editing`
### Inputs
- `video`
Native ComfyUI `VIDEO` input.
- `trim_mode`
Choose `time` or `frames`.
- `start_time`
Trim start time in seconds when `trim_mode = time`.
- `end_time`
Trim end time in seconds when `trim_mode = time`.
Use `0` to trim from `start_time` to the end of the video.
- `start_frame`
Trim start frame when `trim_mode = frames`.
- `end_frame`
Trim end frame when `trim_mode = frames`.
Use `0` to trim from `start_frame` to the end of the video.
### Outputs
- `trimmed_video`
Native ComfyUI `VIDEO` output.
- `duration_seconds`
Duration of the trimmed result.
- `frame_count`
Number of frames in the trimmed result.
- `resolved_start_frame`
Actual start frame used after validation.
- `resolved_end_frame`
Actual end frame used after validation.
## How To Use
### Trim By Time
1. Add `Load Video`.
2. Add `Video Trimmer`.
3. Connect the `VIDEO` output from `Load Video` to `Video Trimmer`.
4. Set `trim_mode` to `time`.
5. Enter `start_time` and `end_time`.
6. Connect `trimmed_video` to your preferred `Save Video` node.
Example:
- `start_time = 2.50`
- `end_time = 7.75`
This keeps the section from 2.50 seconds up to 7.75 seconds.
### Trim By Frame
1. Set `trim_mode` to `frames`.
2. Enter `start_frame` and `end_frame`.
3. Use `0` for `end_frame` to keep everything from the start frame to the video end.
Example:
- `start_frame = 48`
- `end_frame = 192`
This keeps frames 48 through 191.
## Example Workflow
```text
Load Video
-> Video Trimmer
-> Save Video
```
Recommended setup:
- Use `Load Video` to import a source clip.
- Use `Video Trimmer` to isolate the section you want.
- Use `Save Video` to encode/export the trimmed result.
## Notes
- The node trims in memory from the decoded `VIDEO` object supplied by upstream nodes.
- Because ComfyUI video workflows often operate on decoded frames, this node focuses on workflow compatibility and frame accuracy.
- Audio is trimmed to stay synchronized with the selected frame range when audio data is available on the incoming `VIDEO`.
## Error Handling
The node raises clear errors for:
- empty videos
- invalid frame rate metadata
- malformed frame tensors
- start or end positions outside valid bounds
- invalid trim ranges where start is not before end
## Developer Notes
Implementation lives in:
- `/Users/benjaminbertram/ComfyUI/custom_nodes/ComfyUI_VideoCutter_CodexAPP/nodes.py`
Registration entry point:
- `/Users/benjaminbertram/ComfyUI/custom_nodes/ComfyUI_VideoCutter_CodexAPP/__init__.py`