---
title: 'DreamSwapV: End-to-End Video Subject Swapping'
url: https://www.emergentmind.com/topics/dreamswapv
type: topic
---

# DreamSwapV: End-to-End Video Subject Swapping

DreamSwapV is a mask-guided, subject-agnostic, end-to-end video editing framework targeting generic subject swapping in unconstrained videos. Formulated as a specialized video-inpainting task, DreamSwapV replaces a masked source subject in each frame with a target subject specified via a user-supplied mask and reference image, while preserving the original video’s motion, background, and contextual interactions. The system builds on a diffusion-transformer backbone with a dedicated condition fusion approach, utilizes adaptive mask strategies to accommodate subjects of varying scales and attributes, and undergoes a two-phase dataset construction and training regimen. DreamSwapV establishes new state-of-the-art performance on automatic quantitative and perceptual benchmarks, notably on the DreamSwapV-Benchmark and VBench suite [2508.14465].

## 1. Problem Formulation and Framework Objectives

DreamSwapV formalizes subject swapping within video editing as the inpainting of a masked region, driven by a reference image, while maintaining all remaining spatiotemporal content. Let $V=\{v_t\}_{t=1}^T$ be a sequence of source video frames, with associated binary masks $M^s=\{m_t^s\}_{t=1}^T$ delineating the subject $s$ to swap. The user specifies $m_0^s$ on frame 0; subsequent masks are tracked throughout the sequence. Auxiliary per-frame motion information $P=\{p_t\}_{t=1}^T$ (encompassing 2D/3D human pose and 3D hand pose) provides guidance for accurately modeling dynamic interactions. The target appearance is encoded by a reference image $r^s$.

The objective is to learn a function 
$$
f_\theta: (V \odot (1-M^s), M^s, P, r^s) \rightarrow V'
$$
where $V'$ recovers the background outside the mask and inpaints the masked region with the new subject appearance, preserving motion, temporal coherence, and realistic subject–context relationships. Training is self-supervised: reference $r'$ is sampled from a random source frame via $r' = v_i \odot m_i^s$, and the model is trained to minimize a base diffusion-model loss $L_{pt}$ for reconstructing $V$ from its ablated version. At test time, substituting $r^s$ for $r'$ accomplishes subject swapping [2508.14465].

## 2. Model Architecture and Condition Fusion

DreamSwapV leverages the Wan-I2V-14B diffusion-transformer (a DiT variant) architecture with a 3D-VAE encoder/decoder as its foundation. Its principal architectural innovation is the Condition Fusion Module (CFM), which enables strictly spatial-temporally aligned integration of five conditioning signals: mask, agnostic video (background), pose, hand, and reference.

Latent space projection (via the pretrained 3D-VAE) encodes both the agnostic video $A^s=V \odot (1-M^s)$ and motion sequence $P$ into tensors of shape $[b, f, c, h, w]$. The reference image $r^s$ is encoded separately into a latent $Z^r$ of $[b,1,c,h,w]$, which is then temporally duplicated and concatenated with the video latent along the time axis. This temporal concatenation—combined with a custom self-attention mask enforcing that video tokens attend to all tokens while reference tokens attend only to themselves—enables fine-grained reference injection without feature misalignment or parameter inflation.

The binary mask sequence $M^s$ is reshaped by grouping raw frames and downsampling spatially to match latents. Following zero-padding of the reference in the background and pose streams, final feature fusion is performed via concatenation along the channel dimension:
$$
\text{model\_input} = \text{concat\_channel}[\,\text{latent}(A^s),\, \text{latent}(P),\, \text{mask}\,] \in \mathbb{R}^{b, f, C_{total}, h, w}
$$
The fused representation, augmented by reference tokens in self-attention, is then processed by the diffusion U-Net to predict noise residuals at each denoising step [2508.14465].

## 3. Adaptive Mask Strategy

To mitigate “shape leakage” (overfitting to mask contours) and artifacts from overly coarse masks, DreamSwapV incorporates two complementary mask augmentations:

- **Adaptive Grid Sizing**: Each frame is divided into $K_h \times K_w$ blocks, where $K_h$ and $K_w$ are inversely proportional to subject size. Any grid containing mask pixels is dilated. For training, $K_h^{train} = \lfloor \text{bbox}_h / \text{rand}(h_1, h_2) \rfloor$; for inference, $K_h^{inf} = \lfloor \text{bbox}_h / h_3 \rfloor$ (similarly for width). Larger subjects thus maintain finer mask fidelity, while smaller subjects generalize more effectively.

- **Shape Augmentation**: For 30% of samples, only a bounding-box dilation is applied to produce the coarsest mask. Otherwise, randomly selected geometric shapes (circles, triangles, rectangles) are overlaid at grid boundaries to decouple shape cues from subject content.

These augmentations enhance the robustness of the model across subject categories and scales [2508.14465].

## 4. Training Objectives and Two-Phase Training Regimen

The training objective is built around a diffusion noise-prediction loss $L_{pt}$, commonly used in pre-trained diffusion backbone models. To further bias inpainting accuracy on masked regions—especially small subjects—a subject-region re-weighting loss $L_{rw}$ is introduced:
$$
L_{rw} = (E_{frame} / E_{subject}) \cdot (M^s \odot L_{pt})
$$
where $E_{frame}$ and $E_{subject}$ are pixel counts of the full frame and the subject mask, respectively. The combined objective is
$$
L_{final} = (1 - M^s) \odot L_{pt} + \lambda L_{rw}
$$
with $\lambda$ set empirically.

Dataset construction and training proceed in two phases:

- **Phase 1—Pre-training**: Starting with 8K HumanVID videos, subject captions are generated with TikTok-VFM-7B, and per-frame masks with TrackingSAM. Filtering ensures a balanced subject-type distribution (humans:garments:small:large ≈ 1:0.2:1:1). Poses are extracted using DWPose and Hamer detectors. Reference augmentation (scaling, rotation, flips, brightness) prevents “reference leakage”. Self-attention layers alone are trained initially (15K iterations, 32 H100 GPUs).

- **Phase 2—Quality Tuning**: High-quality reference–video pairs (~800) from AnyInsertion, Subject200K, and AnchorCrafter-400 are converted to video format by Wan-I2V. All parameters are unfrozen for 10K iteration fine-tuning, enhancing generalization to cross-domain inputs.

During inference, for very small masks (<5% area), a “tunnel” inpainting technique (crop → inpaint → blend) is applied to concentrate modeling capacity on fine details [2508.14465].

## 5. Evaluation Protocols and Quantitative Benchmarks

Comprehensive evaluation employs the DreamSwapV-Benchmark—a curated challenge set of 100 videos (Pexels.com) encompassing four aspect ratios and 167 annotated subject instances across diverse categories (humans, animals, apparel, handheld and large objects). The quantitative protocol includes the VBench metrics:

- **Subject Consistency (SC)**
- **Background Consistency (BC)**
- **Motion Smoothness (MS)**
- **Dynamic Degree (DD)**
- **Aesthetic Quality (AQ)**

with per-metric and average scores reported as percentages or normalized values. Two additional automatic metrics are introduced:

- **Reference Appearance (RA)**: measures similarity between swapped subject and reference image.
- **Background Preservation (BP)**: quantifies background similarity between source and output.

A user study collects crowdsourced ratings (1–5 scale) on Reference Detail, Subject Interaction, and Visual Fidelity. Table 1 from the original study summarizes outcomes across methods:

| Method           | Avg. VBench | RA (%) | BP (%) | Reference Detail | Subject Interaction | Visual Fidelity |
|------------------|-------------|--------|--------|------------------|--------------------|----------------|
| AnyV2V           | —           | —      | —      | —                | —                  | —              |
| VACE             | —           | —      | —      | —                | —                  | —              |
| HunyuanCustom    | —           | —      | —      | —                | —                  | —              |
| Kling 1.6        | 79.79       | —      | —      | —                | —                  | —              |
| DreamSwapV       | 80.44       | 45.22  | 52.49  | 3.35             | 3.39               | 3.32           |

DreamSwapV attains the highest VBench average, RA, and BP, and leads human ratings across all perceptual criteria. Notably, AnyV2V suffers from background collapses, while Kling 1.6 sometimes regenerates backgrounds destructively, underscoring DreamSwapV’s robustness [2508.14465].

## 6. Implementation, Practical Constraints, and Future Directions

DreamSwapV’s training utilizes 32 NVIDIA H100 GPUs, with approximately 12.5 days for both pre-training (15K iterations) and tuning (10K iterations). Inference for 720p videos executes at ∼2 seconds/frame. Processing of longer videos is managed via overlapping segments, using a “first-frame dummy reference” to ensure temporal coherence.

Limitations include potential minor hallucinations when references are extremely cross-domain (e.g., large differences in scale/lighting), and the need for manual threshold adjustment in tunnel inpainting for tiny objects. The model currently supports up to 720p resolution.

Future research directions identified include extending DreamSwapV to higher resolutions, integrating explicit temporal-consistency or adversarial losses, augmenting with audio editing capabilities, and enabling combined text + reference conditioning for enhanced control [2508.14465].

Source: https://www.emergentmind.com/topics/dreamswapv