Page 1 of 1

Convert from frames to video

Posted: Wed Nov 04, 2020 2:28 am
by Erik Loo

I noticed quite a few people have trouble converting frames to video. This can actually be done quite easily with OpenCV.
You just need to:
Step 1. Install OpenCV-Python. The instructions can be found at https://pypi.org/project/opencv-python/
Step 2: Create an image folder to store all the swapped images.
Step 3: Create a Python script and copy and paste the following code:

########

Code: Select all

import cv2
import numpy as np
import glob

img_array = []
# note glob does not take absolute or relative path
for filename in glob.glob('images/*.png'):
    img = cv2.imread(filename)
    height, width, layers = img.shape
    # cv2.imshow('img', img)
    print("processing..." + filename)
    size = (width, height)
    img_array.append(img)

print("Outputting file...")
out = cv2.VideoWriter('ouput.avi', cv2.VideoWriter_fourcc(*'DIVX'),30, size)

for i in range(len(img_array)):
    print("writing img " + str(i) + "/" + str(len(img_array)))
    out.write(img_array[i])
out.release()

#########
Notes: Make sure your python script is at the same subdirectory level as the image folder.

Step 4:Run the script and be patient.

Hope it helps. My gratitude towards the developers of Faceswap . :-)


Re: Convert from frames to video

Posted: Thu Nov 05, 2020 7:32 pm
by torzdf

We actually have the EFFMPEG tool to do exactly this, but it doesn't hurt to have another method.