fffiloni commited on
Commit
f8cb9bd
1 Parent(s): d30a16f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import os
 
3
  import torch
4
  import gc
5
  from diffusers import AutoencoderKLCogVideoX, CogVideoXImageToVideoPipeline, CogVideoXTransformer3DModel
@@ -109,16 +110,20 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
109
  export_to_video(video.frames[0], temp_path, fps=8)
110
 
111
  try:
112
- # Use ffmpeg-python
113
- stream = ffmpeg.input(temp_path)
114
- stream = ffmpeg.filter(stream, 'scale', target_width, target_height)
115
- stream = ffmpeg.output(stream, final_path,
116
- vcodec='libx264',
117
- preset='medium',
118
- crf=23)
119
- ffmpeg.run(stream, overwrite_output=True)
120
- except Exception as e:
121
- print(f'Error during video processing: {str(e)}')
 
 
 
 
122
  raise e
123
  finally:
124
  if os.path.exists(temp_path):
 
1
  import gradio as gr
2
  import os
3
+ import subprocess
4
  import torch
5
  import gc
6
  from diffusers import AutoencoderKLCogVideoX, CogVideoXImageToVideoPipeline, CogVideoXTransformer3DModel
 
110
  export_to_video(video.frames[0], temp_path, fps=8)
111
 
112
  try:
113
+ # Use ffmpeg via subprocess
114
+ cmd = [
115
+ 'ffmpeg',
116
+ '-i', temp_path,
117
+ '-vf', f'scale={target_width}:{target_height}',
118
+ '-c:v', 'libx264',
119
+ '-preset', 'medium',
120
+ '-crf', '23',
121
+ '-y', # Overwrite output file if it exists
122
+ final_path
123
+ ]
124
+ subprocess.run(cmd, check=True, capture_output=True)
125
+ except subprocess.CalledProcessError as e:
126
+ print(f"FFmpeg error: {e.stderr.decode()}")
127
  raise e
128
  finally:
129
  if os.path.exists(temp_path):