Credit to: https://github.com/Azmarie/Face-Morphing
This repo is an upgrade where we can morph multiple images into video.
Check out Azmarie's repo first to understand all the details.
- Place your images in a folder, for example
raw_images
- Use the command
python code/utils/align_images.py raw_images/ aligned_images/ --output_size=1024
to select images from "raw_images" with a face and align/rotate them and put them in "aligned_images". - Launch the command to create the video :
python code/__init__.py --folder aligned_images --output video_output.mp4 --duration 4
Note that this will create temporary videos (--tmpfolder
) and then combine them into one video (--output
).
Results :
--img1
: The First Image (not necessary when--folder
is used)--img2
: The Second Image (not necessary when--folder
is used)--folder
: The folder with all images to morph (not necessary when--img1
and--img2
are used)--duration
: The duration of morphing from one image to the other.--frame
: The frame rate of the encoding.--output
: Final video path.--tmpfolder
: Folder to store intermediate videos.
- The program goes through all the images in
--folder
with a for loop - For each 2 images we apply what was done by Azmarie's original repo and this outputs a video. We store them in
--tmpfolder
- We append to a text file named
imageslist.txt
the names of the videos like so :file '<filename_of_the_video>'
- After dealing with all images we can encode one big video using
imageslist.txt
and the right ffmpeg command:
ffmpeg -f concat -safe 0 -i imageslist.txt -c copy output.mp4
Note: This is not the most optimized way to do it but it works. It would be better to directly encode one video but it would be a lot of work on Azmarie's work to do.