Skip to content

fix(Video): stream the video transcode instead of buffering every frame in RAM (CORE-353) (CORE-351)#14813

Merged
alexisrolland merged 8 commits into
masterfrom
fix/core/video-transcode-oom
Jul 15, 2026
Merged

fix(Video): stream the video transcode instead of buffering every frame in RAM (CORE-353) (CORE-351)#14813
alexisrolland merged 8 commits into
masterfrom
fix/core/video-transcode-oom

Conversation

@bigcat88

@bigcat88 bigcat88 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

VideoFromFile.save_to() has two paths: remux (stream copy) when source already matches the requested container/codec, and a transcode otherwise
The transcode first materialized the entire video as float32 tensors (get_components --> VideoFromComponents.save_to), with peak memory:

peak = 2 * frames * width * height * 12 bytes      (~ 47.5 MiB per 1080p frame)

of the file actual size. Every Partner Node that uploads video hits this path whenever the source is not already H.264

Note: The video cropping operation also forces the transcoding path (for any codec), so this PR also improves the situation when the Video Slice node is used

Changes in this PR

Transcode branch is rewritten as a single streaming pass: demux --> decode --> reformat --> H.264/AAC encode --> mux, one frame at a time (_save_transcoded). Peak memory no longer scales with video length

Preserved behavior, now verified by tests:

  • trim windows (Trim Video) - video and audio, sample-exact, including chained trims
  • display-matrix rotation is baked in (portrait videos), dimensions swap for 90/270
  • full-range sources (yuvj/MJPEG) are compressed to limited range as before
  • 10-bit sources stay yuv420p10le
  • audio is clamped to the video span; undecodable audio tracks (e.g. iPhone APAC spatial audio) are skipped with a warning as it originally was
  • workflow metadata (prompt / extra_pnginfo) is written to the output as before
  • the output opens lazily on the first kept frame, so cluster-muxed sources (webm/mkv) don't lose their leading audio block to a rewind

Behavior changes (transcode path only)

  • VFR sources keep their real frame timing (pts pass through, rebased to 0) instead of being re-timed to the average rate; audio is clamped to the true encoded span
  • source metadata now survives a transcode (it always survived a remux)
  • 7.1/8-channel audio downmixes to stereo - the old path crashed (segfault on 8-channel)
  • clear, early errors instead of deep PyAV failures: no decodable frames, odd dimensions, mid-stream resolution changes; broken mid-stream timestamps are nudged monotonic instead of failing at mux
  • 10-bit -> 8-bit reduction uses swscale dithering instead of float truncation
  • the H.264 output is encoded without B-frames (max_b_frames = 0): with B-frame reordering the mp4 muxer derives sample durations from decode order, which broke irregular-VFR spans and trim windows; output is a few percent larger for it
Load Video --> Save Video benchmarks Screenshot From 2026-07-07 18-46-01 Screenshot From 2026-07-07 18-46-42

The speedup has the same root as the memory win: ~75 % of the old wall time was spent converting YUV --> float RGB --> torch tensors --> RGB --> YUV

Fixes CORE-353
Related to CORE-351 (the Get Video Components eager tensor materialization is a separate issue, not addressed here)

@bigcat88
bigcat88 force-pushed the fix/core/video-transcode-oom branch 3 times, most recently from 968f73f to 1d595d4 Compare July 8, 2026 08:58
@bigcat88
bigcat88 marked this pull request as ready for review July 8, 2026 10:11
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds shared helpers for audio stream selection, audio parameter probing, metadata writing, and MP4/H.264 output options. It refactors trim-window handling across frame counting and component extraction, and routes transcoding through _save_transcoded() for frame-by-frame H.264/AAC output with trim, rotation, color-range, and PTS handling. The test suite adds transcode helpers and coverage for trimming, sparse/VFR sources, audio probing, rotation, missing PTS, and undecodable audio tracks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: streaming video transcode instead of buffering frames in RAM.
Description check ✅ Passed The description is directly related to the transcode streaming and memory-reduction changes in this PR.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
comfy_api/latest/_input_impl/video_types.py (1)

248-267: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

get_frame_count() returns 1 when duration is 0.

With the switch to get_active_trim_window(), end_pts is now computed unconditionally (Line 251). When there is no trim duration (the common untrimmed case that falls through to this last-resort decode-and-count path because frame metadata was unusable), end_pts == start_pts, so the second loop at Line 264 breaks on the very first frame and this returns frame_count = 1 for the whole video.

Both _save_transcoded() (Lines 523/625) and get_components_internal() (Line 348) correctly gate the end condition on duration; this path should match them.

🐛 Gate the end cap on duration
             start_time, duration = self.get_active_trim_window()
             frame_count = 1
             start_pts = int(start_time / video_stream.time_base)
-            end_pts = int((start_time + duration) / video_stream.time_base)
+            end_pts = int((start_time + duration) / video_stream.time_base) if duration else None
             container.seek(start_pts, stream=video_stream)
             for frame in frame_iterator:
-                if frame.pts >= end_pts:
+                if end_pts is not None and frame.pts >= end_pts:
                     break
                 frame_count += 1
             return frame_count
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@comfy_api/latest/_input_impl/video_types.py` around lines 248 - 267,
get_frame_count() is incorrectly capping the decode loop even when there is no
trim duration, which makes untrimmed videos return 1 frame. Update the
get_frame_count() logic in the frame-count fallback path to mirror
_save_transcoded() and get_components_internal(): compute the end boundary only
when duration is present, and otherwise count frames until exhaustion. Keep
using get_active_trim_window(), but make the second loop’s stop condition
conditional on duration so the untrimmed case is handled correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests-unit/comfy_api_test/video_types_test.py`:
- Around line 260-283: The audio setup in create_transcode_source is hardcoded
to build s16 mono frames, which breaks when
test_save_to_transcode_trims_audio_in_stream_time_base_units passes an AAC
audio_codec. Update the audio frame generation path in create_transcode_source
so it matches each stream’s encoder sample format, using the stream’s format or
an AudioResampler for non-PCM codecs like AAC. Keep the existing audio stream
loop and muxing flow, but ensure the frames handed to stream.encode are
compatible with the selected audio_codec.

---

Outside diff comments:
In `@comfy_api/latest/_input_impl/video_types.py`:
- Around line 248-267: get_frame_count() is incorrectly capping the decode loop
even when there is no trim duration, which makes untrimmed videos return 1
frame. Update the get_frame_count() logic in the frame-count fallback path to
mirror _save_transcoded() and get_components_internal(): compute the end
boundary only when duration is present, and otherwise count frames until
exhaustion. Keep using get_active_trim_window(), but make the second loop’s stop
condition conditional on duration so the untrimmed case is handled correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: af381a80-a01a-4725-afe0-9155b0c4d011

📥 Commits

Reviewing files that changed from the base of the PR and between ffbecff and 1d595d4a703515664157849daeaee88d7ca47a1c.

📒 Files selected for processing (2)
  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
📜 Review details
⚠️ CI failures not shown inline (3)

GitHub Actions: Execution Tests / 0_test (macos-latest).txt: fix(Video): stream the video transcode instead of buffering every frame in RAM

Conclusion: failure

View job details

n alembic.autogenerate.tables
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.types
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.constraints
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.defaults
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.comments
 �[32m[INFO]�[0m Adding extra search path custom_nodes /Users/runner/work/ComfyUI/ComfyUI/tests/execution/testing_nodes
 �[32m[INFO]�[0m Setting output directory to: /Users/runner/work/ComfyUI/ComfyUI/tests/inference/samples
 �[32m[INFO]�[0m Found comfy_kitchen backend cuda: {'available': False, 'disabled': True, 'unavailable_reason': 'Extension file not found: /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/comfy_kitchen/backends/cuda/_C.abi3.so', 'capabilities': []}
 �[32m[INFO]�[0m Found comfy_kitchen backend triton: {'available': False, 'disabled': True, 'unavailable_reason': "ImportError: No module named 'triton'", 'capabilities': []}
 �[32m[INFO]�[0m Found comfy_kitchen backend eager: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_mxfp8', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'scaled_mm_mxfp8', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
 �[32m[INFO]�[0m Checkpoint files will always be loaded safely.
 �[32m[INFO]�[0m Total VRAM 7168 MB, total RAM 7168 MB
 �[32m[INFO]�[0m pytorch version: 2.12.1
 �[32m[INFO]�[0m Mac Version (26, 4)
 �[32m[INFO]�[0m Set vram state to: DISABLED
 �[32m[INFO]�[0m Device: cpu
 �[32m[INFO]�[0m Us...

GitHub Actions: Execution Tests / 1_test (windows-latest).txt: fix(Video): stream the video transcode instead of buffering every frame in RAM

Conclusion: failure

View job details

_not_found[server0] PASSED
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.schemas
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.tables
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.types
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.constraints
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.defaults
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.comments
 �[32m[INFO]�[0m Adding extra search path custom_nodes D:\a\ComfyUI\ComfyUI\tests\execution\testing_nodes
 �[32m[INFO]�[0m Setting output directory to: D:\a\ComfyUI\ComfyUI\tests\inference\samples
 �[32m[INFO]�[0m Found comfy_kitchen backend cuda: {'available': False, 'disabled': True, 'unavailable_reason': 'CUDA not available on this system', 'capabilities': []}
 �[32m[INFO]�[0m Found comfy_kitchen backend triton: {'available': False, 'disabled': True, 'unavailable_reason': "ImportError: No module named 'triton'", 'capabilities': []}
 �[32m[INFO]�[0m Found comfy_kitchen backend eager: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_mxfp8', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'scaled_mm_mxfp8', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
 �[32m[INFO]�[0m Checkpoint files will always be loaded safely.
 �[32m[INFO]�[0m Total VRAM 16379 MB, total RAM 16379 MB
 �[32m[INFO]�[0m pytorch version: 2.12.1+cpu
 �[32m[INFO]�[0m Set vram state to: DISABLED
 �[32m[INFO]�[0m Device: cpu
 �[32m[INFO]�[0m Using sub quadratic optimization for attention, if you hav...

GitHub Actions: Execution Tests / 2_test (ubuntu-latest).txt: fix(Video): stream the video transcode instead of buffering every frame in RAM

Conclusion: failure

View job details

[0m �[32mPrompt executed in 0.00 seconds�[0m
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 tests/execution/test_execution.py::TestExecution::test_jobs_api_pagination[server0] PASSED
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 tests/execution/test_execution.py::TestExecution::test_jobs_api_sorting[server0] PASSED
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 tests/execution/test_execution.py::TestExecution::test_jobs_api_status_filter[server0] PASSED
 �[32m[INFO]�[0m got prompt
 �[32m[INFO]�[0m �[32mPrompt executed in 0.00 seconds�[0m
 tests/execution/test_execution.py::TestExecution::test_get_job_by_id[server0] PASSED
 tests/execution/test_execution.py::TestExecution::test_get_job_not_found[server0] PASSED
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.schemas
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.tables
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.types
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.constraints
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.defaults
 �[32m[INFO]�[0m setup plugin alembic.autogenerate.comments
 �[32m[INFO]�[0m Adding extra search path custom_nodes /home/runner/work/ComfyUI/ComfyUI/tests/execution/testing_nodes
 �[32m[INFO]�[0m Setting output directory to: /home/runner/work/ComfyUI/ComfyUI/tests/inference/samples
 �[32m[INFO]�[0m Found comfy_kitchen backend triton: {'available': False, 'disabled': True, 'unavailable_reason': "ImportError: No module named 'triton'", 'capabilities': []}
 �[32m[INFO]�[0m Found comfy_kitchen backend eager: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'deq...
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Keep imports at module scope; avoid inline imports unless they are already part of an established optional-backend probe or are needed to avoid an import cycle.
Do not add unnecessary try/except blocks; use them only for optional dependency, platform, or backend capability detection when the program has a useful fallback, and prefer specific exception types when changing new code.
Remove workarounds for PyTorch versions that ComfyUI no longer officially supports; if a workaround does not have a comment naming the exact supported PyTorch version(s), remove it.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently producing lower quality output.
Match the existing local style in the file you edit; this codebase tolerates long lines, simple helper functions, module-level state, and direct tensor operations when they make the code easier to follow.
Keep comments sparse and useful; strip useless comments that restate the code or describe obvious behavior, while allowing short TODOs that name the concrete missing follow-up.
Treat dtype, device placement, VRAM usage, and offloading behavior as core correctness concerns; check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low VRAM implications when touching shared execution or loading code.
Prefer native ComfyUI formats and existing quantization/offload helpers over adding parallel code paths; use comfy.quant_ops, comfy.model_management, comfy.memory_management, comfy.pinned_memory, comfy_aimdo, and comfy-kitchen helpers where they already solve the problem.
Use optimized comfy-kitchen ops where they improve performance without changing expected dtype, device, memory, or interface behavior.
All models should use the optimized attention function selected by ComfyUI; higher-level code must not inspect function identity, names, modules, or implementation details to decide behavior.
Apply the same opacity rule to similar patterns beyond...

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
**

⚙️ CodeRabbit configuration file

**: ## Engineering Style

  • Keep changes small and direct. Most fixes should touch the narrowest code path
    that explains the bug, performance issue, dtype issue, model-format issue, or
    user-facing behavior.
  • Change the least amount of files possible. A change that touches many files is
    more likely to be a bad change than a good one unless the broader scope is
    directly required.
  • Prefer practical fixes over broad architecture work. Add abstractions only
    when they remove real repeated logic or match an existing ComfyUI pattern.
  • Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they
    are absolutely necessary.
  • Delete obsolete code aggressively when newer infrastructure makes it useless.
    Remove dead fallbacks, migration paths, unused options, debug prints, and
    compatibility branches that are no longer needed. Do not leave dead branches,
    unreachable code, or functions that are never called. If code is not
    necessary for the current behavior, remove it.
  • Revert or disable problematic behavior quickly when it breaks users. It is
    better to remove a broken feature path than keep a complicated partial fix.
  • Preserve existing APIs, node names, model-loading behavior, file layout, and
    workflow compatibility unless the change is explicitly about replacing them.
  • Code must look hand-written for this repository. Changes that read like
    generic AI-generated code will be rejected automatically: unnecessary helper
    layers, vague names, boilerplate comments, defensive branches without a real
    failure mode, broad rewrites, or code that ignores the local style.

Architecture Boundaries

  • Keep each layer focused on the concepts it owns. Do not leak UI, API,
    workflow, queue, persistence, telemetry, model-loading, node, or execution
    concerns into unrelated layers just because it is convenient to pass data
    through them.
  • Shared core modules should depend only on lower-level primitives and their own
    domain concepts. Highe...

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py

⚙️ CodeRabbit configuration file

**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing a with: block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
🧠 Learnings (1)
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.

Applied to files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
🪛 ast-grep (0.44.1)
comfy_api/latest/_input_impl/video_types.py

[info] 97-97: use jsonify instead of json.dumps for JSON output
Context: json.dumps(value)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🔇 Additional comments (7)
comfy_api/latest/_input_impl/video_types.py (2)

63-113: LGTM!


509-756: LGTM!

tests-unit/comfy_api_test/video_types_test.py (5)

5-10: LGTM!


285-300: LGTM!


303-327: LGTM!


330-596: LGTM!


598-623: LGTM!

Comment thread tests-unit/comfy_api_test/video_types_test.py
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 8, 2026
@bigcat88 bigcat88 added the cursor-review Trigger multi-model Cursor code review label Jul 8, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Cursor Review — Consolidated panel

Triggered by @bigcat88.

Found 10 finding(s).

Severity Count
🟠 High 1
🟡 Medium 6
🟢 Low 3

Panel: 6/8 reviewers contributed findings.

Reviewers that did not contribute: kimi-k2.5:adversarial (empty), kimi-k2.5:edge-case (empty)

Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py Outdated
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
comfy_api/latest/_input_impl/video_types.py (1)

248-251: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep end_pts open-ended when no duration is requested.

Line 251 makes end_pts == start_pts for the default untrimmed case (duration == 0), so the streaming decode fallback reports only the first frame for sources without usable frame/duration metadata.

Proposed fix
-            end_pts = int((start_time + duration) / video_stream.time_base)
+            end_pts = int((start_time + duration) / video_stream.time_base) if duration else None
@@
-                if frame.pts >= end_pts:
+                if end_pts is not None and frame.pts >= end_pts:
                     break
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@comfy_api/latest/_input_impl/video_types.py` around lines 248 - 251, In
`get_active_trim_window` usage inside the video decode path, `end_pts` is being
set equal to `start_pts` when `duration == 0`, which causes the untrimmed case
to stop after the first frame. Update the logic around `start_time, duration`,
`start_pts`, and `end_pts` so that when no duration is requested, `end_pts` is
left open-ended instead of clamping to the start timestamp, while preserving the
existing bounded trim behavior for nonzero durations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@comfy_api/latest/_input_impl/video_types.py`:
- Around line 248-251: In `get_active_trim_window` usage inside the video decode
path, `end_pts` is being set equal to `start_pts` when `duration == 0`, which
causes the untrimmed case to stop after the first frame. Update the logic around
`start_time, duration`, `start_pts`, and `end_pts` so that when no duration is
requested, `end_pts` is left open-ended instead of clamping to the start
timestamp, while preserving the existing bounded trim behavior for nonzero
durations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 590f233a-5506-488c-9433-e78d4802efad

📥 Commits

Reviewing files that changed from the base of the PR and between 1d595d4a703515664157849daeaee88d7ca47a1c and 64f73d40799808431a2e2c900025ece6a60a6f4f.

📒 Files selected for processing (2)
  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: test (windows-2022)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (windows-latest)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Keep imports at module scope; avoid inline imports unless they are already part of an established optional-backend probe or are needed to avoid an import cycle.
Do not add unnecessary try/except blocks; use them only for optional dependency, platform, or backend capability detection when the program has a useful fallback, and prefer specific exception types when changing new code.
Remove workarounds for PyTorch versions that ComfyUI no longer officially supports; if a workaround does not have a comment naming the exact supported PyTorch version(s), remove it.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently producing lower quality output.
Match the existing local style in the file you edit; this codebase tolerates long lines, simple helper functions, module-level state, and direct tensor operations when they make the code easier to follow.
Keep comments sparse and useful; strip useless comments that restate the code or describe obvious behavior, while allowing short TODOs that name the concrete missing follow-up.
Treat dtype, device placement, VRAM usage, and offloading behavior as core correctness concerns; check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low VRAM implications when touching shared execution or loading code.
Prefer native ComfyUI formats and existing quantization/offload helpers over adding parallel code paths; use comfy.quant_ops, comfy.model_management, comfy.memory_management, comfy.pinned_memory, comfy_aimdo, and comfy-kitchen helpers where they already solve the problem.
Use optimized comfy-kitchen ops where they improve performance without changing expected dtype, device, memory, or interface behavior.
All models should use the optimized attention function selected by ComfyUI; higher-level code must not inspect function identity, names, modules, or implementation details to decide behavior.
Apply the same opacity rule to similar patterns beyond...

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
**

⚙️ CodeRabbit configuration file

**: ## Engineering Style

  • Keep changes small and direct. Most fixes should touch the narrowest code path
    that explains the bug, performance issue, dtype issue, model-format issue, or
    user-facing behavior.
  • Change the least amount of files possible. A change that touches many files is
    more likely to be a bad change than a good one unless the broader scope is
    directly required.
  • Prefer practical fixes over broad architecture work. Add abstractions only
    when they remove real repeated logic or match an existing ComfyUI pattern.
  • Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they
    are absolutely necessary.
  • Delete obsolete code aggressively when newer infrastructure makes it useless.
    Remove dead fallbacks, migration paths, unused options, debug prints, and
    compatibility branches that are no longer needed. Do not leave dead branches,
    unreachable code, or functions that are never called. If code is not
    necessary for the current behavior, remove it.
  • Revert or disable problematic behavior quickly when it breaks users. It is
    better to remove a broken feature path than keep a complicated partial fix.
  • Preserve existing APIs, node names, model-loading behavior, file layout, and
    workflow compatibility unless the change is explicitly about replacing them.
  • Code must look hand-written for this repository. Changes that read like
    generic AI-generated code will be rejected automatically: unnecessary helper
    layers, vague names, boilerplate comments, defensive branches without a real
    failure mode, broad rewrites, or code that ignores the local style.

Architecture Boundaries

  • Keep each layer focused on the concepts it owns. Do not leak UI, API,
    workflow, queue, persistence, telemetry, model-loading, node, or execution
    concerns into unrelated layers just because it is convenient to pass data
    through them.
  • Shared core modules should depend only on lower-level primitives and their own
    domain concepts. Highe...

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py

⚙️ CodeRabbit configuration file

**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing a with: block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.

Files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
🧠 Learnings (1)
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.

Applied to files:

  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
🔇 Additional comments (2)
comfy_api/latest/_input_impl/video_types.py (1)

75-88: LGTM!

Also applies to: 306-348, 415-438, 481-491, 527-630, 632-757

tests-unit/comfy_api_test/video_types_test.py (1)

598-650: LGTM!

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 8, 2026
bigcat88 added 3 commits July 8, 2026 18:56
…me in RAM

Signed-off-by: bigcat88 <bigcat88@icloud.com>
Signed-off-by: bigcat88 <bigcat88@icloud.com>
…stead of dropping stream immediately

Signed-off-by: bigcat88 <bigcat88@icloud.com>
Signed-off-by: bigcat88 <bigcat88@icloud.com>
@bigcat88
bigcat88 force-pushed the fix/core/video-transcode-oom branch from 2330be6 to 524414b Compare July 8, 2026 15:57

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@comfy_api/latest/_input_impl/video_types.py`:
- Around line 248-251: The open-ended trim handling in get_active_trim_window()
is forcing end_pts to match start_pts when duration is 0, which makes the later
frame.pts cutoff stop after the first frame for metadata-poor untrimmed videos.
Update the frame-count logic in video_types.py so the no-duration-cap path
leaves end_pts unset/optional and only applies the frame.pts >= end_pts check
when an active duration cap exists.
- Around line 101-111: The MP4 kwargs builder in mp4_output_open_kwargs
currently only sets the output format when format is a VideoContainer instance,
so string-like enum values such as "mp4" can pass validation but still skip the
format passed to av.open(). Normalize the accepted format input after the
validation checks and always set open_kwargs["format"] to the MP4 container
value for supported outputs, while preserving the BytesIO-specific handling; use
mp4_output_open_kwargs, VideoContainer, and VideoCodec as the key locations to
update.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a6e9a176-a0c0-4328-94cc-6cf440c4777e

📥 Commits

Reviewing files that changed from the base of the PR and between 64f73d40799808431a2e2c900025ece6a60a6f4f and 524414b.

📒 Files selected for processing (2)
  • comfy_api/latest/_input_impl/video_types.py
  • tests-unit/comfy_api_test/video_types_test.py
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Run Pylint
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (windows-latest)
  • GitHub Check: test
  • GitHub Check: test (windows-2022)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: Run Pylint
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Keep imports at module scope; avoid inline imports unless they are already part of an established optional-backend probe or are needed to avoid an import cycle.
Do not add unnecessary try/except blocks; use them only for optional dependency, platform, or backend capability detection when the program has a useful fallback, and prefer specific exception types when changing new code.
Remove workarounds for PyTorch versions that ComfyUI no longer officially supports; if a workaround does not have a comment naming the exact supported PyTorch version(s), remove it.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently producing lower quality output.
Match the existing local style in the file you edit; this codebase tolerates long lines, simple helper functions, module-level state, and direct tensor operations when they make the code easier to follow.
Keep comments sparse and useful; strip useless comments that restate the code or describe obvious behavior, while allowing short TODOs that name the concrete missing follow-up.
Treat dtype, device placement, VRAM usage, and offloading behavior as core correctness concerns; check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low VRAM implications when touching shared execution or loading code.
Prefer native ComfyUI formats and existing quantization/offload helpers over adding parallel code paths; use comfy.quant_ops, comfy.model_management, comfy.memory_management, comfy.pinned_memory, comfy_aimdo, and comfy-kitchen helpers where they already solve the problem.
Use optimized comfy-kitchen ops where they improve performance without changing expected dtype, device, memory, or interface behavior.
All models should use the optimized attention function selected by ComfyUI; higher-level code must not inspect function identity, names, modules, or implementation details to decide behavior.
Apply the same opacity rule to similar patterns beyond...

Files:

  • tests-unit/comfy_api_test/video_types_test.py
  • comfy_api/latest/_input_impl/video_types.py
**

⚙️ CodeRabbit configuration file

**: ## Engineering Style

  • Keep changes small and direct. Most fixes should touch the narrowest code path
    that explains the bug, performance issue, dtype issue, model-format issue, or
    user-facing behavior.
  • Change the least amount of files possible. A change that touches many files is
    more likely to be a bad change than a good one unless the broader scope is
    directly required.
  • Prefer practical fixes over broad architecture work. Add abstractions only
    when they remove real repeated logic or match an existing ComfyUI pattern.
  • Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they
    are absolutely necessary.
  • Delete obsolete code aggressively when newer infrastructure makes it useless.
    Remove dead fallbacks, migration paths, unused options, debug prints, and
    compatibility branches that are no longer needed. Do not leave dead branches,
    unreachable code, or functions that are never called. If code is not
    necessary for the current behavior, remove it.
  • Revert or disable problematic behavior quickly when it breaks users. It is
    better to remove a broken feature path than keep a complicated partial fix.
  • Preserve existing APIs, node names, model-loading behavior, file layout, and
    workflow compatibility unless the change is explicitly about replacing them.
  • Code must look hand-written for this repository. Changes that read like
    generic AI-generated code will be rejected automatically: unnecessary helper
    layers, vague names, boilerplate comments, defensive branches without a real
    failure mode, broad rewrites, or code that ignores the local style.

Architecture Boundaries

  • Keep each layer focused on the concepts it owns. Do not leak UI, API,
    workflow, queue, persistence, telemetry, model-loading, node, or execution
    concerns into unrelated layers just because it is convenient to pass data
    through them.
  • Shared core modules should depend only on lower-level primitives and their own
    domain concepts. Highe...

Files:

  • tests-unit/comfy_api_test/video_types_test.py
  • comfy_api/latest/_input_impl/video_types.py

⚙️ CodeRabbit configuration file

**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing a with: block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.

Files:

  • tests-unit/comfy_api_test/video_types_test.py
  • comfy_api/latest/_input_impl/video_types.py
🧠 Learnings (1)
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.

Applied to files:

  • tests-unit/comfy_api_test/video_types_test.py
  • comfy_api/latest/_input_impl/video_types.py
🪛 ast-grep (0.44.1)
comfy_api/latest/_input_impl/video_types.py

[info] 97-97: use jsonify instead of json.dumps for JSON output
Context: json.dumps(value)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🔇 Additional comments (4)
comfy_api/latest/_input_impl/video_types.py (2)

3-13: LGTM!

Also applies to: 63-100


306-348: LGTM!

Also applies to: 415-438, 484-491, 509-761, 809-814

tests-unit/comfy_api_test/video_types_test.py (2)

5-10: LGTM!

Also applies to: 243-300, 303-565, 604-684


590-593: 🎯 Functional Correctness

Patch durations on flushed packets too, if this path can emit delayed packets.

video_stream.encode(None) skips the duration_by_pts handling, so any delayed packet would keep its default duration and miss the exact VFR stts mapping.

Comment thread comfy_api/latest/_input_impl/video_types.py
Comment thread comfy_api/latest/_input_impl/video_types.py
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 8, 2026
Signed-off-by: bigcat88 <bigcat88@icloud.com>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 9, 2026
Signed-off-by: bigcat88 <bigcat88@icloud.com>
@alexisrolland alexisrolland changed the title fix(Video): stream the video transcode instead of buffering every frame in RAM fix(Video): stream the video transcode instead of buffering every frame in RAM (CORE-353) Jul 15, 2026
@alexisrolland alexisrolland changed the title fix(Video): stream the video transcode instead of buffering every frame in RAM (CORE-353) fix(Video): stream the video transcode instead of buffering every frame in RAM (CORE-353) (CORE-351) Jul 15, 2026
@alexisrolland
alexisrolland merged commit cc6b352 into master Jul 15, 2026
22 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cursor-review Trigger multi-model Cursor code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants