| 105 | del state_dict |
| 106 | |
| 107 | def save_video(self, vid_target_recon: torch.Tensor, video_path: str, audio_path: str) -> str: |
| 108 | with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_video: |
| 109 | temp_filename = temp_video.name |
| 110 | vid = vid_target_recon.permute(0, 2, 3, 1) |
| 111 | vid = vid.detach().clamp(-1, 1).cpu() |
| 112 | vid = ((vid + 1) / 2 * 255).type('torch.ByteTensor') |
| 113 | torchvision.io.write_video(temp_filename, vid, fps=self.opt.fps) |
| 114 | if audio_path is not None: |
| 115 | with open(os.devnull, 'wb') as f: |
| 116 | command = "ffmpeg -i {} -i {} -c:v copy -c:a aac {} -y".format(temp_filename, audio_path, video_path) |
| 117 | subprocess.call(command, shell=True, stdout=f, stderr=f) |
| 118 | if os.path.exists(video_path): |
| 119 | os.remove(temp_filename) |
| 120 | else: |
| 121 | os.rename(temp_filename, video_path) |
| 122 | return video_path |
| 123 | |
| 124 | @torch.no_grad() |
| 125 | def run_inference( |