Skip to content

Commit

Permalink
Bugfix: Release processed video handle
Browse files Browse the repository at this point in the history
  • Loading branch information
C0untFloyd committed Jul 28, 2024
1 parent 3e3932c commit c398def
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions roop/capturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def get_video_frame(video_path: str, frame_number: int = 0) -> Optional[Frame]:
global current_video_path, current_capture, current_frame_total

if video_path != current_video_path:
if current_capture is not None:
current_capture.release()
release_video()

current_capture = cv2.VideoCapture(video_path)
current_video_path = video_path
Expand All @@ -33,6 +32,13 @@ def get_video_frame(video_path: str, frame_number: int = 0) -> Optional[Frame]:
return frame
return None

def release_video():
global current_capture

if current_capture is not None:
current_capture.release()
current_capture = None


def get_video_frame_total(video_path: str) -> int:
capture = cv2.VideoCapture(video_path)
Expand Down
2 changes: 1 addition & 1 deletion roop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from roop.ProcessEntry import ProcessEntry
from roop.ProcessMgr import ProcessMgr
from roop.ProcessOptions import ProcessOptions
from roop.capturer import get_video_frame_total
from roop.capturer import get_video_frame_total, release_video


clip_text = None
Expand Down
2 changes: 1 addition & 1 deletion roop/metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'roop unleashed'
version = '4.1.3'
version = '4.1.4'
5 changes: 4 additions & 1 deletion roop/util_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def create_video(target_path: str, dest_filename: str, fps: float = 24.0, temp_d


def create_gif_from_video(video_path: str, gif_path):
from roop.capturer import get_video_frame
from roop.capturer import get_video_frame, release_video

fps = util.detect_fps(video_path)
frame = get_video_frame(video_path)
release_video()

scalex = frame.shape[0]
scaley = frame.shape[1]

if scalex >= scaley:
scaley = -1
else:
Expand All @@ -88,6 +90,7 @@ def create_gif_from_video(video_path: str, gif_path):
run_ffmpeg(['-i', video_path, '-vf', f'fps={fps},scale={int(scalex)}:{int(scaley)}:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse', '-loop', '0', gif_path])



def create_video_from_gif(gif_path: str, output_path):
fps = util.detect_fps(gif_path)
filter = """scale='trunc(in_w/2)*2':'trunc(in_h/2)*2',format=yuv420p,fps=10"""
Expand Down

0 comments on commit c398def

Please sign in to comment.