add audio2mesh_ar

This commit is contained in:
Sen Liang committed 2022-03-14 18:13:13 +08:00
1 parent ded9b27f71
commit e0f24982d1
46 files changed
+3917 -325

No files matched your search

+15 -19
View File
@@ -6,12 +6,13 @@ from moviepy.editor import VideoFileClip, AudioFileClip
if __name__ == '__main__':
# path_root = Path("/yrfs/lsen/DATA/Actor1")
path_root = Path("/yrfs/lsen/DATA/TestData")
vpath_videos = sorted(path_root.glob("raw/*.mp4"), reverse=False)
print(f"Have {len(vpath_videos)} dir files")
# IDs = ["2021-P29"]
IDs = ["clip_full"]
# for each video
for i, ipath_item in enumerate(vpath_videos):
@@ -19,7 +20,7 @@ if __name__ == '__main__':
print(f"processing {i}/{len(vpath_videos)} -> {ipath_item} ... ")
# if i < 40: continue
# if iname not in IDs: continue
if iname not in IDs: continue
# data path
ipath_data = path_root.joinpath("processing", ipath_item.stem)
@@ -39,21 +40,24 @@ if __name__ == '__main__':
# info = json.load(f)
# nframe_info = info['nframes']
# load video
video = VideoFileClip(str(ipath_item))
print(f"video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
if video.audio is None:
print("\nERROR: audio info is None")
continue
# Trim
# video = video.subclip(t_start=5.0, t_end=int(video.duration)-5.0)
# video = video.subclip(t_start=5.0, t_end=60.0)
# print(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# nframes = int(video.duration * video.fps)
# nframes = len(list(video.iter_frames()))
# save sub video fps=50
ipath_video_sub = ipath_video.joinpath("video_trim.mp4")
if ipath_video_sub.exists():
print("\nERROR: ipath_video_sub.exists()")
continue
@@ -61,23 +65,17 @@ if __name__ == '__main__':
video.write_videofile(str(ipath_video_sub), fps=50, audio=True)
print(f"save video > {ipath_video_sub}")
# reload video
video.close()
video = VideoFileClip(str(ipath_video_sub))
print(f"video reload duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# Trim
# video = video.subclip(t_start=20.0, t_end=int(video.duration)-20.0)
# print(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
nframes = int(video.duration * video.fps)
nframes = len(list(video.iter_frames()))
# check frames
nframe_real = len(list(ipath_frame.glob("*.jpg")))
if nframe_real == nframes:
print(f"\n Skip: have already done!")
continue
# nframe_real = len(list(ipath_frame.glob("*.jpg")))
# if nframe_real == nframes:
# print(f"\n Skip: have already done!")
# continue
# get audio
audio_sub = video.audio
@@ -91,7 +89,6 @@ if __name__ == '__main__':
audio_sub.write_audiofile(str(ipath_audio_sub), fps=audio_sub.fps)
print(f"save audio > {ipath_audio_sub}")
# # check fps
# if int(video.fps) != 50:
# print(f"\n Skip: fps != 50 realy fps={video.fps}, convert to 50fps")
@@ -111,7 +108,6 @@ if __name__ == '__main__':
print(info)
print(f"save video info in -> {ipath_infor}\n")
# save trim video
print(f"write_images_sequence...")
ipath_format = str(ipath_frame) + "/frame-%06d.jpg"
@@ -22,13 +22,18 @@ def main(args):
deca = DECA(config = deca_cfg, device=device)
path_data = Path("/yrfs/lsen/DATA/TestData/processing")
# path_data = Path("/yrfs/lsen/DATA/Actor1/processing")
v_dir_videos = sorted(path_data.glob("*"), reverse=False)
print(f"Have {len(v_dir_videos)} dir files")
# IDs = ["actor-2HD", "actor-3HD"]
IDs = ["clip_full"]
# for each video
for ipath_data in v_dir_videos[1:]:
for ipath_data in v_dir_videos:
ivideo_name = ipath_data.stem
print("\nprocessing ...", ivideo_name)
if ivideo_name not in IDs: continue
ipath_infor = ipath_data.joinpath("video/info.json")
ipath_frame = ipath_data.joinpath("frames")
@@ -50,7 +55,7 @@ def main(args):
with open(str(ipath_infor), "r") as f:
info = json.load(f)
nframes = info['nframes']
nframes = info['nframes']
nframe_real = len(list(ipath_frame.glob("*.jpg")))
@@ -58,7 +63,6 @@ def main(args):
print(f"\n ERROR: nframe_real ={nframe_real} / nframe_info ={nframes}")
continue
# check if finish
nkpt2d = len(list(ipath_kpt2d.glob("*.txt")))
if nkpt2d + 10 > nframes:
@@ -66,7 +70,7 @@ def main(args):
continue
datatest = ObamaData(ipath_frame, iscrop=args.iscrop, face_detector=args.detector)
dataloader = DataLoader(datatest, batch_size=48, shuffle=False, drop_last=False)
dataloader = DataLoader(datatest, batch_size=64, shuffle=False, drop_last=False)
for i, ibatch_data in enumerate(dataloader):
@@ -114,7 +118,7 @@ if __name__ == '__main__':
parser.add_argument('-i', '--inputpath', default='TestSamples/examples', type=str,
help='path to the test data, can be image folder, image path, image list, video')
parser.add_argument('-d', '--device', default='cuda:2', type=str,
parser.add_argument('-d', '--device', default='cuda:0', type=str,
help='set device, cpu for using cpu' )
# process test images
parser.add_argument('--iscrop', default=True, type=lambda x: x.lower() in ['true', '1'],
@@ -7,8 +7,8 @@ from pathlib import Path
if __name__ == "__main__":
path_data = Path('/yrfs/lsen/DATA/TestData/processing') # '../data/trinity/source'
# path_data = Path('/yrfs/lsen/DATA/TestData/processing') # '../data/trinity/source'
path_data = Path("/yrfs/lsen/DATA/Actor1/processing")
v_dir_videos = sorted(path_data.glob("*"))
print(f"Have {len(v_dir_videos)} dir files")
@@ -25,8 +25,10 @@ def tensor2image(tensor):
if __name__ == "__main__":
# load data
pid = "1645666605877506" # "2021-P22"
path_root = Path("/yrfs/lsen/DATA/TestData/processing/")
pid = "2022-P01" # "2021-P22", actor-2HD
# path_root = Path("/yrfs/lsen/DATA/TestData/processing/")
path_root = Path("/yrfs/lsen/DATA/Actor1/processing")
path_data = path_root.joinpath(pid)
path_pos = path_data.joinpath("audio/feat_DECA_pos_trim.npy")
@@ -53,7 +55,7 @@ if __name__ == "__main__":
netR = DECA(config = deca_cfg, device=device)
# render
path_save = path_data.joinpath("video/deca_render_no_pos_no_idn.mp4")
path_save = path_data.joinpath("video/deca_render_no_pos.mp4")
v_render_pt = []
nbatch_render = 10
for k in range(0, N, nbatch_render):
@@ -67,8 +69,8 @@ if __name__ == "__main__":
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)
# 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"]]