Skip to content

fix(Video): don't crash on videos with undecodable audio streams#14746

Open
bigcat88 wants to merge 1 commit into
masterfrom
fix/core/mov-spatial-audio
Open

fix(Video): don't crash on videos with undecodable audio streams#14746
bigcat88 wants to merge 1 commit into
masterfrom
fix/core/mov-spatial-audio

Conversation

@bigcat88

@bigcat88 bigcat88 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Videos recorded on recent iPhones with Spatial Audio carry two audio tracks: a stereo AAC fallback and Apple Positional Audio Codec(APAC)
FFmpeg usually has no APAC decoder, so PyAV exposes that stream with codec_context = None
VideoFromFile picked the last audio track - the APAC one. Decoding a packet on a stream without a codec context segfaults the whole process with such error:

Extension modules: numpy._core._multiarray_umath, numpy.linalg._umath_linalg, sqlalchemy.cyextension.collections,
...
scipy.signal._peak_finding_utils (total: 184)

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

Three changes:

  • get_components_internal picks the last decodable audio stream. A file with only undecodable audio decodes as video-only with a warning instead of crashing
  • the remux path in save_to skips streams that have no codec context (they can't be used as an output template) instead of failing the whole save
  • upload_video_to_comfyapi wraps the conversion so a failure surfaces as a readable node error suggesting to re-export as MP4

API Node PR Checklist

Scope

  • Is API Node Change

Pricing & Billing

  • Need pricing update
  • No pricing update

If Need pricing update:

  • Metronome rate cards updated
  • Auto‑billing tests updated and passing

QA

  • QA done
  • QA not required

Comms

  • Informed Kosinkadink

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Video stream handling now skips undecodable audio and template streams without a codec context, logging warnings instead of proceeding with invalid streams. Upload conversion errors are also wrapped in a contextual ValueError that preserves the original exception. Tiny fix, big sigh of relief—no codec chaos.

Estimated code review effort: 🎯 2 (Simple) | ⏱️ ~15 minutes

Related issues: None specified

Related PRs: None specified

Suggested labels: bug, video, error-handling

Suggested reviewers: Not enough information to suggest specific reviewers

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/core/mov-spatial-audio
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/core/mov-spatial-audio

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.

🧹 Nitpick comments (1)
comfy_api_nodes/util/upload_helpers.py (1)

161-168: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Broad except Exception in new code.

Catching generic Exception here conflicts with the guideline to prefer specific exception types in new code. That said, save_to can raise a wide variety of errors (PyAV, OS, ValueError), and this is a top-level boundary meant to translate any conversion failure into a friendly message, so the broad catch is arguably justified here.

As per coding guidelines: "Prefer specific exception types when changing new code."

🤖 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_nodes/util/upload_helpers.py` around lines 161 - 168, The new
upload conversion boundary in the video save path is catching a generic
Exception, which conflicts with the preferred exception-handling guideline.
Update the try/except around video.save_to in upload_helpers to catch only the
specific failure types it can raise here (for example the relevant PyAV/codec/OS
exceptions, or a narrowly scoped tuple of known errors) and still re-raise the
same friendly ValueError message with the original error attached. Keep the
behavior localized to the save_to conversion flow and avoid broad exception
handling unless there is no narrower alternative.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@comfy_api_nodes/util/upload_helpers.py`:
- Around line 161-168: The new upload conversion boundary in the video save path
is catching a generic Exception, which conflicts with the preferred
exception-handling guideline. Update the try/except around video.save_to in
upload_helpers to catch only the specific failure types it can raise here (for
example the relevant PyAV/codec/OS exceptions, or a narrowly scoped tuple of
known errors) and still re-raise the same friendly ValueError message with the
original error attached. Keep the behavior localized to the save_to conversion
flow and avoid broad exception handling unless there is no narrower alternative.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: df0c7078-7d3b-494e-b1ac-3d5cb0246f18

📥 Commits

Reviewing files that changed from the base of the PR and between 77917ed and 0c316c5.

📒 Files selected for processing (2)
  • comfy_api/latest/_input_impl/video_types.py
  • comfy_api_nodes/util/upload_helpers.py

Signed-off-by: bigcat88 <bigcat88@icloud.com>
@bigcat88 bigcat88 force-pushed the fix/core/mov-spatial-audio branch from 0c316c5 to 15f94d0 Compare July 3, 2026 13:30

@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)

441-475: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Fail remux when the primary video stream can't be templated
The reuse path only logs and skips streams with no codec_context, so an undecodable video stream can still take this branch and come out audio-only (or empty) instead of failing. Raise a clear error when the video track can’t be reused, rather than letting the picture disappear like a bad magic trick.

🤖 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 441 - 475, The
remux path in the stream-copy logic is currently skipping streams with missing
codec_context, which can let the primary video track disappear silently. Update
the reuse_streams branch in the save/remux flow so that the main video stream
must be templatable: if the video stream (or any required video track) has no
codec_context, raise a clear error instead of continuing. Keep the existing skip
behavior only for non-required streams, and use the existing stream handling
around container.streams and output_container.add_stream_from_template to locate
the fix.

Source: Coding guidelines

🤖 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_nodes/util/upload_helpers.py`:
- Around line 161-168: The upload helper is using a broad catch-all around the
video remux/encode path in the save_to call, which should be narrowed if PyAV
exposes a reliable failure type. In upload_helpers.py, review the exception
hierarchy for video.save_to in the remux_video_to_container helper and replace
the generic except Exception with the specific PyAV/ffmpeg errors that can occur
there (and any clearly related I/O/ValueError cases), while keeping the same
chained ValueError message for user-facing context. If the API surface is
uncertain, confirm the documented PyAV error types before changing the handler
so unrelated bugs are not swallowed.

---

Outside diff comments:
In `@comfy_api/latest/_input_impl/video_types.py`:
- Around line 441-475: The remux path in the stream-copy logic is currently
skipping streams with missing codec_context, which can let the primary video
track disappear silently. Update the reuse_streams branch in the save/remux flow
so that the main video stream must be templatable: if the video stream (or any
required video track) has no codec_context, raise a clear error instead of
continuing. Keep the existing skip behavior only for non-required streams, and
use the existing stream handling around container.streams and
output_container.add_stream_from_template to locate the fix.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 68e54ad9-a05a-4d5b-a367-76f12dfaad26

📥 Commits

Reviewing files that changed from the base of the PR and between 0c316c5 and 15f94d0.

📒 Files selected for processing (2)
  • comfy_api/latest/_input_impl/video_types.py
  • comfy_api_nodes/util/upload_helpers.py

Comment thread comfy_api_nodes/util/upload_helpers.py
@alexisrolland alexisrolland added the cursor-review Trigger multi-model Cursor code review label Jul 4, 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 @alexisrolland.

Found 2 finding(s).

Severity Count
🟡 Medium 1
⚪ Nit 1

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_nodes/util/upload_helpers.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cursor-review Trigger multi-model Cursor code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants