Face Swapping Videos with Roop and Stable Diffusion (Deepfake tutorial)

Updated
Face Swapping Videos with Roop and Stable Diffusion (Deepfake tutorial)
Learn to create lifelike face swaps in videos with Roop and Stable Diffusion in this comprehensive guide.

1. Introduction

Welcome to this comprehensive guide on using the Roop extension for face swapping videos in Stable Diffusion. Roop is a powerful tool that allows you to seamlessly swap faces and achieve lifelike results. Whether you're an artist, a content creator, or simply someone looking to have fun with image manipulation, this guide will provide you with the steps to harness the power of Roop.

2. Requirements

Before we start face swapping with Roop, let's look at what you need:

Stable Diffusion

To begin, you must have Stable Diffusion installed. If you haven't installed it yet, you can check our easy-to-follow Stable Diffusion installation guide.

Roop Extension

If you don't have the Roop extension installed, you can watch our step-by-step video tutorial on YouTube.

How to Face Swap in Stable Diffusion | Roop Extension

Initial Video

You'll need a starting video that you'll convert into a series of JPEG images. You can do this using Adobe Media Encoder or another program of your choice, but we'll explain more about that later.

Now that we have the necessary requirements in place, let's proceed to the face-swapping process.

Stable Diffusion in the Cloud⚡️Run Automatic1111 in your browser in under 90 seconds
20% bonus on first deposit

3. Making a JPEG Sequence

To initiate the face swap process on a video, the initial step involves converting the video into a sequence of JPEG images. I will be utilizing Adobe Media Encoder for this task because it's the program I'm most comfortable with, but you are free to choose any alternative software that suits your preferences.

Begin by placing your original video into the queue, and then select “H.264” under the Format Section. (Please note that the format option may appear differently depending on the type of video you're working with). face-swap-video-roop-deepfake-media-encoder-queue.webp

Next up in the Export Settings, click on “Format:” and select JPEG. face-swap-video-roop-deepfake-media-encoder-jpeg.webp

Now click on “Output Name:”, here you want to select your destination folder. I recommend creating an empty folder named “output”, where your JPEG sequence will be saved.

face-swap-video-roop-deepfake-media-encoder-output.webp

Simply kick off the queue by clicking the green play button located in the upper-right corner.

4. Face Swap with Roop in img2img

Roop utilizes a two-stage approach for face swapping. Initially, it fully renders the image, followed by the application of the Roop image's face onto the generated AI image. This differentiation becomes noticeable during the rendering phase when the image seems complete but takes additional time for the face application.

However, we will fine-tune the settings to ensure that the original image remains completely unaltered, so that only the face swap is executed.

Step-by-Step Face Swapping Process

Navigate to the img2img tab.

Within the img2img tab, drag a frame from your JPEG sequence, and make the following adjustments to the settings:

  • Sampling method: Choose "Euler a."
  • Width & Height: Ensure that you maintain the same aspect ratio as your original image. In my instance, I will use dimensions of 720 by 1280. Denoising strength: Set this to 0 to guarantee that the original image remains unchanged, allowing only the Roop extension to perform its enhancements.

You can leave the rest of the settings at their default values. face-swap-video-roop-deepfake-img2img-settings.webp

Access the Roop extension by selecting it within the img2img settings.

Activate Roop by checking the corresponding checkbox, and then import a high-quality image of the desired face into the extension. Ensure that the subject in the image is facing the camera directly and is well-illuminated. In this guide, we will use Margot Robbie's image as an example.

For the "Restore Face" option, you have two choices:

  • None: Opt for this if your video displays significant movement and contains grain or noise.
  • CodeFormer: Choose this option if your video has minimal movement and is of high quality. I recommend experimenting with both options to determine which one yields the best outcome. Leave the other settings unaltered.

face-swap-video-roop-deepfake-roop-settings.webp

Click the "Generate" button to initiate the face-swapping process. Once you are content with the result, you can proceed with face-swapping your video.

Stable Diffusion in the Cloud⚡️Run Automatic1111 in your browser in under 90 seconds

5. Face swapping your video with Roop

With all the preparations complete, let's initiate the face swap process for the JPEG Sequence. Begin by accessing img2img and navigate to the "Batch" tab.

For the Input directory, duplicate the path from our JPEG Sequence folder. You can accomplish this by holding down the Shift key and right-clicking on the folder we recently established, then selecting "Copy as path." Ensure that you remove any quotation marks from the Input directory.

Create an empty folder to serve as the Output directory and follow the same procedure as before. face-swap-video-roop-deepfake-batch-settings.webp

Now, proceed by transferring the settings that we applied in the img2img settings. If you haven't closed Stable Diffusion, these settings should already be set up.

Afterward, click the "generate" button and patiently wait as Roop handles all the tasks for you. The duration of this process will vary depending on your graphics card and the image resolution, typically ranging from 7 to 12 seconds per frame.

6. Converting JPEG sequence to Video

After completing the generation processes for Stable Diffusion and Roop, you will have a collection of individual frames. To transform these frames into a video file, we will employ Adobe Media Encoder once more. While there are alternative programs capable of performing this task, my expertise lies primarily with Media Encoder.

Within Adobe Media Encoder, locate the "Queue" section and click the "+" symbol. Next, navigate to the directory where Stable Diffusion has stored all the face-swapped images, and select the first image. Ensure that the "PNG File Sequence" option is activated, and then click "Open." face-swap-video-roop-deepfake-media-encoder-select-frame.webp

Next up, as we did previously, under format change it to H.264, select your output name and destination folder and hit “ OK”. Press the green play button to start converting and you’re all done!

Stable Diffusion in the Cloud⚡️Run Automatic1111 in your browser in under 90 seconds

7. Face Swap Example (Deepfake with Roop)

In this section, we will showcase a collection of captivating and impressive face swap demonstrations made possible by the Stable Diffusion Roop Extension. Get ready for an extraordinary visual experience like no other.

Margot Robbie

8. Conclusion

Congratulations on mastering the art of face swapping using the Roop extension with Stable Diffusion. By following the steps and considerations outlined in this guide, you can create amazingly realistic face swaps, both in images and videos. The Roop extension in Stable Diffusion empowers you to explore your creativity and experiment with face swaps, whether for artistic purposes or simply for fun. Enjoy the process of transforming images and videos and unlocking new possibilities with Roop!

Frequently Asked Questions

Yes, while Adobe Media Encoder is recommended, you can use other software of your choice for this step, depending on your preferences.

Roop offers a user-friendly interface and powerful capabilities for realistic face swaps, making it an excellent choice for artists, content creators, and those interested in image manipulation.

No, this guide provides step-by-step instructions suitable for beginners. Basic computer skills are sufficient to get started.

The duration varies based on your hardware and image resolution but generally ranges from 7 to 12 seconds per frame for the face-swapping process.

character creation tool card

AI Image Generation Tool

Create Your AI Images in Seconds!

News & Updates