fffiloni commited on
Commit
057ef8f
1 Parent(s): 2c5156d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -47,6 +47,8 @@ def calculate_resize_dimensions(width, height, max_width=1024):
47
  aspect_ratio = height / width
48
  new_width = max_width
49
  new_height = int(max_width * aspect_ratio)
 
 
50
  return new_width, new_height
51
 
52
  def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True)):
@@ -98,28 +100,34 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
98
  # Generate initial output video
99
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
100
  temp_path = f"output_{timestamp}_temp.mp4"
101
- output_path = f"output_{timestamp}.mp4"
102
 
103
- # Export initial video
104
  export_to_video(video.frames[0], temp_path, fps=8)
105
 
106
- # Resize using moviepy with h264 codec
107
- video_clip = VideoFileClip(temp_path)
108
- resized_clip = video_clip.resize(width=target_width, height=target_height)
109
- resized_clip.write_videofile(
110
- output_path,
111
- codec='libx264',
112
- fps=8,
113
- preset='medium',
114
- ffmpeg_params=['-crf', '23']
115
- )
116
-
117
- # Cleanup
118
- video_clip.close()
119
- resized_clip.close()
120
- os.remove(temp_path)
 
 
 
 
 
 
121
 
122
- return output_path
123
 
124
  # Set up Gradio UI
125
  with gr.Blocks(analytics_enabled=False) as demo:
 
47
  aspect_ratio = height / width
48
  new_width = max_width
49
  new_height = int(max_width * aspect_ratio)
50
+ # Make height even number for video encoding
51
+ new_height = new_height - (new_height % 2)
52
  return new_width, new_height
53
 
54
  def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True)):
 
100
  # Generate initial output video
101
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
102
  temp_path = f"output_{timestamp}_temp.mp4"
103
+ final_path = f"output_{timestamp}.mp4"
104
 
105
+ # First export the original video
106
  export_to_video(video.frames[0], temp_path, fps=8)
107
 
108
+ # Then resize it with moviepy
109
+ try:
110
+ video_clip = VideoFileClip(temp_path)
111
+ resized_clip = video_clip.resize(width=target_width, height=target_height)
112
+ resized_clip.write_videofile(
113
+ final_path,
114
+ codec='libx264',
115
+ fps=8,
116
+ preset='medium',
117
+ ffmpeg_params=['-crf', '23'],
118
+ verbose=False,
119
+ logger=None
120
+ )
121
+ finally:
122
+ # Make sure we clean up the clips
123
+ if 'video_clip' in locals():
124
+ video_clip.close()
125
+ if 'resized_clip' in locals():
126
+ resized_clip.close()
127
+ if os.path.exists(temp_path):
128
+ os.remove(temp_path)
129
 
130
+ return final_path
131
 
132
  # Set up Gradio UI
133
  with gr.Blocks(analytics_enabled=False) as demo: