Skip to content

Commit

Permalink
camera: allow udp stream through ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyabsi committed Feb 13, 2024
1 parent 05814e7 commit 2b0b3fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion BabbleApp/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def run(self):
if self.cancellation_event.wait(WAIT_TIME):
return
self.current_capture_source = self.config.capture_source
self.cv2_camera = cv2.VideoCapture(self.current_capture_source)
if self.config.use_ffmpeg == True:
self.cv2_camera = cv2.VideoCapture(self.current_capture_source, cv2.CAP_FFMPEG)
else:
self.cv2_camera = cv2.VideoCapture(self.current_capture_source)
if not self.settings.gui_cam_resolution_x == 0: self.cv2_camera.set(cv2.CAP_PROP_FRAME_WIDTH, self.settings.gui_cam_resolution_x)
if not self.settings.gui_cam_resolution_y == 0: self.cv2_camera.set(cv2.CAP_PROP_FRAME_HEIGHT, self.settings.gui_cam_resolution_y)
if not self.settings.gui_cam_framerate == 0: self.cv2_camera.set(cv2.CAP_PROP_FPS, self.settings.gui_cam_framerate)
Expand Down
8 changes: 6 additions & 2 deletions BabbleApp/camera_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,18 @@ def render(self, window, event, values):
):
print("\033[94m[INFO] New value: {}\033[0m".format(values[self.gui_camera_addr]))
try:
self.config.use_ffmpeg = False
# Try storing ints as ints, for those using wired cameras.
self.config.capture_source = int(values[self.gui_camera_addr])
except ValueError:
if values[self.gui_camera_addr] == "":
self.config.capture_source = None
else:
if len(values[self.gui_camera_addr]) > 5 and "http" not in values[self.gui_camera_addr] and ".mp4" not in values[self.gui_camera_addr]: # If http is not in camera address, add it.
self.config.capture_source = f"http://{values[self.gui_camera_addr]}/"
if len(values[self.gui_camera_addr]) > 5 and "http" not in values[self.gui_camera_addr] and ".mp4" not in values[self.gui_camera_addr] and "udp" not in values[self.gui_camera_addr]: # If http is not in camera address, add it.
self.config.capture_source = f"http://{values[self.gui_camera_addr]}/"
elif "udp" in values[self.gui_camera_addr]:
self.config.use_ffmpeg = True
self.config.capture_source = values[self.gui_camera_addr]
else:
self.config.capture_source = values[self.gui_camera_addr]
changed = True
Expand Down
1 change: 1 addition & 0 deletions BabbleApp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BabbleCameraConfig(BaseModel):
use_n_calibration: bool = True
gui_vertical_flip: bool = False
gui_horizontal_flip: bool = False
use_ffmpeg: bool = False

class BabbleSettingsConfig(BaseModel):
gui_min_cutoff: str = "0.9"
Expand Down

0 comments on commit 2b0b3fd

Please sign in to comment.