Spanicin commited on
Commit
83d2c37
·
verified ·
1 Parent(s): 3d09648

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -121,7 +121,7 @@ def get_video_duration(video_path):
121
 
122
 
123
  def extend_video_simple(video_path, audio_path, output_path):
124
- # Get durations dynamically
125
  audio_duration = librosa.get_duration(path=audio_path)
126
  video_duration = get_video_duration(video_path)
127
 
@@ -132,7 +132,8 @@ def extend_video_simple(video_path, audio_path, output_path):
132
  print("Extending video by adding reversed version.")
133
 
134
  # Create a reversed version of the full video
135
- reversed_clip = "reversed.mp4"
 
136
  subprocess.run(
137
  f"ffmpeg -y -i {video_path} -vf reverse -an {reversed_clip}", shell=True
138
  )
@@ -142,7 +143,6 @@ def extend_video_simple(video_path, audio_path, output_path):
142
  f"ffmpeg -y -i {video_path} -i {reversed_clip} -filter_complex \"[0:v:0][1:v:0]concat=n=2:v=1[outv]\" -map \"[outv]\" -an {output_path}",
143
  shell=True
144
  )
145
-
146
  else:
147
  print("Audio is not longer than video. No extension needed.")
148
  subprocess.run(f"cp {video_path} {output_path}", shell=True)
@@ -170,13 +170,14 @@ def generate_video():
170
  video_file.save(temp_video_path)
171
  print('temp_video_path',temp_video_path)
172
 
173
- output_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
174
 
175
  # You can pass additional parameters via form data if needed (e.g., checkpoint path)
176
  inference_ckpt_path = request.form.get('inference_ckpt_path', 'checkpoints/latentsync_unet.pt')
177
  unet_config_path = request.form.get('unet_config_path', 'configs/unet/second_stage.yaml')
178
 
179
-
 
180
  extend_video_simple(temp_video_path, temp_audio_path, output_video)
181
 
182
  try:
 
121
 
122
 
123
  def extend_video_simple(video_path, audio_path, output_path):
124
+ """Extends video duration by appending a reversed version if audio is longer."""
125
  audio_duration = librosa.get_duration(path=audio_path)
126
  video_duration = get_video_duration(video_path)
127
 
 
132
  print("Extending video by adding reversed version.")
133
 
134
  # Create a reversed version of the full video
135
+ reversed_clip = tempfile.NamedTemporaryFile(dir=TEMP_DIR.name, delete=False, suffix=".mp4").name
136
+
137
  subprocess.run(
138
  f"ffmpeg -y -i {video_path} -vf reverse -an {reversed_clip}", shell=True
139
  )
 
143
  f"ffmpeg -y -i {video_path} -i {reversed_clip} -filter_complex \"[0:v:0][1:v:0]concat=n=2:v=1[outv]\" -map \"[outv]\" -an {output_path}",
144
  shell=True
145
  )
 
146
  else:
147
  print("Audio is not longer than video. No extension needed.")
148
  subprocess.run(f"cp {video_path} {output_path}", shell=True)
 
170
  video_file.save(temp_video_path)
171
  print('temp_video_path',temp_video_path)
172
 
173
+ # output_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
174
 
175
  # You can pass additional parameters via form data if needed (e.g., checkpoint path)
176
  inference_ckpt_path = request.form.get('inference_ckpt_path', 'checkpoints/latentsync_unet.pt')
177
  unet_config_path = request.form.get('unet_config_path', 'configs/unet/second_stage.yaml')
178
 
179
+ output_video = tempfile.NamedTemporaryFile(dir=TEMP_DIR.name, delete=False, suffix=".mp4").name
180
+
181
  extend_video_simple(temp_video_path, temp_audio_path, output_video)
182
 
183
  try: