hacksider / Deep-Live-Cam

real time face swap and one-click video deepfake with only a single image
GNU Affero General Public License v3.0
41.22k stars 6.01k forks source link

- #768

Closed KRSHH closed 3 weeks ago

KRSHH commented 3 weeks ago

Summary by Sourcery

Enhance the webcam preview functionality by introducing a virtual camera feature and optimizing performance through dynamic scaling and caching. Improve camera initialization settings for better frame processing efficiency.

New Features:

Enhancements:

sourcery-ai[bot] commented 3 weeks ago

Reviewer's Guide by Sourcery

This PR implements significant performance improvements to the webcam preview and face swapping functionality. The changes focus on optimizing camera settings, implementing adaptive frame processing, adding virtual camera support, and enhancing face swapping performance through better VRAM utilization and face caching.

Sequence diagram for webcam preview and face swapping

sequenceDiagram
    participant User
    participant UI
    participant Camera
    participant FrameProcessor
    participant VCam

    User->>UI: Start webcam preview
    UI->>Camera: Initialize with optimized settings
    Camera-->>UI: Return camera dimensions
    UI->>VCam: Initialize virtual camera
    loop Every frame
        Camera->>UI: Capture frame
        UI->>FrameProcessor: Process frame
        FrameProcessor-->>UI: Return processed frame
        UI->>VCam: Send frame to virtual camera
        VCam-->>UI: Confirm frame sent
    end
    User->>UI: Stop webcam preview
    UI->>Camera: Release camera
    UI->>VCam: Release virtual camera

Updated class diagram for frame processing

classDiagram
    class FrameProcessor {
        +process_frame(source_face: Face, temp_frame: Frame) : Frame
        +process_frame_v2(temp_frame: Frame) : Frame
        +_cache: dict
    }
    class FaceSwapper {
        +get_face_swapper() : Any
        +swap_face(source_face: Face, target_face: Face, temp_frame: Frame) : Frame
    }
    FrameProcessor --> FaceSwapper
    note for FrameProcessor "Added caching for repeated faces"
    note for FaceSwapper "Set optimal inference parameters for VRAM usage"

File-Level Changes

Change Details Files
Implemented optimized webcam capture and virtual camera support
  • Added optimized camera settings including buffer size and FPS
  • Integrated virtual camera support with matching dimensions
  • Added proper camera cleanup and resource management
modules/ui.py
Added adaptive frame processing for performance optimization
  • Implemented dynamic process scaling based on performance metrics
  • Added frame skipping mechanism for maintaining target FPS
  • Improved frame interpolation methods for better quality
  • Added gradual performance-based scaling adjustments
modules/ui.py
Enhanced face swapping performance and quality
  • Implemented face caching mechanism for repeated faces
  • Optimized CUDA execution provider settings for maximum VRAM usage
  • Added exhaustive algorithm search for optimal performance
  • Implemented aggressive memory allocation strategy
modules/processors/frame/face_swapper.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
KRSHH commented 3 weeks ago

@sourcery-ai review