retry to increase fps
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import tempfile
|
|
9 |
def extract_waveform_animation(audio_file, window_seconds=5):
|
10 |
y, sr = librosa.load(audio_file, sr=None)
|
11 |
duration = librosa.get_duration(y=y, sr=sr)
|
12 |
-
|
13 |
fig, ax = plt.subplots()
|
14 |
line, = ax.plot([], [], lw=2)
|
15 |
window_length = int(window_seconds * sr)
|
@@ -27,7 +27,7 @@ def extract_waveform_animation(audio_file, window_seconds=5):
|
|
27 |
|
28 |
def update(frame):
|
29 |
# Get current window
|
30 |
-
start = frame * sr
|
31 |
end = start + window_length
|
32 |
window = y[start:end]
|
33 |
|
@@ -40,10 +40,10 @@ def extract_waveform_animation(audio_file, window_seconds=5):
|
|
40 |
|
41 |
total_frames = int(duration)
|
42 |
ani = FuncAnimation(fig, update, frames=range(total_frames),
|
43 |
-
init_func=init, interval=
|
44 |
|
45 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
|
46 |
-
ani.save(tmpfile.name, writer='ffmpeg', fps=
|
47 |
video_path = tmpfile.name
|
48 |
|
49 |
return video_path
|
|
|
9 |
def extract_waveform_animation(audio_file, window_seconds=5):
|
10 |
y, sr = librosa.load(audio_file, sr=None)
|
11 |
duration = librosa.get_duration(y=y, sr=sr)
|
12 |
+
FPS = 30
|
13 |
fig, ax = plt.subplots()
|
14 |
line, = ax.plot([], [], lw=2)
|
15 |
window_length = int(window_seconds * sr)
|
|
|
27 |
|
28 |
def update(frame):
|
29 |
# Get current window
|
30 |
+
start = frame * (sr / FPS)
|
31 |
end = start + window_length
|
32 |
window = y[start:end]
|
33 |
|
|
|
40 |
|
41 |
total_frames = int(duration)
|
42 |
ani = FuncAnimation(fig, update, frames=range(total_frames),
|
43 |
+
init_func=init, interval=window_seconds, blit=False)
|
44 |
|
45 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
|
46 |
+
ani.save(tmpfile.name, writer='ffmpeg', fps=FPS)
|
47 |
video_path = tmpfile.name
|
48 |
|
49 |
return video_path
|