Skip to content

Commit ab5bfff

Browse files
committed
Video mode fixes
1 parent 2d9812a commit ab5bfff

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def convert_to_i16(arr):
4444
# uint16 conversion uses round-down, therefore values should be [0; 2**16)
4545
numbytes = 2
4646
max_val = (2 ** (8 * numbytes))
47-
out = np.clip(arr * max_val, 0, max_val - 0.1) # -0.1 from above is needed to avoid overflowing
47+
out = np.clip(arr * max_val + 0.0001, 0, max_val - 0.1) # -0.1 from above is needed to avoid overflowing
4848
return out.astype("uint16")
4949

5050
def convert_i16_to_rgb(image, like):
@@ -252,7 +252,7 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
252252
yield count, 'depth', Image.fromarray(img_output)
253253

254254
if inp[go.GEN_STEREO]:
255-
print("Generating stereoscopic images..")
255+
# print("Generating stereoscopic image(s)..")
256256
stereoimages = create_stereoimages(
257257
inputimages[count], img_output,
258258
inp[go.STEREO_DIVERGENCE], inp[go.STEREO_SEPARATION],

src/video_mode.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)