Skip to content

Commit 0da6b33

Browse files
SanderGidevxpy
authored andcommitted
grab 1 frame from video
1 parent e8ece05 commit 0da6b33

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

retro/sadtalker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ def sadtalker(
166166
inputs.source_image,
167167
os.path.join(save_dir, "face" + os.path.splitext(inputs.source_image)[1]),
168168
)
169+
# convert video to jpg (choose the middle frame) to fix oom error when sadtalker tries to load a large video into memory
170+
if face_mime_type.startswith("video/"):
171+
ffprobe = ffprobe_video(input_path)
172+
duration_sec = ffprobe.duration_sec
173+
args = [
174+
"ffmpeg",
175+
"-y",
176+
"-ss", # select the middle frame
177+
str(duration_sec / 2), # select the middle frame
178+
"-i",
179+
input_path,
180+
"-q:v",
181+
"1",
182+
"-frames:v",
183+
"1",
184+
os.path.splitext(input_path)[0] + ".jpg",
185+
]
186+
subprocess.check_output(args, encoding="utf-8")
187+
input_path = os.path.splitext(input_path)[0] + ".jpg"
188+
face_mime_type = "image/jpeg"
169189
# convert image to jpg (to remove transparency) and make smaller than MAX_RES
170190
if face_mime_type.startswith("image/"):
171191
args = [

0 commit comments

Comments
 (0)