initial commit
This commit is contained in:
commit
c7175dd7ff
127 files changed
+13949
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import librosa
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/yrfs/lsen/DATA/Obama/processing') # '../data/trinity/source'
|
||||
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"))
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
# for each video
|
||||
for ipath_data in v_dir_videos:
|
||||
ivideo_name = ipath_data.stem
|
||||
|
||||
print(f"\n processing {ivideo_name} ... ")
|
||||
|
||||
ipath_infors = ipath_data.joinpath("video/info.json")
|
||||
ipath_audio_trim = ipath_data.joinpath("audio/audio_trim.wav")
|
||||
ipath_save_feat = ipath_data.joinpath("audio/feat_mel_trim.npy")
|
||||
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_infors), "r") as f:
|
||||
info = json.load(f)
|
||||
|
||||
fps = info["fps"]
|
||||
if len(info["active_frames"]) == 2:
|
||||
ibeg = info["active_frames"][0]
|
||||
iend = info["active_frames"][1]
|
||||
nframe_trim = iend - ibeg
|
||||
print(f"frame trim = {nframe_trim}, info['active_frames'] = {info['active_frames']}")
|
||||
else:
|
||||
print(f"ERROR: info['active_frames'] = {info['active_frames']}")
|
||||
continue
|
||||
|
||||
|
||||
# load trim audio
|
||||
data, sr = librosa.load(str(ipath_audio_trim), sr=16484) # 16484 = fps * 550 让这个sr是fps的整数,
|
||||
hop_len = int(sr / fps)
|
||||
n_fft = int(sr * 0.13) # default 2048
|
||||
print(f"data={data.shape}, sr={sr}, fps={fps}, hop_len={sr/fps}, frames = {(len(data) / sr) * fps}, minmax = {np.min(data)},{np.max(data)}")
|
||||
|
||||
# melspectrogram
|
||||
mel = librosa.feature.melspectrogram(y=data, sr=sr,
|
||||
n_fft=n_fft, # FFT窗口的长度
|
||||
hop_length=hop_len, # 帧移
|
||||
win_length=n_fft, # 窗口长度,默认=n_fft
|
||||
window="hann", # 加hanming窗
|
||||
n_mels=27, # 滤波器组
|
||||
fmin=0.0, fmax=8000)
|
||||
mel = np.log(mel+1).T
|
||||
print(f"sr={sr}, data ={data.shape}, mel = {mel.shape}, (min,max)=({np.min(mel), np.max(mel)}")
|
||||
|
||||
# align to video
|
||||
assert mel.shape[0] >= nframe_trim
|
||||
mel_align = mel[:nframe_trim, :]
|
||||
|
||||
# save
|
||||
# np.save(ipath_save_feat, mel_align)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user