(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None, smoothening='none')
| 129 | |
| 130 | |
| 131 | def gen_video(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None, smoothening='none'): |
| 132 | if inp[go.GEN_SIMPLE_MESH.name.lower()] or inp[go.GEN_INPAINTED_MESH.name.lower()]: |
| 133 | return 'Creating mesh-videos is not supported. Please split video into frames and use batch processing.' |
| 134 | |
| 135 | fps, input_images = open_path_as_images(os.path.abspath(video.name)) |
| 136 | os.makedirs(backbone.get_outpath(), exist_ok=True) |
| 137 | |
| 138 | if custom_depthmap is None: |
| 139 | print('Generating depthmaps for the video frames') |
| 140 | needed_keys = [go.COMPUTE_DEVICE, go.MODEL_TYPE, go.BOOST, go.NET_SIZE_MATCH, go.NET_WIDTH, go.NET_HEIGHT] |
| 141 | needed_keys = [x.name.lower() for x in needed_keys] |
| 142 | first_pass_inp = {k: v for (k, v) in inp.items() if k in needed_keys} |
| 143 | # We need predictions where frames are not normalized separately. |
| 144 | first_pass_inp[go.DO_OUTPUT_DEPTH_PREDICTION] = True |
| 145 | # No need in normalized frames. Properly processed depth video will be created in the second pass |
| 146 | first_pass_inp[go.DO_OUTPUT_DEPTH.name] = False |
| 147 | |
| 148 | gen_obj = core.core_generation_funnel(None, input_images, None, None, first_pass_inp) |
| 149 | input_depths = [x[2] for x in list(gen_obj)] |
| 150 | input_depths = process_predicitons(input_depths, smoothening) |
| 151 | else: |
| 152 | print('Using custom depthmap video') |
| 153 | cdm_fps, input_depths = open_path_as_images(os.path.abspath(custom_depthmap.name), maybe_depthvideo=True) |
| 154 | assert len(input_depths) == len(input_images), 'Custom depthmap video length does not match input video length' |
| 155 | if input_depths[0].size != input_images[0].size: |
| 156 | print('Warning! Input video size and depthmap video size are not the same!') |
| 157 | |
| 158 | print('Generating output frames') |
| 159 | img_results = list(core.core_generation_funnel(None, input_images, input_depths, None, inp)) |
| 160 | gens = list(set(map(lambda x: x[1], img_results))) |
| 161 | |
| 162 | print('Saving generated frames as video outputs') |
| 163 | for gen in gens: |
| 164 | if gen == 'depth' and custom_depthmap is not None: |
| 165 | # Well, that would be extra stupid, even if user has picked this option for some reason |
| 166 | # (forgot to change the default?) |
| 167 | continue |
| 168 | |
| 169 | imgs = [x[2] for x in img_results if x[1] == gen] |
| 170 | basename = f'{gen}_video' |
| 171 | frames_to_video(fps, imgs, outpath, f"depthmap-{backbone.get_next_sequence_number(outpath, basename)}-{basename}", |
| 172 | colorvids_bitrate) |
| 173 | print('All done. Video(s) saved!') |
| 174 | return '<h3>Videos generated</h3>' if len(gens) > 1 else '<h3>Video generated</h3>' if len(gens) == 1 \ |
| 175 | else '<h3>Nothing generated - please check the settings and try again</h3>' |
nothing calls this directly
no test coverage detected