Arminius-Software / face2video

MIT License
71 stars 5 forks source link

No frames created on extract frames #10

Open abhishekvakharia opened 1 month ago

abhishekvakharia commented 1 month ago
Finished extracting frames from video
Exception in thread Thread-2 (swap_face):
Traceback (most recent call last):
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/abhishekvakharia/workplace/Stable diffusion/extensions/face2video/main.py", line 95, in swap_face
    files = os.listdir("extracted_frames/")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'extracted_frames/'

Facing this issue after

  1. added video in input_video
  2. added face image in input_face
  3. and then did run main.py, and clicked on choose face, choose video
  4. After that clicked on extract frames, it shows message extracted successfully
  5. And on swap face it throws the above error.
Arminius-Software commented 1 month ago

Hello, this looks like a simple pathing error. This script expects the files to be run in the same folder that the created folders are placed in. I created a version that uses the full system path instead. You can find this updated version on the "issue_10_fix" branch (https://github.com/Arminius-Software/face2video/tree/issue_10_fix). Please let me know if this version fixes your issue.

abhishekvakharia commented 1 month ago

Thanks for the quick response @Arminius-Software

Made the following changes (https://github.com/Arminius-Software/face2video/compare/main...abhishekvakharia:face2video:fixPaths). it's a bit different because of the file structure on Mac.

It resolved couple of errors but not again stuck with another path issue

Exception in thread Thread-2 (swap_face):
Traceback (most recent call last):
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/abhishekvakharia/workplace/Stable diffusion/extensions/face2video/main.py", line 108, in swap_face
    automatic1111_api.api_change_face(file, self.input_face, input_model, file_path, self.processing_unit, source_choice)
  File "/Users/abhishekvakharia/workplace/Stable diffusion/extensions/face2video/automatic1111_api.py", line 20, in api_change_face
    with open(input_image, "rb") as image_file:
         ^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/extracted_frames/frame144.png'

Am able to see the files created as well it picks up the path correctly but still throws this error when I click on Swap facce

Arminius-Software commented 1 month ago

I had to pull your code since this error is not present in my version. You simply need to change: 'file_path = os.path.join(self.main_path, "/extracted_frames/", file)' to 'file_path = os.path.join(self.main_path, "extracted_frames", file)' in main.py swap_face (this fixes the error in Windows at least). Please change your pull request from the main branch to the issue_10_fix branch. Once we have fixed all the errors and you can confirm that it runs without error on macOS, we can change that branch into an official mac version.

abhishekvakharia commented 1 month ago

if i directly use the branch I see this error also the extracted_frames folder is empty whereas in the branch I pushed, I was able to create frames in extracted_frames folder

Running] python3 -u "/Users/abhishekvakharia/workplace/Stable diffusion/extensions/face2video/main.py"
Finished extracting frames from video
Exception in thread Thread-2 (swap_face):
Traceback (most recent call last):
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/Users/abhishekvakharia/.pyenv/versions/3.12.4/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/abhishekvakharia/workplace/Stable diffusion/extensions/face2video/main.py", line 96, in swap_face
    files = os.listdir("extracted_frames/")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'extracted_frames/'

if you looked at my branch that worked for extracting frames, only the swap step fails

Arminius-Software commented 1 month ago

It appears that the issue is that having the "/" or "\" symbol causes problems on Mac even if you use the os.path.join function. I can try to replace all those instances with clean names only and then only ever combine things with the os library. The problem here is that I can't recreate the errors that you run into since I don't use macOS.

abhishekvakharia commented 1 month ago

Yes @Arminius-Software you are right removing / helped. got to the next step,I am able to see the response is successful. but now I don't see anything being saved in finished_frames Anything which could be possibly updated?

Once we get through this we can mark it as Mac branch

Screenshot 2024-08-05 at 10 13 54 PM
Arminius-Software commented 1 month ago

Can you check the response in the automatic 1111 console? If the reactor fails to swap/save the image, then it should be displayed there. Also check if the response.status_code returns 200.

Once everything works i will merge all your commits into a Mac Version branch and of course give you credit in the readme as well.

abhishekvakharia commented 1 month ago

yes responses are fine not sure they are not being saved, will test that out. and one it works I will push it to my remote branch and you can take it up from there.

Thanks for the support!

abhishekvakharia commented 1 month ago

Hi @Arminius-Software, I was able to generate video successfully made few changes in the path, I have it on fixPath as well as on main. you can decide how you want to manage branch for Macs. I would push some changes later.

TODO:

  1. put check if the path is already in finished_frames and finished_videos then do not change the directory which is done manually using chdir()

Thank you for the support

Arminius-Software commented 1 month ago

Awesome, I have opened a Mac-Version branch and merged your changes. It would be great if you could confirm that everything was merged correctly and the code on the Mac-Version branch runs on your system. If there are still changes to be made, you can just open another pull request.

abhishekvakharia commented 1 week ago

@Arminius-Software it works verified, and we are good to close this. Thanks a lot

buffoff commented 5 days ago

os.path.join(current_directory, "extensions", "face2video", "finished_frames")

This line was causing issues for me, as I do not have F2V as a subdirectory of A1111

A1111 console:

23:17:33 - ReActor - STATUS - Restoring the face with CodeFormer (weight: 0.5)
23:17:34 - ReActor - ERROR - Error while saving result: [Errno 2] No such file or directory: '/Users/user1/extensions/face2video/finished_frames/frame52.png'

This code in automatic1111_api.py worked for me:

current_directory = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(current_directory, "finished_frames")
Arminius-Software commented 5 days ago

@buffoff thank you for your feedback. I am assuming you are also using macOS? The pathing behaves differently than on Windows. I never had any issues with the face2video folder not being a subfolder of automatic1111 on Windows. Maybe @abhishekvakharia can check if the changes that you suggested also work on his machine. It would be nice if you could open a pull request into the Mac branch for that.

abhishekvakharia commented 5 days ago

@Arminius-Software will check and update, will wait for @buffoff to clarify if he is on Mac, also @buffoff can you share your directory structure

buffoff commented 5 days ago

@buffoff thank you for your feedback. I am assuming you are also using macOS? The pathing behaves differently than on Windows. I never had any issues with the face2video folder not being a subfolder of automatic1111 on Windows. Maybe @abhishekvakharia can check if the changes that you suggested also work on his machine. It would be nice if you could open a pull request into the Mac branch for that.

Apple Silicon, macOS Sonoma 14.6.1, Python 3.12.5

buffoff commented 5 days ago

@Arminius-Software will check and update, will wait for @buffoff to clarify if he is on Mac, also @buffoff can you share your directory structure

.
├── face2video
│   ├── __pycache__
│   ├── extracted_frames
│   ├── finished_frames
│   ├── finished_videos
│   ├── input_faces
│   ├── input_faces_models
│   └── input_videos
└── stable-diffusion-webui
    ├── __pycache__
    ├── cache
    ├── config_states
    ├── configs
    ├── embeddings
    ├── extensions