File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff 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 = [
You can’t perform that action at this time.
0 commit comments