Skip to content

Instantly share code, notes, and snippets.

@woctezuma
Last active Jun 21, 2021
Embed
What would you like to do?
Export GIF with SimSwap

References:

At the start of the notebook, ensure the logo is removed:

%cd /content
%rm -rf SimSwap
!git clone https://github.com/woctezuma/SimSwap
%cd SimSwap
!git checkout no-logo

If you want to apply SimSwap to a GIF, there will be an error because the input video has no audio.

To fix this issue, collate the temporary image outputs at the end of the notebook:

import os 
import cv2
import glob
from moviepy.video.io.ImageSequenceClip import ImageSequenceClip

input_fname = '/content/SimSwap/video.gif'
temp_results_dir = '/content/SimSwap/tmp/'
output_fname = '/content/output.gif'

video_path = input_fname
video = cv2.VideoCapture(video_path)
fps = video.get(cv2.CAP_PROP_FPS)

path = os.path.join(temp_results_dir,'*.jpg')
image_filenames = sorted(glob.glob(path))

clips = ImageSequenceClip(image_filenames,fps = fps)
clips.write_gif(output_fname)

To optimize the file size (in MB) of the GIF, you can upload it to a website like https://ezgif.com/optimize

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