add audio2mesh model support
This commit is contained in:
1 parent
5eb304186a
commit
386df9a4ab
83 files changed
+9318
-1307
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
import torch
|
||||
from pathlib import Path
|
||||
|
||||
# common
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/Audio2Motion")
|
||||
from common.animation import save_images_with_audio
|
||||
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/DECA_old")
|
||||
from decalib.deca import DECA
|
||||
from decalib.utils import util
|
||||
from decalib.utils.config import cfg as deca_cfg
|
||||
|
||||
def tensor2image(tensor):
|
||||
image = tensor.detach().cpu().numpy()
|
||||
image = image*255.
|
||||
image = np.maximum(np.minimum(image, 255), 0)
|
||||
image = image.transpose(1,2,0)[:,:,[2,1,0]]
|
||||
return image.astype(np.uint8).copy()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# load data
|
||||
# pid = "Bringing-Our-Workplace-Policies-into-the-21st-Century" # "2021-P22"
|
||||
pid = "Celebrating-Independence-Day"
|
||||
path_root = Path("/yrfs/lsen/DATA/Obama/processing/")
|
||||
path_data = path_root.joinpath(pid)
|
||||
|
||||
path_pos = path_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
path_idn = path_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
path_exp = path_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
# path_audio = path_data.joinpath("audio/audio_trim.wav")
|
||||
path_audio = path_data.joinpath("audio/audio_trim_60_120s.wav")
|
||||
|
||||
|
||||
fps = 29.97002997002997
|
||||
nframe_beg = int(60 * fps + 0.5)
|
||||
nframe = int(120 * fps + 0.5)
|
||||
print(f"fps = {fps}, beg = {nframe_beg}, len= 120s * fps = frame = {nframe}")
|
||||
|
||||
data_pos = np.load(path_pos)[nframe_beg:nframe_beg+nframe] # N x 6
|
||||
data_idn = np.load(path_idn)[nframe_beg:nframe_beg+nframe] # N x 100
|
||||
data_exp = np.load(path_exp)[nframe_beg:nframe_beg+nframe] # N x 50
|
||||
N = data_exp.shape[0]
|
||||
|
||||
|
||||
# load mean
|
||||
path_deca_mean = Path("./data/DECA_obama_mean.npy")
|
||||
mean_dict = np.load(path_deca_mean, allow_pickle=True).item()
|
||||
print(mean_dict.keys())
|
||||
|
||||
# load deca model
|
||||
device = torch.device("cuda:3")
|
||||
deca_cfg.model.use_tex = False
|
||||
deca_cfg.dataset.image_size = 512
|
||||
netR = DECA(config = deca_cfg, device=device)
|
||||
|
||||
# render
|
||||
path_save = path_data.joinpath("video/deca_render_no_pose_60_120s.mp4")
|
||||
v_render_pt = []
|
||||
nbatch_render = 10
|
||||
for k in range(0, N, nbatch_render):
|
||||
codedict = {}
|
||||
|
||||
codedict["exp"] = data_exp[k:k+nbatch_render, :50] # (nbatch_render, 50)
|
||||
|
||||
nbatch_real = codedict["exp"].shape[0]
|
||||
|
||||
codedict["pose"] = np.zeros((nbatch_real, 6)) # (nbatch_render, 6)
|
||||
codedict["pose"][:, 3:6] = data_pos[k:k+nbatch_render, 3:6]
|
||||
# codedict["pose"] = data_pos[k:k+nbatch_render, :] # (nbatch_render, 6)
|
||||
|
||||
# codedict["shape"] = np.zeros((nbatch_real, 100)) # (nabtch_render, 100)
|
||||
codedict["shape"] = data_idn[k:k+nbatch_render, :] # (nabatch_render, 100)
|
||||
|
||||
# others ==> to mean
|
||||
mean_cam = [[5,0,0]] # or [self.mean_dict["cam"]]
|
||||
codedict["cam"] = np.repeat(mean_cam, nbatch_real, axis=0) # (nbatch_render, 3)
|
||||
codedict["light"] = np.repeat([mean_dict["light"]], nbatch_real, axis=0) # (nbatch_render, 9, 3)
|
||||
# codedict["shape"] = np.repeat([mean_dict["shape"]], nbatch_real, axis=0) # (nbatch_render, 100)
|
||||
codedict["detail"] = np.repeat([mean_dict["detail"]], nbatch_real, axis=0) # (nbatch_render, 128)
|
||||
|
||||
|
||||
_, visdict_pt = netR.decode_one(codedict, nbatch_real, device)
|
||||
render_pt = visdict_pt["shape_images"] # (nbatch_render, 3, 224, 224)
|
||||
# print(f"render pt shape = {render_pt.shape}")
|
||||
|
||||
for m in range(nbatch_real):
|
||||
# cv2.imwrite(str(kpath_image), util.tensor2image(render_image[m, ...]))
|
||||
v_render_pt.append(tensor2image(render_pt[m, ...]))
|
||||
|
||||
|
||||
|
||||
save_images_with_audio(v_render_pt, path_audio, path_save)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# fid = "Bringing-Our-Workplace-Policies-into-the-21st-Century"
|
||||
fid = "Equipping-Workers-with-Skills-Employers-Need-Now-and-for-the-Future"
|
||||
path_root = Path("/yrfs/lsen/DATA/Obama/processing/")
|
||||
path_data = path_root.joinpath(fid)
|
||||
|
||||
path_coeff = path_data.joinpath("DECA_coeff")
|
||||
vpath_coeff = sorted(path_coeff.glob("*.npy"), reverse=False)
|
||||
print(f"Have {len(vpath_coeff)} frames")
|
||||
|
||||
|
||||
feat_shape = []
|
||||
feat_tex = []
|
||||
feat_cam = []
|
||||
feat_exp = []
|
||||
feat_pos = []
|
||||
feat_light = []
|
||||
feat_detail = []
|
||||
|
||||
for ipath_coeff in vpath_coeff:
|
||||
|
||||
data_coeff = np.load(ipath_coeff, allow_pickle=True).item()
|
||||
|
||||
# print(data_coeff.keys())
|
||||
|
||||
feat_exp.append(data_coeff["exp"])
|
||||
feat_pos.append(data_coeff["pose"])
|
||||
feat_tex.append(data_coeff["tex"])
|
||||
feat_cam.append(data_coeff["cam"])
|
||||
feat_light.append(data_coeff["light"])
|
||||
feat_detail.append(data_coeff["detail"])
|
||||
feat_shape.append(data_coeff["shape"])
|
||||
|
||||
# save
|
||||
feat_exp = np.array(feat_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.array(feat_pos) # (nframe_trim, 6)
|
||||
feat_tex = np.array(feat_tex) # (nframe_trim, 50)
|
||||
feat_cam = np.array(feat_cam) # (nframe_trim, 6)
|
||||
feat_light = np.array(feat_light) # (nframe_trim, 50)
|
||||
feat_detail = np.array(feat_detail) # (nframe_trim, 6)
|
||||
feat_shape = np.array(feat_shape) # (nframe_trim, 50)
|
||||
|
||||
mean_exp = feat_exp.mean(axis=0)
|
||||
mean_pos = feat_pos.mean(axis=0)
|
||||
mean_tex = feat_tex.mean(axis=0)
|
||||
mean_cam = feat_cam.mean(axis=0)
|
||||
mean_light = feat_light.mean(axis=0)
|
||||
mean_detail = feat_detail.mean(axis=0)
|
||||
mean_shape = feat_shape.mean(axis=0)
|
||||
|
||||
print(f"feat_exp shape = {feat_exp.shape}, mean = {mean_exp.shape}, \n{mean_exp}")
|
||||
print(f"mean_pos shape = {feat_pos.shape}, mean = {mean_pos.shape}, \n{mean_pos}")
|
||||
print(f"mean_tex shape = {feat_tex.shape}, mean = {mean_tex.shape}, \n{mean_tex}")
|
||||
print(f"mean_cam shape = {feat_cam.shape}, mean = {mean_cam.shape}, \n{mean_cam}")
|
||||
print(f"mean_light shape = {feat_light.shape}, mean = {mean_light.shape}, \n{mean_light}")
|
||||
print(f"mean_detail shape = {feat_detail.shape}, mean = {mean_detail.shape}, \n{mean_detail}")
|
||||
print(f"mean_shape shape = {feat_shape.shape}, mean = {mean_shape.shape}, \n{mean_shape}")
|
||||
|
||||
# save
|
||||
mean_DECA = {
|
||||
"exp": mean_exp, # (50, )
|
||||
"pose": mean_pos, # (6, )
|
||||
"tex": mean_tex, # (50, )
|
||||
"cam": mean_cam, # (3, )
|
||||
"light": mean_light, # (9, 3)
|
||||
"detail": mean_detail,# (128, )
|
||||
"shape": mean_shape, # (100, )
|
||||
}
|
||||
|
||||
path_save = "./data/DECA_obama_mean.npy"
|
||||
# np.save(path_save, mean_DECA)
|
||||
print("save to --> ", path_save)
|
||||
|
||||
|
||||
|
||||
+21
-26
@@ -9,41 +9,37 @@ from pathlib2 import Path
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/yrfs/lsen/DATA/Obama/processing') # '../data/trinity/source'
|
||||
path_save = Path('data/obama-deca-mel') # processing
|
||||
path_save = Path('data/obama-ds-daca-5h') # processing
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*/audio/feat_DECA_exp_trim.npy"))
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
v_dir_videos = [ipath.parent.parent for ipath in v_dir_videos]
|
||||
vids = [ipath.stem for ipath in v_dir_videos]
|
||||
print(f"Have {len(v_dir_videos)} video id[:3] > {vids[:3]}")
|
||||
|
||||
nv_total = len(v_dir_videos)
|
||||
nv_valid, nv_test = 1, 1
|
||||
nv_train = nv_total - (nv_valid + nv_test)
|
||||
|
||||
vid_test = vids[:nv_test]
|
||||
vid_valid = vids[nv_test:nv_test+nv_valid]
|
||||
vid_train = vids[nv_test+nv_valid:]
|
||||
vid_test = set(vids[:1])
|
||||
vid_valid = set(vids[1:2])
|
||||
vid_train = set(vids) - vid_test - vid_valid
|
||||
print("vid_test = ", vid_test)
|
||||
print("vid_valid = ", vid_valid)
|
||||
|
||||
|
||||
# for each video
|
||||
data_train, data_valid, data_test = {}, {}, {}
|
||||
durations_train, durations_valid, durations_test = 0, 0, 0
|
||||
|
||||
for i, ipath_data in enumerate(v_dir_videos):
|
||||
vid = ipath_data.stem
|
||||
|
||||
if i % 50 == 0:
|
||||
print(f"\n processing the {i}-th video {vid} ... ")
|
||||
print(f"\n processing the {i}-th video {vid} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
ipath_exp = ipath_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
ipath_pos = ipath_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
# ipath_speech = ipath_data.joinpath("audio/audio_trim.wav")
|
||||
ipath_speech = ipath_data.joinpath("audio/feat_mel_no_align_trim.npy")
|
||||
|
||||
|
||||
|
||||
if not ipath_speech.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_speech}" )
|
||||
continue
|
||||
@@ -53,19 +49,14 @@ if __name__ == "__main__":
|
||||
continue
|
||||
|
||||
# check existing
|
||||
if not ipath_speech.exists() or not ipath_info.exists():
|
||||
msg = "ERROR: NOT exsiting "
|
||||
if not ipath_info.exists():
|
||||
msg += f"\n\t {ipath_info} "
|
||||
if not ipath_speech.exists():
|
||||
msg += f"\n\t {ipath_speech} "
|
||||
|
||||
print(msg)
|
||||
if not ipath_info.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_info}")
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["info"] # 29.89990, NOT fixed
|
||||
width = info["width"][0] # 1280 or 1920
|
||||
height = info["height"][0] # 720 or 1080
|
||||
print("\nwidth=",width, "height=",height, "fps=",info["fps"], "-->", ipath_data)
|
||||
@@ -81,12 +72,16 @@ if __name__ == "__main__":
|
||||
continue
|
||||
|
||||
# load data
|
||||
# feat_idn = np.load(ipath_idn) # (nframe_trim, 100)
|
||||
feat_exp = np.load(ipath_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.load(ipath_pos) # (nframe_trim, 6) # (N, 6)
|
||||
data_motion = np.concatenate([feat_exp, feat_pos[:, 3:6]], axis=1) # (N, 53)
|
||||
data_speech = np.load(ipath_speech) # (M, 80) please note that M != N
|
||||
feat_exp = np.load(ipath_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.load(ipath_pos) # (nframe_trim, 6)
|
||||
feat_pos_head = feat_pos[:, :3] # (nframe_trim, 3)
|
||||
feat_pos_lips = feat_pos[:, 3:] # (nframe_trim, 3)
|
||||
data_motion = np.concatenate([feat_exp, feat_pos_lips], axis=1) # (N, 53)
|
||||
print(f"motion = {data_motion.shape}")
|
||||
|
||||
|
||||
# load raw audio
|
||||
data_speech = np.load(ipath_speech) # (M, 80) please note that M != N
|
||||
print(f"motion data = {data_motion.shape}, speech data = {data_speech.shape}")
|
||||
# assert data_motion.shape[0] == data_speech.shape[0]
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import json
|
||||
import torchaudio
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
from scipy import interpolate
|
||||
|
||||
def convert_fps(y, source_fps = 30, target_fps=25):
|
||||
"""
|
||||
y, N x 136, with 30fps
|
||||
"""
|
||||
|
||||
nsteps = y.shape[0]
|
||||
x = np.arange(0, nsteps, 1)
|
||||
# print("x:", x[::30], x[-10:])
|
||||
func = interpolate.interp1d(x, y=y, axis=0)
|
||||
|
||||
x_new = np.arange(0, nsteps-1, 1.0*source_fps/target_fps)
|
||||
# print("x_new", x_new[::30], x_new[-10:])
|
||||
y_new = func(x_new)
|
||||
|
||||
if source_fps < target_fps:
|
||||
y_new = np.concatenate([y_new, y[-1:]])
|
||||
|
||||
return y_new
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/yrfs/lsen/DATA/Obama/processing') # '../data/trinity/source'
|
||||
path_save = Path('data/obama-raw-deca-9h-50fps') # processing
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*/audio/feat_DECA_exp_trim.npy"))
|
||||
v_dir_videos = [ipath.parent.parent for ipath in v_dir_videos]
|
||||
vids = [ipath.stem for ipath in v_dir_videos]
|
||||
print(f"Have {len(v_dir_videos)} video id[:3] > {vids[:3]}")
|
||||
|
||||
vid_test = set(vids[:2])
|
||||
vid_valid = set(vids[2:4])
|
||||
vid_train = set(vids) - vid_test - vid_valid
|
||||
print("vid_test = ", vid_test)
|
||||
print("vid_valid = ", vid_valid)
|
||||
|
||||
# for each video
|
||||
data_train, data_valid, data_test = {}, {}, {}
|
||||
durations_train, durations_valid, durations_test = 0, 0, 0
|
||||
|
||||
for i, ipath_data in enumerate(v_dir_videos):
|
||||
vid = ipath_data.stem
|
||||
|
||||
print(f"\n processing the {i}-th video {vid} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
ipath_exp = ipath_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
ipath_pos = ipath_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
ipath_idn = ipath_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
ipath_speech = ipath_data.joinpath("audio/audio_trim.wav")
|
||||
|
||||
if not ipath_speech.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_speech}" )
|
||||
continue
|
||||
|
||||
if not ipath_exp.exists() or not ipath_pos.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_pos} or {ipath_exp}" )
|
||||
continue
|
||||
|
||||
# check existing
|
||||
if not ipath_info.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_info}")
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["fps"] # 29.89990, NOT fixed
|
||||
width = info["width"][0] # 1280 or 1920
|
||||
height = info["height"][0] # 720 or 1080
|
||||
print("\nwidth=",width, "height=",height, "fps=",fps, "-->", ipath_data)
|
||||
|
||||
# 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 data
|
||||
feat_exp = np.load(ipath_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.load(ipath_pos) # (nframe_trim, 6)
|
||||
feat_idn = np.load(ipath_idn) # (nframe_trim, 100)
|
||||
|
||||
feat_pos_head = feat_pos[:, :3] # (nframe_trim, 3)
|
||||
feat_pos_lips = feat_pos[:, 3:] # (nframe_trim, 3)
|
||||
data_motion = np.concatenate([feat_exp, feat_pos_lips], axis=1) # (N, 53)
|
||||
print(f"motion = {data_motion.shape}")
|
||||
|
||||
# laod shape
|
||||
|
||||
|
||||
# resample to 30fps
|
||||
fps_convert = 50
|
||||
data_motion = convert_fps(data_motion, source_fps=fps, target_fps=fps_convert)
|
||||
data_shape = convert_fps(feat_idn, source_fps=fps, target_fps=fps_convert)
|
||||
nframe_convert = data_motion.shape[0]
|
||||
assert data_motion.shape[0] == data_shape.shape[0], f"motion = {data_motion.shape[0]} shape = {data_shape.shape[0]}"
|
||||
|
||||
print(f"after convert motion = {data_motion.shape}, duration = {nframe_convert / fps_convert} vs. orignal duration = {nframe_trim / fps}")
|
||||
# print(f"after convert shape = {data_shape.shape}, duration = {nframe_convert / fps_convert} vs. orignal duration = {nframe_trim / fps}")
|
||||
|
||||
# load raw audioß
|
||||
audio_raw, sample_rate = torchaudio.load(ipath_speech)
|
||||
print(f"audio_raw shape = {audio_raw.shape}, sr = {sample_rate}, duration = {(len(audio_raw[0])/sample_rate)}")
|
||||
|
||||
if len(audio_raw.shape) == 2:
|
||||
audio_raw = audio_raw[0]
|
||||
|
||||
if sample_rate != 16000:
|
||||
resampler = torchaudio.transforms.Resample(sample_rate, 16_000)
|
||||
audio_raw = resampler(audio_raw).squeeze().numpy()
|
||||
print(f"audio_raw shape = {audio_raw.shape}, sr = {16000}, duration = {(len(audio_raw)/16000)}")
|
||||
|
||||
# add to data dict
|
||||
if vid in vid_train:
|
||||
durations_train += nframe_trim / fps
|
||||
data_train[vid] = {
|
||||
"W": width, "H": height,
|
||||
"sr":16000, "FPS": fps_convert,
|
||||
"nframe": nframe_convert,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_shape,
|
||||
}
|
||||
|
||||
if vid in vid_valid:
|
||||
durations_valid += nframe_trim / fps
|
||||
data_valid[vid] = {
|
||||
"W": width, "H": height,
|
||||
"sr":16000, "FPS": fps_convert,
|
||||
"nframe": nframe_convert,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_shape,
|
||||
}
|
||||
|
||||
if vid in vid_test:
|
||||
durations_test += nframe_trim / fps
|
||||
data_test[vid] = {
|
||||
"W": width, "H": height,
|
||||
"sr":16000, "FPS": fps_convert,
|
||||
"nframe": nframe_convert,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_shape,
|
||||
}
|
||||
|
||||
|
||||
|
||||
np.savez(path_save.joinpath("data_train.npz"), data=data_train)
|
||||
np.savez(path_save.joinpath("data_valid.npz"), data=data_valid)
|
||||
np.savez(path_save.joinpath("data_test.npz"), data=data_test)
|
||||
|
||||
print(f"Total ids: data_train ({len(data_train)}), data_test ({len(data_test)}) data_valid({len(data_valid)})")
|
||||
print(f"Total frames: data_train ({durations_train / 3600} h), data_test ({durations_test / 60 } min) data_valid({durations_valid / 60} min)")
|
||||
|
||||
print(f"--> {path_save}")
|
||||
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import moviepy.editor as mpy
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
fps_save = 30
|
||||
path_save = "/yrfs/lsen/DATA/Obama/processing/Celebrating-Independence-Day/video/audio2mesh_compare_60_115_GT.mp4"
|
||||
|
||||
path_clipA = "experiments/audio2mesh/infer_audio2mesh_EN_20220208/20220225-17H57M52S/audio_trim_60_120s_infer_20220217-17H36M22S_epoch_115_00.mp4"
|
||||
path_clipB = "experiments/audio2mesh/infer_audio2mesh_EN_20220208/20220225-17H48M06S/audio_trim_60_120s_infer_20220223-22H17M02S_epoch_060_00.mp4"
|
||||
path_clipC = "/yrfs/lsen/DATA/Obama/processing/Celebrating-Independence-Day/video/deca_render_no_pose_60_120s.mp4"
|
||||
|
||||
|
||||
# path_clipAA = "experiments/audio2mesh/infer_audio2mesh_EN_20220208/20220224-17H27M45S/audio_trim_120s_infer_20220223-22H17M02S_epoch_060_00.mp4"
|
||||
# path_clipBB = "/yrfs/lsen/DATA/Obama/processing/Bringing-Our-Workplace-Policies-into-the-21st-Century/video/deca_render_no_pose_120s.mp4"
|
||||
# path_clipCC = "/yrfs/lsen/DATA/LuoXData/processing2/2021-P09/video/deca_render_no_pos_60_120s.mp4"
|
||||
|
||||
path_audio = "/yrfs/lsen/DATA/Obama/processing/Celebrating-Independence-Day/audio/audio_trim_60_120s.wav"
|
||||
|
||||
clip_A = mpy.VideoFileClip(path_clipA)
|
||||
clip_B = mpy.VideoFileClip(path_clipB)
|
||||
clip_C = mpy.VideoFileClip(path_clipC)
|
||||
|
||||
# clip_AA = mpy.VideoFileClip(path_clipAA)
|
||||
# clip_BB = mpy.VideoFileClip(path_clipBB)
|
||||
# clip_CC = mpy.VideoFileClip(path_clipCC)
|
||||
|
||||
audio = mpy.AudioFileClip(path_audio)
|
||||
|
||||
# txtClip = mpy.TextClip('orignal',color='white', kerning = 5, fontsize=18)
|
||||
# clip_A = mpy.CompositeVideoClip( [clip_A, txtClip.set_pos('top')], size=(512,512))
|
||||
|
||||
# txtClip = mpy.TextClip('-pose',color='white', kerning = 5, fontsize=18)
|
||||
# clip_B = mpy.CompositeVideoClip( [clip_B, txtClip.set_pos('top')], size=(512,512))
|
||||
|
||||
# txtClip = mpy.TextClip('-pose-idn',color='white', kerning = 5, fontsize=18)
|
||||
# clip_C = mpy.CompositeVideoClip( [clip_C, txtClip.set_pos('top')], size=(512,512))
|
||||
|
||||
# align to clipGT
|
||||
duration = min(min(clip_A.duration, clip_C.duration), audio.duration)
|
||||
|
||||
clip_A = clip_A.set_duration(duration)
|
||||
clip_B = clip_B.set_duration(duration)
|
||||
clip_C = clip_C.set_duration(duration)
|
||||
audio = audio.set_duration(duration)
|
||||
|
||||
# stack
|
||||
# video = mpy.clips_array([[clip_A, clip_B], [clip_AA, clip_BB]]) # clip_C
|
||||
video = mpy.clips_array([[clip_A, clip_B, clip_C]]) # clip_C
|
||||
video = video.set_audio(audio) # audd audio
|
||||
|
||||
# save
|
||||
video.write_videofile(path_save, fps=fps_save, logger=None)
|
||||
print(f"save to > {path_save}")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user