Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add messages for exceptions #245

Open
wants to merge 12 commits into
base: experimental
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ __pycache__/
.tmp/
temp/
venv/
env/
workflow/
gfpgan/
models/inswapper_128.onnx
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Choose a face (image with desired face) and the target image/video (image/video
Just follow the clicks on the screenshot
1. Select a face
2. Click live
3. Wait for a few second (it takes a longer time, usually 10 to 30 seconds before the preview shows up)
3. Wait for a few seconds (it takes a longer time, usually 10 to 30 seconds before the preview shows up)

![demo-gif](demo.gif)

Expand Down Expand Up @@ -166,10 +166,14 @@ options:

Looking for a CLI mode? Using the -s/--source argument will make the run program in cli mode.

## Want the Next Update Now?
If you want the latest and greatest build, or want to see some new great features, go to our [experimental branch](https://github.com/hacksider/Deep-Live-Cam/tree/experimental) and experience what the contributors have given.

## Credits
- [henryruhs](https://github.com/henryruhs): for being an irreplaceable contributor to the project

- [ffmpeg](https://ffmpeg.org/): for making video related operations easy
- [deepinsight](https://github.com/deepinsight): for their [insightface](https://github.com/deepinsight/insightface) project which provided a well-made library and models.
- [havok2-htwo](https://github.com/havok2-htwo) : for sharing the code for webcam
- [GosuDRM](https://github.com/GosuDRM/nsfw-roop) : for uncensoring roop
- and all developers behind libraries used in this project.
- and [all developers](https://github.com/hacksider/Deep-Live-Cam/graphs/contributors) behind libraries used in this project.
- Foot Note: [This is originally roop-cam, see the full history of the code here.](https://github.com/hacksider/roop-cam) Please be informed that the base author of the code is [s0md3v](https://github.com/s0md3v/roop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (documentation): Change 'Foot Note' to 'Footnote'.

41 changes: 6 additions & 35 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,8 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
preview_button = ctk.CTkButton(root, text='Preview', cursor='hand2', command=lambda: toggle_preview())
preview_button.place(relx=0.65, rely=0.80, relwidth=0.2, relheight=0.05)

# --- Camera Selection ---
camera_label = ctk.CTkLabel(root, text="Select Camera:")
camera_label.place(relx=0.4, rely=0.86, relwidth=0.2, relheight=0.05)

available_cameras = get_available_cameras()

# Convert camera indices to strings for CTkOptionMenu
available_camera_strings = [str(cam) for cam in available_cameras]

camera_variable = ctk.StringVar(value=available_camera_strings[0] if available_camera_strings else "No cameras found")
camera_optionmenu = ctk.CTkOptionMenu(root, variable=camera_variable,
values=available_camera_strings)
camera_optionmenu.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05)

live_button = ctk.CTkButton(root, text='Live', cursor='hand2', command=lambda: webcam_preview(int(camera_variable.get())))
live_button.place(relx=0.15, rely=0.86, relwidth=0.2, relheight=0.05)
# --- End Camera Selection ---
live_button = ctk.CTkButton(root, text='Live', cursor='hand2', command=lambda: webcam_preview())
live_button.place(relx=0.40, rely=0.86, relwidth=0.2, relheight=0.05)

status_label = ctk.CTkLabel(root, text=None, justify='center')
status_label.place(relx=0.1, rely=0.9, relwidth=0.8)
Expand Down Expand Up @@ -264,18 +249,14 @@ def update_preview(frame_number: int = 0) -> None:
image = ctk.CTkImage(image, size=image.size)
preview_label.configure(image=image)

def webcam_preview(camera_index: int):
def webcam_preview():
if modules.globals.source_path is None:
# No image selected
return

global preview_label, PREVIEW

cap = cv2.VideoCapture(camera_index)
if not cap.isOpened():
update_status(f"Error: Could not open camera with index {camera_index}")
return

cap = cv2.VideoCapture(0) # Use index for the webcam (adjust the index accordingly if necessary)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 960) # Set the width of the resolution
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 540) # Set the height of the resolution
cap.set(cv2.CAP_PROP_FPS, 60) # Set the frame rate of the webcam
Expand Down Expand Up @@ -312,14 +293,4 @@ def webcam_preview(camera_index: int):
ROOT.update()

cap.release()
PREVIEW.withdraw() # Close preview window when loop is finished

def get_available_cameras():
"""Returns a list of available camera indices."""
available_cameras = []
for index in range(10): # Check for cameras with index 0 to 9
cap = cv2.VideoCapture(index)
if cap.isOpened():
available_cameras.append(index)
cap.release()
return available_cameras
PREVIEW.withdraw() # Close preview window when loop is finished
5 changes: 3 additions & 2 deletions modules/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def run_ffmpeg(args: List[str]) -> bool:
subprocess.check_output(commands, stderr=subprocess.STDOUT)
return True
except Exception:
pass
print(' '.join(commands), "failed, please check the ffmpeg installation!")
exit(-1)
return False


Expand All @@ -38,7 +39,7 @@ def detect_fps(target_path: str) -> float:
numerator, denominator = map(int, output)
return numerator / denominator
except Exception:
pass
print(' '.join(commands), "failed, please check the ffprobe installation!")
return 30.0


Expand Down