@@ -21,22 +21,25 @@ def open_path_as_images(path, maybe_depthvideo=False):
21
21
frames .append (img .convert ('RGB' ))
22
22
return 1000 / img .info ['duration' ], frames
23
23
if suffix in ['.avi' ] and maybe_depthvideo :
24
- import imageio_ffmpeg
25
- gen = imageio_ffmpeg .read_frames (path )
26
24
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 )
27
29
video_info = next (gen )
28
30
if video_info ['pix_fmt' ] == 'gray16le' :
29
31
width , height = video_info ['size' ]
30
32
frames = []
31
33
for frame in gen :
32
34
# Not sure if this is implemented somewhere else
33
35
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.
35
37
frames += [Image .fromarray (result )]
36
38
# TODO: Wrapping frames into Pillow objects is wasteful
37
39
return video_info ['fps' ], frames
38
40
finally :
39
- gen .close ()
41
+ if 'gen' in locals ():
42
+ gen .close ()
40
43
if suffix in ['.webm' , '.mp4' , '.avi' ]:
41
44
from moviepy .video .io .VideoFileClip import VideoFileClip
42
45
clip = VideoFileClip (path )
@@ -45,7 +48,7 @@ def open_path_as_images(path, maybe_depthvideo=False):
45
48
return clip .fps , frames
46
49
else :
47
50
try :
48
- return 1000 , [Image .open (path )]
51
+ return 1 , [Image .open (path )]
49
52
except Exception as e :
50
53
raise Exception (f"Probably an unsupported file format: { suffix } " ) from e
51
54
@@ -128,8 +131,8 @@ def gen_video(video, outpath, inp, custom_depthmap=None, colorvids_bitrate=None,
128
131
first_pass_inp [go .DO_OUTPUT_DEPTH .name ] = False
129
132
130
133
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 )
133
136
else :
134
137
print ('Using custom depthmap video' )
135
138
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,
153
156
frames_to_video (fps , imgs , outpath , f"depthmap-{ backbone .get_next_sequence_number ()} -{ basename } " ,
154
157
colorvids_bitrate )
155
158
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