| 69 | |
| 70 | |
| 71 | def frames_to_video(fps, frames, path, name, colorvids_bitrate=None): |
| 72 | if frames[0].mode == 'I;16': # depthmap video |
| 73 | import imageio_ffmpeg |
| 74 | writer = imageio_ffmpeg.write_frames( |
| 75 | os.path.join(path, f"{name}.avi"), frames[0].size, 'gray16le', 'gray16le', fps, codec='ffv1', |
| 76 | macro_block_size=1) |
| 77 | try: |
| 78 | writer.send(None) |
| 79 | for frame in frames: |
| 80 | writer.send(np.array(frame)) |
| 81 | finally: |
| 82 | writer.close() |
| 83 | else: |
| 84 | arrs = [np.asarray(frame) for frame in frames] |
| 85 | from moviepy.video.io.ImageSequenceClip import ImageSequenceClip |
| 86 | clip = ImageSequenceClip(arrs, fps=fps) |
| 87 | done = False |
| 88 | priority = [('avi', 'png'), ('avi', 'rawvideo'), ('mp4', 'libx264'), ('webm', 'libvpx')] |
| 89 | if colorvids_bitrate: |
| 90 | priority = reversed(priority) |
| 91 | for v_format, codec in priority: |
| 92 | try: |
| 93 | br = f'{colorvids_bitrate}k' if codec not in ['png', 'rawvideo'] else None |
| 94 | clip.write_videofile(os.path.join(path, f"{name}.{v_format}"), codec=codec, bitrate=br) |
| 95 | done = True |
| 96 | break |
| 97 | except: |
| 98 | traceback.print_exc() |
| 99 | if not done: |
| 100 | raise Exception('Saving the video failed!') |
| 101 | |
| 102 | |
| 103 | def process_predicitons(predictions, smoothening='none'): |