Render depth and save as video.
(
verts: torch.Tensor,
faces: torch.Tensor,
R: torch.Tensor,
T: torch.Tensor,
width: int = 1024,
height: int = 1024,
focal: float = 2000,
batch_size: int = 24,
fps: int = 60,
output_path: Optional[str] = None,
motion_name: Optional[str] = None,
verbose: bool = False,
)
| 330 | |
| 331 | |
| 332 | def render_and_save( |
| 333 | verts: torch.Tensor, |
| 334 | faces: torch.Tensor, |
| 335 | R: torch.Tensor, |
| 336 | T: torch.Tensor, |
| 337 | width: int = 1024, |
| 338 | height: int = 1024, |
| 339 | focal: float = 2000, |
| 340 | batch_size: int = 24, |
| 341 | fps: int = 60, |
| 342 | output_path: Optional[str] = None, |
| 343 | motion_name: Optional[str] = None, |
| 344 | verbose: bool = False, |
| 345 | ) -> str: |
| 346 | """Render depth and save as video.""" |
| 347 | |
| 348 | def ffmpeg_command(path: str, pix_fmt: str): |
| 349 | return [ |
| 350 | "ffmpeg", |
| 351 | "-loglevel", |
| 352 | "quiet", |
| 353 | "-y", |
| 354 | "-f", |
| 355 | "rawvideo", |
| 356 | "-vcodec", |
| 357 | "rawvideo", |
| 358 | "-pix_fmt", |
| 359 | pix_fmt, |
| 360 | "-s", |
| 361 | f"{width}x{height}", |
| 362 | "-r", |
| 363 | str(fps), |
| 364 | "-i", |
| 365 | "-", |
| 366 | "-an", |
| 367 | "-vcodec", |
| 368 | "libx264", |
| 369 | "-pix_fmt", |
| 370 | "yuv420p", |
| 371 | path, |
| 372 | ] |
| 373 | |
| 374 | start_time = time.time() |
| 375 | depth_maps = rendering_batches( |
| 376 | verts, faces, width, height, focal, R, T, batch_size=batch_size, render_multiple=True, reverse_axis=False |
| 377 | ) |
| 378 | render_time = time.time() - start_time |
| 379 | if verbose: |
| 380 | print(f"Rendering time: {render_time:.2f}s") |
| 381 | |
| 382 | start_time = time.time() |
| 383 | depth_images = visualize_depth_map(depth_maps) |
| 384 | vis_time = time.time() - start_time |
| 385 | if verbose: |
| 386 | print(f"Visualization time: {vis_time:.2f}s") |
| 387 | |
| 388 | start_time = time.time() |
| 389 | os.makedirs(os.path.dirname(output_path), exist_ok=True) |
no test coverage detected