-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_video_save.py
More file actions
26 lines (20 loc) · 860 Bytes
/
simple_video_save.py
File metadata and controls
26 lines (20 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# import subprocess
import numpy as np
import librosa.display
import matplotlib.pyplot as plt
image_path = '/home/natalia/Data/spectrogram.jpg'
sound_path = '/home/natalia/Data/sample.wav'
output_path = '/home/natalia/Data/video.mp4'
# Usage:
# subprocess.call(
# ['ffmpeg', '-loop', '1', '-i', image_path, '-i', sound_path, '-c:v', 'libx264', '-c:a', 'aac', '-strict',
# 'experimental', '-b:a', '192k', '-t', '1', output_path])
# Load audio file using librosa
y, sr = librosa.load(sound_path)
# Convert the spectrogram to decibels (dB)
log_spec = librosa.amplitude_to_db(librosa.stft(y), ref=np.max)
# Plot and save spectrogram as JPG
librosa.display.specshow(log_spec, sr=sr, x_axis='time', y_axis='mel')
plt.title('Log-Scaled Spectrogram of {}'.format(sound_path))
plt.tight_layout()
plt.savefig('/home/natalia/Data/spectrogram.jpg')