Spaces:
Sleeping
Sleeping
File size: 21,604 Bytes
b03a8f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
import os
import time
import numpy as np
os.environ['PYOPENGL_PLATFORM'] = 'egl' # or 'osmesa'
import pyrender
import trimesh
import queue
import imageio
import threading
import multiprocessing
import glob
import subprocess
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
args = {
'render_video_fps': 30,
'render_video_width': 480,
'render_video_height': 720,
'render_concurrent_num': max(1, multiprocessing.cpu_count() - 1) ,
'render_tmp_img_filetype': 'bmp',
'debug': False
}
def deg_to_rad(degrees):
return degrees * np.pi / 180
def create_pose_camera(angle_deg):
angle_rad = deg_to_rad(angle_deg)
return np.array([
[1.0, 0.0, 0.0, 0.0],
[0.0, np.cos(angle_rad), -np.sin(angle_rad), 1.0],
[0.0, np.sin(angle_rad), np.cos(angle_rad), 5.0],
[0.0, 0.0, 0.0, 1.0]
])
def create_pose_light(angle_deg):
angle_rad = deg_to_rad(angle_deg)
return np.array([
[1.0, 0.0, 0.0, 0.0],
[0.0, np.cos(angle_rad), -np.sin(angle_rad), 0.0],
[0.0, np.sin(angle_rad), np.cos(angle_rad), 3.0],
[0.0, 0.0, 0.0, 1.0]
])
def create_scene_with_mesh(vertices, faces, uniform_color, pose_camera, pose_light):
trimesh_mesh = trimesh.Trimesh(vertices=vertices, faces=faces, vertex_colors=uniform_color)
mesh = pyrender.Mesh.from_trimesh(trimesh_mesh, smooth=True)
scene = pyrender.Scene(bg_color=[0, 0, 0, 0])
scene.add(mesh)
camera = pyrender.OrthographicCamera(xmag=1.0, ymag=1.0)
scene.add(camera, pose=pose_camera)
light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=4.0)
scene.add(light, pose=pose_light)
return scene
def do_render_one_frame(renderer, frame_idx, vertices, vertices1, faces):
if frame_idx % 100 == 0:
print('processed', frame_idx, 'frames')
uniform_color = [220, 220, 220, 255]
pose_camera = create_pose_camera(angle_deg=-2)
pose_light = create_pose_light(angle_deg=-30)
figs = []
for vtx in [vertices, vertices1]:
scene = create_scene_with_mesh(vtx, faces, uniform_color, pose_camera, pose_light)
fig, _ = renderer.render(scene)
figs.append(fig)
return figs[0], figs[1]
def do_render_one_frame_no_gt(renderer, frame_idx, vertices, faces):
if frame_idx % 100 == 0:
print('processed', frame_idx, 'frames')
uniform_color = [220, 220, 220, 255]
pose_camera = create_pose_camera(angle_deg=-2)
pose_light = create_pose_light(angle_deg=-30)
scene = create_scene_with_mesh(vertices, faces, uniform_color, pose_camera, pose_light)
fig, _ = renderer.render(scene)
return fig
def write_images_from_queue(fig_queue, output_dir, img_filetype):
while True:
e = fig_queue.get()
if e is None:
break
fid, fig1, fig2 = e
fn = os.path.join(output_dir, f"frame_{fid}.{img_filetype}")
merged_fig = np.hstack((fig1, fig2))
try:
imageio.imwrite(fn, merged_fig)
except Exception as ex:
print(f"Error writing image {fn}: {ex}")
raise ex
def write_images_from_queue_no_gt(fig_queue, output_dir, img_filetype):
while True:
e = fig_queue.get()
if e is None:
break
fid, fig1 = e
fn = os.path.join(output_dir, f"frame_{fid}.{img_filetype}")
try:
imageio.imwrite(fn, fig1)
except Exception as ex:
print(f"Error writing image {fn}: {ex}")
raise ex
def render_frames_and_enqueue(fids, frame_vertex_pairs, faces, render_width, render_height, fig_queue):
fig_resolution = (render_width, render_height)
renderer = pyrender.OffscreenRenderer(*fig_resolution)
for idx, fid in enumerate(fids):
fig1, fig2 = do_render_one_frame(renderer, fid, frame_vertex_pairs[idx][0], frame_vertex_pairs[idx][1], faces)
fig_queue.put((fid, fig1, fig2))
renderer.delete()
def render_frames_and_enqueue_no_gt(fids, frame_vertex_pairs, faces, render_width, render_height, fig_queue):
fig_resolution = (render_width, render_height)
renderer = pyrender.OffscreenRenderer(*fig_resolution)
for idx, fid in enumerate(fids):
fig1 = do_render_one_frame_no_gt(renderer, fid, frame_vertex_pairs[idx][0], faces)
fig_queue.put((fid, fig1))
renderer.delete()
def sub_process_process_frame(subprocess_index, render_video_width, render_video_height, render_tmp_img_filetype, fids, frame_vertex_pairs, faces, output_dir):
t0 = time.time()
print(f"subprocess_index={subprocess_index} begin_ts={t0}")
fig_queue = queue.Queue()
render_frames_and_enqueue(fids, frame_vertex_pairs, faces, render_video_width, render_video_height, fig_queue)
fig_queue.put(None)
t1 = time.time()
thr = threading.Thread(target=write_images_from_queue, args=(fig_queue, output_dir, render_tmp_img_filetype))
thr.start()
thr.join()
t2 = time.time()
print(f"subprocess_index={subprocess_index} render={t1 - t0:.2f} all={t2 - t0:.2f}")
def sub_process_process_frame_no_gt(subprocess_index, render_video_width, render_video_height, render_tmp_img_filetype, fids, frame_vertex_pairs, faces, output_dir):
t0 = time.time()
print(f"subprocess_index={subprocess_index} begin_ts={t0}")
fig_queue = queue.Queue()
render_frames_and_enqueue_no_gt(fids, frame_vertex_pairs, faces, render_video_width, render_video_height, fig_queue)
fig_queue.put(None)
t1 = time.time()
thr = threading.Thread(target=write_images_from_queue_no_gt, args=(fig_queue, output_dir, render_tmp_img_filetype))
thr.start()
thr.join()
t2 = time.time()
print(f"subprocess_index={subprocess_index} render={t1 - t0:.2f} all={t2 - t0:.2f}")
def distribute_frames(frames, vertices_all, vertices1_all):
sample_interval = max(1, int(30 // args['render_video_fps']))
subproc_frame_ids = [[] for _ in range(args['render_concurrent_num'])]
subproc_vertices = [[] for _ in range(args['render_concurrent_num'])]
sid = 0
for i in range(frames):
if i % sample_interval != 0:
continue
idx = sid % args['render_concurrent_num']
subproc_frame_ids[idx].append(sid)
subproc_vertices[idx].append((vertices_all[i], vertices1_all[i]))
sid += 1
return subproc_frame_ids, subproc_vertices
def distribute_frames_no_gt(frames, vertices_all):
sample_interval = max(1, int(30 // args['render_video_fps']))
subproc_frame_ids = [[] for _ in range(args['render_concurrent_num'])]
subproc_vertices = [[] for _ in range(args['render_concurrent_num'])]
sid = 0
for i in range(frames):
if i % sample_interval != 0:
continue
idx = sid % args['render_concurrent_num']
subproc_frame_ids[idx].append(sid)
subproc_vertices[idx].append((vertices_all[i], vertices_all[i]))
sid += 1
return subproc_frame_ids, subproc_vertices
def generate_silent_videos(frames, vertices_all, vertices1_all, faces, output_dir):
ids, verts = distribute_frames(frames, vertices_all, vertices1_all)
with multiprocessing.Pool(args['render_concurrent_num']) as pool:
pool.starmap(sub_process_process_frame, [
(
i,
args['render_video_width'],
args['render_video_height'],
args['render_tmp_img_filetype'],
ids[i],
verts[i],
faces,
output_dir
)
for i in range(args['render_concurrent_num'])
])
out_file = os.path.join(output_dir, "silence_video.mp4")
convert_img_to_mp4(os.path.join(output_dir, f"frame_%d.{args['render_tmp_img_filetype']}"), out_file, args['render_video_fps'])
for fn in glob.glob(os.path.join(output_dir, f"*.{args['render_tmp_img_filetype']}")):
os.remove(fn)
return out_file
def generate_silent_videos_no_gt(frames, vertices_all, faces, output_dir):
ids, verts = distribute_frames_no_gt(frames, vertices_all)
with multiprocessing.Pool(args['render_concurrent_num']) as pool:
pool.starmap(sub_process_process_frame_no_gt, [
(
i,
args['render_video_width'],
args['render_video_height'],
args['render_tmp_img_filetype'],
ids[i],
verts[i],
faces,
output_dir
)
for i in range(args['render_concurrent_num'])
])
out_file = os.path.join(output_dir, "silence_video.mp4")
convert_img_to_mp4(os.path.join(output_dir, f"frame_%d.{args['render_tmp_img_filetype']}"), out_file, args['render_video_fps'])
for fn in glob.glob(os.path.join(output_dir, f"*.{args['render_tmp_img_filetype']}")):
os.remove(fn)
return out_file
def add_audio_to_video(silent_video_path, audio_path, output_video_path):
cmd = [
'ffmpeg','-y','-i', silent_video_path,'-i', audio_path,'-map','0:v','-map','1:a','-c:v','copy','-shortest',output_video_path
]
try:
subprocess.run(cmd, check=True)
print(f"Video with audio generated: {output_video_path}")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
def convert_img_to_mp4(input_pattern, output_file, framerate=30):
cmd = ['ffmpeg','-framerate', str(framerate),'-i', input_pattern,'-c:v','libx264','-pix_fmt','yuv420p',output_file,'-y']
try:
subprocess.run(cmd, check=True)
print(f"Video conversion: {output_file}")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
def process_frame(i, vertices_all, vertices1_all, faces, output_dir, filenames):
uniform_color = [220, 220, 220, 255]
reso = (1000, 1000)
fig, axs = plt.subplots(1, 2, figsize=(20,10))
axs = axs.flatten()
vertices = vertices_all[i]
vertices1 = vertices1_all[i]
fn = f"{output_dir}frame_{i}.png"
if i % 100 == 0:
print('processed', i, 'frames')
angle_rad = deg_to_rad(-2)
pose_camera = np.array([
[1.0, 0.0, 0.0, 0.0],
[0.0, np.cos(angle_rad), -np.sin(angle_rad), 1.0],
[0.0, np.sin(angle_rad), np.cos(angle_rad), 5.0],
[0.0, 0.0, 0.0, 1.0]
])
angle_rad = deg_to_rad(-30)
pose_light = np.array([
[1.0, 0.0, 0.0, 0.0],
[0.0, np.cos(angle_rad), -np.sin(angle_rad), 0.0],
[0.0, np.sin(angle_rad), np.cos(angle_rad), 3.0],
[0.0, 0.0, 0.0, 1.0]
])
for idx, vtx in enumerate([vertices, vertices1]):
tm = trimesh.Trimesh(vertices=vtx, faces=faces, vertex_colors=uniform_color)
mesh = pyrender.Mesh.from_trimesh(tm, smooth=True)
scene = pyrender.Scene()
scene.add(mesh)
cam = pyrender.OrthographicCamera(xmag=1.0, ymag=1.0)
scene.add(cam, pose=pose_camera)
light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=4.0)
scene.add(light, pose=pose_light)
r = pyrender.OffscreenRenderer(*reso)
color, _ = r.render(scene)
axs[idx].imshow(color)
axs[idx].axis('off')
r.delete()
plt.savefig(fn, bbox_inches='tight')
plt.close(fig)
def generate_images(frames, vertices_all, vertices1_all, faces, output_dir, filenames):
nc = multiprocessing.cpu_count() - 1
for i in range(frames):
process_frame(i*3, vertices_all, vertices1_all, faces, output_dir, filenames)
def render_one_sequence_with_face(res_npz_path, output_dir, audio_path, model_folder="/data/datasets/smplx_models/", model_type='smplx', gender='NEUTRAL_2020', ext='npz', num_betas=300, num_expression_coeffs=100, use_face_contour=False, use_matplotlib=False, remove_transl=True):
import smplx
import torch
data_np_body = np.load(res_npz_path, allow_pickle=True)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
faces = np.load(f"{model_folder}/smplx/SMPLX_NEUTRAL_2020.npz", allow_pickle=True)["f"]
n = data_np_body["poses"].shape[0]
model = smplx.create(model_folder, model_type=model_type, gender=gender, use_face_contour=use_face_contour, num_betas=num_betas, num_expression_coeffs=num_expression_coeffs, ext=ext, use_pca=False).cuda()
beta = torch.from_numpy(data_np_body["betas"]).to(torch.float32).unsqueeze(0).cuda()
beta = beta.repeat(n, 1)
expression = torch.from_numpy(data_np_body["expressions"][:n]).to(torch.float32).cuda()
jaw_pose = torch.from_numpy(data_np_body["poses"][:n, 66:69]).to(torch.float32).cuda()
pose = torch.from_numpy(data_np_body["poses"][:n]).to(torch.float32).cuda()
transl = torch.from_numpy(data_np_body["trans"][:n]).to(torch.float32).cuda()
if remove_transl:
transl = transl[0:1].repeat(n, 1)
output = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose[:,:3], body_pose=pose[:,3:21*3+3], left_hand_pose=pose[:,25*3:40*3], right_hand_pose=pose[:,40*3:55*3], leye_pose=pose[:,69:72], reye_pose=pose[:,72:75], return_verts=True)
vertices_all = output["vertices"].cpu().numpy()
pose1 = torch.zeros_like(pose).to(torch.float32).cuda()
output1 = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose1[:,:3], body_pose=pose1[:,3:21*3+3], left_hand_pose=pose1[:,25*3:40*3], right_hand_pose=pose1[:,40*3:55*3], leye_pose=pose1[:,69:72], reye_pose=pose1[:,72:75], return_verts=True)
v1 = output1["vertices"].cpu().numpy()*7
td = np.zeros_like(v1)
td[:, :, 1] = 10
vertices1_all = v1 - td
if args['debug']:
seconds = 1
else:
seconds = vertices_all.shape[0]//30
sfile = generate_silent_videos(int(seconds*args['render_video_fps']), vertices1_all, vertices_all, faces, output_dir)
base = os.path.splitext(os.path.basename(res_npz_path))[0]
final_clip = os.path.join(output_dir, f"{base}.mp4")
add_audio_to_video(sfile, audio_path, final_clip)
os.remove(sfile)
return final_clip
def render_one_sequence(res_npz_path, gt_npz_path, output_dir, audio_path, model_folder="/data/datasets/smplx_models/", model_type='smplx', gender='NEUTRAL_2020', ext='npz', num_betas=300, num_expression_coeffs=100, use_face_contour=False, use_matplotlib=False, remove_transl=True):
import smplx
import torch
data_np_body = np.load(res_npz_path, allow_pickle=True)
gt_np_body = np.load(gt_npz_path, allow_pickle=True)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
faces = np.load(f"{model_folder}/smplx/SMPLX_NEUTRAL_2020.npz", allow_pickle=True)["f"]
n = data_np_body["poses"].shape[0]
model = smplx.create(model_folder, model_type=model_type, gender=gender, use_face_contour=use_face_contour, num_betas=num_betas, num_expression_coeffs=num_expression_coeffs, ext=ext, use_pca=False).cuda()
beta = torch.from_numpy(data_np_body["betas"]).to(torch.float32).unsqueeze(0).cuda()
beta = beta.repeat(n, 1)
expression = torch.from_numpy(data_np_body["expressions"][:n]).to(torch.float32).cuda()
jaw_pose = torch.from_numpy(data_np_body["poses"][:n, 66:69]).to(torch.float32).cuda()
pose = torch.from_numpy(data_np_body["poses"][:n]).to(torch.float32).cuda()
transl = torch.from_numpy(data_np_body["trans"][:n]).to(torch.float32).cuda()
if remove_transl:
transl = transl[0:1].repeat(n, 1)
output = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose[:,:3], body_pose=pose[:,3:21*3+3], left_hand_pose=pose[:,25*3:40*3], right_hand_pose=pose[:,40*3:55*3], leye_pose=pose[:,69:72], reye_pose=pose[:,72:75], return_verts=True)
vertices_all = output["vertices"].cpu().numpy()
beta1 = torch.from_numpy(gt_np_body["betas"]).to(torch.float32).unsqueeze(0).cuda()
expression1 = torch.from_numpy(gt_np_body["expressions"][:n]).to(torch.float32).cuda()
jaw_pose1 = torch.from_numpy(gt_np_body["poses"][:n,66:69]).to(torch.float32).cuda()
pose1 = torch.from_numpy(gt_np_body["poses"][:n]).to(torch.float32).cuda()
transl1 = torch.from_numpy(gt_np_body["trans"][:n]).to(torch.float32).cuda()
if remove_transl:
transl1 = transl1[0:1].repeat(n, 1)
output1 = model(betas=beta1, transl=transl1, expression=expression1, jaw_pose=jaw_pose1, global_orient=pose1[:,:3], body_pose=pose1[:,3:21*3+3], left_hand_pose=pose1[:,25*3:40*3], right_hand_pose=pose1[:,40*3:55*3], leye_pose=pose1[:,69:72], reye_pose=pose1[:,72:75], return_verts=True)
vertices1_all = output1["vertices"].cpu().numpy()
if args['debug']:
seconds = 1
else:
seconds = vertices_all.shape[0]//30
sfile = generate_silent_videos(int(seconds*args['render_video_fps']), vertices_all, vertices1_all, faces, output_dir)
base = os.path.splitext(os.path.basename(res_npz_path))[0]
final_clip = os.path.join(output_dir, f"{base}.mp4")
add_audio_to_video(sfile, audio_path, final_clip)
os.remove(sfile)
return final_clip
def render_one_sequence_no_gt(res_npz_path, output_dir, audio_path, model_folder="/data/datasets/smplx_models/", model_type='smplx', gender='NEUTRAL_2020', ext='npz', num_betas=300, num_expression_coeffs=100, use_face_contour=False, use_matplotlib=False, remove_transl=True):
import smplx
import torch
data_np_body = np.load(res_npz_path, allow_pickle=True)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
faces = np.load(f"{model_folder}/smplx/SMPLX_NEUTRAL_2020.npz", allow_pickle=True)["f"]
n = data_np_body["poses"].shape[0]
model = smplx.create(model_folder, model_type=model_type, gender=gender, use_face_contour=use_face_contour, num_betas=num_betas, num_expression_coeffs=num_expression_coeffs, ext=ext, use_pca=False).cuda()
beta = torch.from_numpy(data_np_body["betas"]).to(torch.float32).unsqueeze(0).cuda()
beta = beta.repeat(n, 1)
expression = torch.from_numpy(data_np_body["expressions"][:n]).to(torch.float32).cuda()
jaw_pose = torch.from_numpy(data_np_body["poses"][:n, 66:69]).to(torch.float32).cuda()
pose = torch.from_numpy(data_np_body["poses"][:n]).to(torch.float32).cuda()
transl = torch.from_numpy(data_np_body["trans"][:n]).to(torch.float32).cuda()
if remove_transl:
transl = transl[0:1].repeat(n, 1)
output = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose[:,:3], body_pose=pose[:,3:21*3+3], left_hand_pose=pose[:,25*3:40*3], right_hand_pose=pose[:,40*3:55*3], leye_pose=pose[:,69:72], reye_pose=pose[:,72:75], return_verts=True)
vertices_all = output["vertices"].cpu().numpy()
if args['debug']:
seconds = 1
else:
seconds = vertices_all.shape[0]//30
sfile = generate_silent_videos_no_gt(int(seconds*args['render_video_fps']), vertices_all, faces, output_dir)
base = os.path.splitext(os.path.basename(res_npz_path))[0]
final_clip = os.path.join(output_dir, f"{base}.mp4")
add_audio_to_video(sfile, audio_path, final_clip)
os.remove(sfile)
return final_clip
def render_one_sequence_face_only(res_npz_path, output_dir, audio_path, model_folder="/data/datasets/smplx_models/", model_type='smplx', gender='NEUTRAL_2020', ext='npz', num_betas=300, num_expression_coeffs=100, use_face_contour=False, use_matplotlib=False, remove_transl=True):
import smplx
import torch
data_np_body = np.load(res_npz_path, allow_pickle=True)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
faces = np.load(f"{model_folder}/smplx/SMPLX_NEUTRAL_2020.npz", allow_pickle=True)["f"]
n = data_np_body["poses"].shape[0]
model = smplx.create(model_folder, model_type=model_type, gender=gender, use_face_contour=use_face_contour, num_betas=num_betas, num_expression_coeffs=num_expression_coeffs, ext=ext, use_pca=False).cuda()
beta = torch.from_numpy(data_np_body["betas"]).to(torch.float32).unsqueeze(0).cuda()
beta = beta.repeat(n, 1)
expression = torch.from_numpy(data_np_body["expressions"][:n]).to(torch.float32).cuda()
jaw_pose = torch.from_numpy(data_np_body["poses"][:n, 66:69]).to(torch.float32).cuda()
pose = torch.from_numpy(data_np_body["poses"][:n]).to(torch.float32).cuda()
transl = torch.from_numpy(data_np_body["trans"][:n]).to(torch.float32).cuda()
if remove_transl:
transl = transl[0:1].repeat(n, 1)
output = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose[:,:3], body_pose=pose[:,3:21*3+3], left_hand_pose=pose[:,25*3:40*3], right_hand_pose=pose[:,40*3:55*3], leye_pose=pose[:,69:72], reye_pose=pose[:,72:75], return_verts=True)
vertices_all = output["vertices"].cpu().numpy()
pose1 = torch.zeros_like(pose).to(torch.float32).cuda()
output1 = model(betas=beta, transl=transl, expression=expression, jaw_pose=jaw_pose, global_orient=pose1[:,:3], body_pose=pose1[:,3:21*3+3], left_hand_pose=pose1[:,25*3:40*3], right_hand_pose=pose1[:,40*3:55*3], leye_pose=pose1[:,69:72], reye_pose=pose1[:,72:75], return_verts=True)
v1 = output1["vertices"].cpu().numpy()*7
td = np.zeros_like(v1)
td[:, :, 1] = 10
vertices_all = v1 - td
if args['debug']:
seconds = 1
else:
seconds = vertices_all.shape[0]//30
sfile = generate_silent_videos_no_gt(int(seconds*args['render_video_fps']), vertices_all, faces, output_dir)
base = os.path.splitext(os.path.basename(res_npz_path))[0]
final_clip = os.path.join(output_dir, f"{base}_face.mp4")
add_audio_to_video(sfile, audio_path, final_clip)
os.remove(sfile)
return final_clip |