jbilcke-hf HF staff commited on
Commit
e54869f
1 Parent(s): 7316f37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -92,41 +92,30 @@ def export_to_video_file(video_frames, output_video_path=None, fps=10):
92
  # those are way too slow for a AiTube which needs things to be as fast as possible
93
  # -----------------------------------------------------------------------------------
94
 
95
- def interpolate_video_frames(input_file_path, output_file_path, output_fps=10, desired_duration=1):
96
- """
97
- Interpolates frames in a video file to adjust frame rate and duration using ffmpeg's minterpolate.
98
-
99
- Parameters:
100
- input_file_path (str): Path to the input video file.
101
- output_file_path (str): Path to the output video file.
102
- output_fps (int): Target frames per second for the output video.
103
- desired_duration (int): Desired duration of the video in seconds.
104
-
105
- Returns:
106
- str: The file path of the modified video.
107
- """
108
-
109
- # Construct the ffmpeg command for interpolation
110
  cmd = [
111
  'ffmpeg',
112
- '-i', input_file_path, # input file
113
- '-filter:v', f'minterpolate=fps={output_fps}', # minterpolate filter options
114
- '-r', str(output_fps), # output frame rate
115
- output_file_path # Output file
116
  ]
117
 
 
118
  print("output_fps:", output_fps)
119
  print("desired_duration:", desired_duration)
120
- print("cmd:", cmd)
 
121
 
122
- # Execute the command
123
  try:
124
  subprocess.run(cmd, check=True)
125
- print("Video interpolation successful.")
126
- return input_file_path
127
  except subprocess.CalledProcessError as e:
128
  print("Failed to interpolate video. Error:", e)
129
- return output_file_path
130
 
131
  def generate_image(secret_token, prompt, base, width, height, motion, step, desired_duration, desired_fps):
132
  if secret_token != SECRET_TOKEN:
@@ -269,7 +258,7 @@ with gr.Blocks() as demo:
269
  ('8-Step', 8)],
270
  value=4,
271
  )
272
- duration_slider = gr.Slider(label="Desired Duration (seconds)", min_value=1, max_value=30, value=1, step=1)
273
  fps_slider = gr.Slider(label="Desired Frames Per Second", min_value=10, max_value=60, value=10, step=1)
274
 
275
  submit = gr.Button()
 
92
  # those are way too slow for a AiTube which needs things to be as fast as possible
93
  # -----------------------------------------------------------------------------------
94
 
95
+ def interpolate_video_frames(input_file_path, output_file_path, output_fps=10, desired_duration=1.6, original_duration=1.6):
96
+ scale_factor = original_duration / desired_duration
97
+ interpolation_filter = f'minterpolate=fps={output_fps},setpts={scale_factor}*PTS'
98
+
 
 
 
 
 
 
 
 
 
 
 
99
  cmd = [
100
  'ffmpeg',
101
+ '-i', input_file_path,
102
+ '-filter:v', interpolation_filter,
103
+ '-r', str(output_fps),
104
+ output_file_path
105
  ]
106
 
107
+ # Logging for debugging
108
  print("output_fps:", output_fps)
109
  print("desired_duration:", desired_duration)
110
+ print("original_duration:", original_duration)
111
+ print("cmd:", cmd)
112
 
 
113
  try:
114
  subprocess.run(cmd, check=True)
115
+ return output_file_path
 
116
  except subprocess.CalledProcessError as e:
117
  print("Failed to interpolate video. Error:", e)
118
+ return input_file_path # In case of error, return original path
119
 
120
  def generate_image(secret_token, prompt, base, width, height, motion, step, desired_duration, desired_fps):
121
  if secret_token != SECRET_TOKEN:
 
258
  ('8-Step', 8)],
259
  value=4,
260
  )
261
+ duration_slider = gr.Slider(label="Desired Duration (seconds)", min_value=1, max_value=120, value=1.6, step=0.1)
262
  fps_slider = gr.Slider(label="Desired Frames Per Second", min_value=10, max_value=60, value=10, step=1)
263
 
264
  submit = gr.Button()