@@ -21,22 +21,25 @@ def open_path_as_images(path, maybe_depthvideo=False):
2121 frames .append (img .convert ('RGB' ))
2222 return 1000 / img .info ['duration' ], frames
2323 if suffix in ['.avi' ] and maybe_depthvideo :
24- import imageio_ffmpeg
25- gen = imageio_ffmpeg .read_frames (path )
2624 try :
25+ import imageio_ffmpeg
26+ # Suppose there are in fact 16 bits per pixel
27+ # If this is not the case, this is not a 16-bit depthvideo, so no need to process it this way
28+ gen = imageio_ffmpeg .read_frames (path , pix_fmt = 'gray16le' , bits_per_pixel = 16 )
2729 video_info = next (gen )
2830 if video_info ['pix_fmt' ] == 'gray16le' :
2931 width , height = video_info ['size' ]
3032 frames = []
3133 for frame in gen :
3234 # Not sure if this is implemented somewhere else
3335 result = np .frombuffer (frame , dtype = 'uint16' )
34- result .shape = (height , width * 3 // 2 ) # Why does it work? I don't remotely have any idea.
36+ result .shape = (height , width ) # Why does it work? I don't remotely have any idea.
3537 frames += [Image .fromarray (result )]
3638 # TODO: Wrapping frames into Pillow objects is wasteful
3739 return video_info ['fps' ], frames
3840 finally :
39- gen .close ()
41+ if 'gen' in locals ():
42+ gen .close ()
4043 if suffix in ['.webm' , '.mp4' , '.avi' ]:
4144 from moviepy .video .io .VideoFileClip import VideoFileClip
4245 clip = VideoFileClip (path )
@@ -45,7 +48,7 @@ def open_path_as_images(path, maybe_depthvideo=False):
4548 return clip .fps , frames
4649 else :
4750 try :
48- return 1000 , [Image .open (path )]
51+ return 1 , [Image .open (path )]
4952 except Exception as e :
5053 raise Exception (f"Probably an unsupported file format: { suffix } " ) from e
5154
@@ -128,8 +131,8 @@ def gen_video(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None,
128131 first_pass_inp [go .DO_OUTPUT_DEPTH .name ] = False
129132
130133 gen_obj = core .core_generation_funnel (None , input_images , None , None , first_pass_inp )
131- predictions = [x [2 ] for x in list (gen_obj )]
132- input_depths = process_predicitons (predictions , smoothening )
134+ input_depths = [x [2 ] for x in list (gen_obj )]
135+ input_depths = process_predicitons (input_depths , smoothening )
133136 else :
134137 print ('Using custom depthmap video' )
135138 cdm_fps , input_depths = open_path_as_images (os .path .abspath (custom_depthmap .name ), maybe_depthvideo = True )
@@ -153,4 +156,5 @@ def gen_video(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None,
153156 frames_to_video (fps , imgs , outpath , f"depthmap-{ backbone .get_next_sequence_number ()} -{ basename } " ,
154157 colorvids_bitrate )
155158 print ('All done. Video(s) saved!' )
156- return 'Video generated!' if len (gens ) == 1 else 'Videos generated!'
159+ return '<h3>Videos generated</h3>' if len (gens ) > 1 else '<h3>Video generated</h3>' if len (gens ) == 1 \
160+ else '<h3>Nothing generated - please check the settings and try again</h3>'
0 commit comments