ai-forever / ghost

A new one shot face swap approach for image and video domains
Apache License 2.0
1.25k stars 265 forks source link

Make possible to save the final frames to a separate (temp) folder during video processing #31

Closed netrunner-exe closed 2 years ago

netrunner-exe commented 2 years ago

Hello! Please make it possible to save the final frames to a separate folder during video processing, as it is implemented in SimSwap. This is convenient when you can view a frame if a long video is being processed so as not to waste time if the result turns out to be bad. Or it will give the opportunity to make a GIF from these frames yourself. Thanks!

quantarb commented 2 years ago

Here you go. I modified the colab notebook. This notebook does the following.

  1. Iterate through each image zip file or video file in your dst folder.
  2. Extract images from the zip file or video file into a temp folder.
  3. Attempts to sber swap each image in the temp folder and saves the swapped image in the swapped folder.
  4. If the original file was a zip, it will zipped all the images and save it as a zip file with the same name in the result folder.
  5. If the original file was a video file it will make a video from all the swapped images and save it with the name in the result folder.

https://colab.research.google.com/gist/quantarb/6327c2ef8f72ebeb0e41541f8476f4ce/sber-swap.ipynb

netrunner-exe commented 2 years ago

Here you go. I modified the colab notebook. This notebook does the following.

1. Iterate through each image zip file or video file in your dst folder.

2. Extract images from the zip file or video file into a temp folder.

3. Attempts to sber swap each image in the temp folder and saves the swapped image in the swapped folder.

4. If the original file was a zip, it will zipped all the images and save it as a zip file with the same name in the result folder.

5. If the original file was a video file it will make a video from all the swapped images and save it with the name in the result folder.

https://colab.research.google.com/gist/quantarb/5073703261652edde5464db0cacd9059/sber-swap.ipynb

Big thanks for the reply and for the link! At the moment I'm using my own version of Colab and using video processing either as written in the readme. Yes, I can export video to frames with FFmpeg or opencv and batch process the images and then assemble them into a video or GIF, but I mean it would be great to have the option like --save_frames to save the final images during processing in a separate folder! Thanks

aesanchezgh commented 2 years ago

In video_processing.py there is a function read_video. In that function you could simply save the images to disk.

netrunner-exe commented 2 years ago

In video_processing.py there is a function read_video. In that function you could simply save the images to disk.

Hey! If I understand correctly, this function is responsible for counting frames from the video, but I meant to save full frames with the face already replaced. I tried to add in def get_final_video something like cv2.imwrite("/content/sber-swap/tmp_frames", result_frames[i]) but unfortunately I'm not strong in Python to do it right.

quantarb commented 2 years ago

I added a new parameter called save_swaps. If you check this option or set this value to True, it will save the swapped images for a video file as well as the video itself. Please see the updated colab notebook below.

https://colab.research.google.com/gist/quantarb/6327c2ef8f72ebeb0e41541f8476f4ce/sber-swap.ipynb

Lyntai commented 2 years ago

I added a new parameter called save_swaps. If you check this option or set this value to True, it will save the swapped images for a video file as well as the video itself. Please see the updated colab notebook below.

https://colab.research.google.com/gist/quantarb/6327c2ef8f72ebeb0e41541f8476f4ce/sber-swap.ipynb

You did a splendid job, congrats! I tried the multiple functions and they work very well, I just have a question: I noticed that the swapped face is the first one encountered on dest or the one we place on the target folder, is there a simple way to swap every face in the images/videos?

quantarb commented 2 years ago

I added a new parameter called save_swaps. If you check this option or set this value to True, it will save the swapped images for a video file as well as the video itself. Please see the updated colab notebook below. https://colab.research.google.com/gist/quantarb/6327c2ef8f72ebeb0e41541f8476f4ce/sber-swap.ipynb

You did a splendid job, congrats! I tried the multiple functions and they work very well, I just have a question: I noticed that the swapped face is the first one encountered on dest or the one we place on the target folder, is there a simple way to swap every face in the images/videos?

Not to my knowledge. You would need to pass in all face images in the target_face_paths to swap all the faces.