Skip to content

Commit

Permalink
grab 1 frame from video
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi authored and devxpy committed Jul 30, 2024
1 parent e8ece05 commit 0da6b33
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions retro/sadtalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ def sadtalker(
inputs.source_image,
os.path.join(save_dir, "face" + os.path.splitext(inputs.source_image)[1]),
)
# convert video to jpg (choose the middle frame) to fix oom error when sadtalker tries to load a large video into memory
if face_mime_type.startswith("video/"):
ffprobe = ffprobe_video(input_path)
duration_sec = ffprobe.duration_sec
args = [
"ffmpeg",
"-y",
"-ss", # select the middle frame
str(duration_sec / 2), # select the middle frame
"-i",
input_path,
"-q:v",
"1",
"-frames:v",
"1",
os.path.splitext(input_path)[0] + ".jpg",
]
subprocess.check_output(args, encoding="utf-8")
input_path = os.path.splitext(input_path)[0] + ".jpg"
face_mime_type = "image/jpeg"
# convert image to jpg (to remove transparency) and make smaller than MAX_RES
if face_mime_type.startswith("image/"):
args = [
Expand Down

0 comments on commit 0da6b33

Please sign in to comment.