80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
import os
|
|
import sys
|
|
import json
|
|
|
|
import numpy as np
|
|
from pathlib2 import Path
|
|
|
|
if __name__ == "__main__":
|
|
|
|
path_data = Path('/mnt/data2/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_info = ipath_data.joinpath("video/info.json")
|
|
ipath_ldmk = ipath_data.joinpath("landmk-PFLD")
|
|
ipath_save_feat = ipath_data.joinpath("audio/feat_ldmk_trim.npy")
|
|
|
|
if ipath_save_feat.exists():
|
|
continue
|
|
|
|
# load video info
|
|
with open(str(ipath_info), "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 landmark
|
|
feat_ldmk = []
|
|
prev_ldmk = None
|
|
nContinue = 0
|
|
for j in range(ibeg, iend):
|
|
jpath_ldmk = ipath_ldmk.joinpath(f"frame--{j:05d}.txt")
|
|
|
|
if not jpath_ldmk.exists():
|
|
print("ERROR: Missing the landmark of frame --> ", jpath_ldmk)
|
|
if nContinue <= 2:
|
|
data_ldmk = prev_ldmk
|
|
nContinue += 1
|
|
else:
|
|
nContinue += 1
|
|
break
|
|
|
|
else:
|
|
data_ldmk = np.loadtxt(jpath_ldmk).astype(np.float)
|
|
prev_ldmk = data_ldmk
|
|
nContinue = 0
|
|
|
|
feat_ldmk.append(data_ldmk)
|
|
# if j % 100 == 0:
|
|
# print(f"the {j:05d}-th landmark")
|
|
|
|
|
|
# save
|
|
feat_ldmk = np.array(feat_ldmk)
|
|
if nContinue <= 2 and feat_ldmk.shape[0] == (iend-ibeg):
|
|
np.save(ipath_save_feat, feat_ldmk)
|
|
print(f"feat shape = {feat_ldmk.shape}, save to -> {ipath_save_feat}") # (nframe, 68, 2)
|
|
else:
|
|
print(f"ERROR: some landmark missing or length not same, length = {feat_ldmk.shape}/{iend-ibeg}")
|
|
|
|
|
|
|
|
|