multimodalart HF Staff linoyts HF Staff commited on
Commit
eaefc3d
·
verified ·
1 Parent(s): d2c73e1

Update app.py (#7)

Browse files

- Update app.py (4b9bca0dab3c9feb9c3e6bb59106709a35b9313d)


Co-authored-by: Linoy Tsaban <[email protected]>

Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -117,7 +117,7 @@ def process_video_for_canny(video, width, height):
117
  detect_resolution = max(video[0].size[0],video[0].size[1])
118
  image_resolution = max(width, height)
119
  for frame in video:
120
- canny_video.append(canny_processor(frame, low_threshold=50, high_threshold=200, detect_resolution=detect_resolution, image_resolution=image_resolution))
121
 
122
  return canny_video
123
 
@@ -137,11 +137,14 @@ def process_input_video(reference_video, width, height,
137
  processed_video = process_video_for_canny(video, width, height)
138
 
139
  # Create a preview video file for display
140
- with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_file:
141
- preview_path = tmp_file.name
142
- export_to_video(processed_video, preview_path, fps=FPS)
 
 
 
143
 
144
- return preview_path
145
 
146
  except Exception as e:
147
  print(f"Error processing input video: {e}")
 
117
  detect_resolution = max(video[0].size[0],video[0].size[1])
118
  image_resolution = max(width, height)
119
  for frame in video:
120
+ canny_video.append(canny_processor(frame, low_threshold=50, high_threshold=200, detect_resolution=detect_resolution, image_resolution=image_resolution, output_type="np"))
121
 
122
  return canny_video
123
 
 
137
  processed_video = process_video_for_canny(video, width, height)
138
 
139
  # Create a preview video file for display
140
+ output_filename = "control.mp4"
141
+ video_uint8_frames = [(frame * 255).astype(np.uint8) for frame in processed_video]
142
+ with imageio.get_writer(output_filename, fps=FPS, quality=8, macro_block_size=1) as writer:
143
+ for frame_idx, frame_data in enumerate(video_uint8_frames):
144
+ progress((frame_idx + 1) / len(video_uint8_frames), desc="Encoding video frames...")
145
+ writer.append_data(frame_data)
146
 
147
+ return output_filename
148
 
149
  except Exception as e:
150
  print(f"Error processing input video: {e}")