Skip to content

rs2v shot infer: stream save video, support deploy worker, va_control…#934

Merged
helloyongyang merged 1 commit intomainfrom
rs2v_deploy
Mar 10, 2026
Merged

rs2v shot infer: stream save video, support deploy worker, va_control…#934
helloyongyang merged 1 commit intomainfrom
rs2v_deploy

Conversation

@huochaitiantang
Copy link
Collaborator

rs2v shot infer:

  1. stream save video
  2. support deploy worker
  3. va_controller fix div 0 error

@helloyongyang helloyongyang merged commit 08f1f3c into main Mar 10, 2026
2 checks passed
@helloyongyang helloyongyang deleted the rs2v_deploy branch March 10, 2026 08:34
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the rs2v shot inference pipeline by integrating streaming video capabilities and laying the groundwork for distributed worker deployment. It refactors video and audio handling to leverage a VAController for real-time output, ensuring more efficient resource management and providing a mechanism for stopping ongoing processes. Additionally, a critical bug related to division by zero in the VAController's interval calculation has been addressed, contributing to overall system reliability.

Highlights

  • Stream Video Saving: Implemented functionality to stream and save video output, moving away from traditional file-based saving for improved efficiency and real-time processing.
  • Worker Deployment Support: Added foundational support for deploying workers, enhancing the scalability and distributed processing capabilities of the system.
  • VAController Division by Zero Fix: Resolved a potential division by zero error within the VAController, improving the robustness and stability of video/audio control operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lightx2v/shot_runner/rs2v_infer.py
    • Removed direct file saving utilities (os, save_audio, save_to_video) and introduced VAController for stream management.
    • Integrated VAController initialization and usage within the generate method to manage video and audio streams.
    • Added a check_stop mechanism to allow for stopping the pipeline during execution.
    • Refactored video and audio segment processing to support streaming, including conversion to ComfyUI image format for live publishing.
    • Implemented a try...finally block to ensure proper cleanup of the VAController resources.
  • lightx2v/shot_runner/shot_base.py
    • Added clip_name and va_controller attributes to the ShotPipeline class for better management of clip configurations and video/audio control.
    • Exposed config and stop_signal as properties to allow external control and access to pipeline settings.
  • lightx2v/utils/va_controller.py
    • Corrected the slice_interval calculation to prevent division by zero errors by ensuring the divisor is at least one.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant changes to the video generation pipeline, focusing on streaming capabilities, refactoring video/audio saving, and enabling worker deployment for the RS2V inference pipeline. However, critical security vulnerabilities have been identified, as the VAController exposes the application to GStreamer pipeline injection and arbitrary file write vulnerabilities due to unvalidated user-supplied paths and URLs in system commands. These issues are particularly critical given the intended deployment as a worker service. Furthermore, the fix for a division-by-zero error in va_controller.py is flawed and can still result in a crash if record_fps is zero. There is also a potential issue with passing None to pub_livestream for the gen_video argument, which could lead to unexpected behavior.

# run input encoder only once, get the target shape, init video recorder
rs2v.input_info = clip_input_info
rs2v.inputs = rs2v.run_input_encoder()
self.va_controller = VAController(rs2v)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-high high

The instantiation of VAController with rs2v (which contains unvalidated user input from clip_input_info) leads to several security vulnerabilities in the underlying components. Since this tool is intended to be deployed as a worker, these inputs are potentially attacker-controlled.

  1. GStreamer Pipeline Injection: In VAReader.start_ffmpeg_process_whep (in va_reader.py), the stream_url (derived from audio_path) is interpolated directly into a GStreamer pipeline string: f"whep-endpoint={self.stream_url}". An attacker could provide a malicious URL containing GStreamer elements (e.g., using ! separators) to manipulate the pipeline, potentially leading to arbitrary file writes (via filesink) or other unintended behaviors.
  2. Arbitrary File Write / Argument Injection: In VARecorder.start_ffmpeg_process_local (in va_recorder.py), the livestream_url (derived from save_result_path) is passed as an output argument to ffmpeg. This allows an attacker to overwrite arbitrary files on the system or inject additional ffmpeg arguments if the path starts with a dash.

It is recommended to implement strict validation and sanitization for all file paths and URLs provided by users before passing them to system commands or complex parsers.

elif self.va_controller.recorder is not None:
video_seg = torch.clamp(video_seg, -1, 1).to(torch.float).cpu()
video_seg = vae_to_comfyui_image_inplace(video_seg)
self.va_controller.pub_livestream(video_seg, audio_seg, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Passing None as the gen_video argument to self.va_controller.pub_livestream can lead to issues. The VARecorder.buffer_stream method (which pub_livestream calls when realtime is true) stores this gen_video in its stream_buffer. Later, VARecorder.truncate_stream_buffer might attempt to return this gen value, which would be None, potentially causing NoneType errors or unexpected behavior if the caller expects a tensor. It appears gen_latents (from line 92) would be the appropriate tensor to pass here.

Suggested change
self.va_controller.pub_livestream(video_seg, audio_seg, None)
self.va_controller.pub_livestream(video_seg, audio_seg, gen_latents)

self.slice_frame = config.get("slice_frame", self.prev_frame_length)
# estimate the max infer seconds, for immediate switch with local omni
slice_interval = self.slice_frame / self.record_fps
slice_interval = max(1, self.slice_frame / self.record_fps)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The fix for the division by zero error is incorrect. The expression self.slice_frame / self.record_fps is evaluated before the max(1, ...) function is called. If self.record_fps is zero, a ZeroDivisionError will still be raised. To properly fix this, the max function (or another check) should be applied to the divisor to ensure it is non-zero before the division occurs.

Suggested change
slice_interval = max(1, self.slice_frame / self.record_fps)
slice_interval = max(1, self.slice_frame / (self.record_fps if self.record_fps > 0 else 1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants