add audio2mesh model support
This commit is contained in:
1 parent
5eb304186a
commit
386df9a4ab
83 files changed
+9318
-1307
No files matched your search
+20
-26
@@ -2,7 +2,7 @@ import moviepy.editor as mpy
|
||||
import numpy as np
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, "/mnt/data/CODE/Audio2Expression")
|
||||
# sys.path.insert(0, "/ssdata1/lsen/CODE/Audio2Motion")
|
||||
from common.landmark import landmark_to_images
|
||||
|
||||
|
||||
@@ -136,6 +136,9 @@ def save_animation_with_gts(images_list, path_save):
|
||||
animation = mpy.clips_array([animations])
|
||||
animation.write_videofile(str(path_save), fps=fps, logger=None)
|
||||
|
||||
# close
|
||||
animation.close()
|
||||
|
||||
def save_images_with_audio(images, path_audio, path_save):
|
||||
""" convert images_pt to .mp4 animation
|
||||
images_pt, shape len=N list [224, 224, 3]
|
||||
@@ -153,7 +156,6 @@ def save_images_with_audio(images, path_audio, path_save):
|
||||
# print(f"load audio form np.ndarray")
|
||||
# audioclip = mpy.AudioFileClip(path_audio, fps=16000)
|
||||
|
||||
|
||||
duration = audioclip.duration
|
||||
|
||||
# add video
|
||||
@@ -165,30 +167,11 @@ def save_images_with_audio(images, path_audio, path_save):
|
||||
animation.write_videofile(str(path_save), fps=fps)
|
||||
print(f"fps = {fps}, N ={N}, duration={duration} -> save to = {path_save}")
|
||||
|
||||
# close
|
||||
audioclip.close()
|
||||
animation.close()
|
||||
|
||||
|
||||
def save_animation_with_gt5(images_pt, images_gt, images_A, images_B, images_C, path_save):
|
||||
""" convert images_pt to .mp4 animation
|
||||
images_pt, shape len=N list [224, 224, 3]
|
||||
images_gt, shape len=N list [224, 224, 3]
|
||||
"""
|
||||
# print(f"images_pt shape = {len(images_pt)}, shape[0]={images_pt[0].shape}")
|
||||
fps = 30
|
||||
N = len(images_pt)
|
||||
duration = N / fps
|
||||
# print(f"fps = {fps}, N ={N}, duration={duration}")
|
||||
|
||||
# assert len(images_pt) == len(images_gt), f"pt and gt imamge size not the same ({len(images_pt)}, {len(images_pt)})"
|
||||
animation_pt = mpy.VideoClip(lambda t: images_pt[int(fps * t + 0.5) -1], duration= duration)
|
||||
animation_gt = mpy.VideoClip(lambda t: images_gt[int(fps * t + 0.5) -1], duration= duration)
|
||||
animation_A = mpy.VideoClip(lambda t: images_A[int(fps * t + 0.5) -1], duration= duration)
|
||||
animation_B = mpy.VideoClip(lambda t: images_B[int(fps * t + 0.5) -1], duration= duration)
|
||||
animation_C = mpy.VideoClip(lambda t: images_C[int(fps * t + 0.5) -1], duration= duration)
|
||||
|
||||
# mixture & save
|
||||
animation = mpy.clips_array([[animation_pt, animation_gt, animation_A, animation_B, animation_C]])
|
||||
animation.write_videofile(str(path_save), fps=fps, logger=None)
|
||||
|
||||
|
||||
def save_animation_with_gt2(images_pt, images_gt, path_save, fps=None, path_audio=None, start_time=None, end_time=None):
|
||||
""" convert images_pt to .mp4 animation
|
||||
@@ -228,14 +211,20 @@ def save_animation_with_gt2(images_pt, images_gt, path_save, fps=None, path_audi
|
||||
|
||||
|
||||
animation.write_videofile(str(path_save), fps=fps)
|
||||
|
||||
# close
|
||||
animation_pt.close()
|
||||
animation_gt.close()
|
||||
animation.close()
|
||||
|
||||
|
||||
|
||||
def save_animation_with_gt(data_motion, data_motion_gt, path_save, suffix, w=128*5, h=72*5, dpi=80, maxsave=3):
|
||||
def save_animation_with_gt(data_motion, data_motion_gt, path_save, suffix, w=128*5, h=72*5, dpi=80, maxsave=3, fps=30):
|
||||
""" convert data_motion to .mp4 animation
|
||||
data_motion, shape [B, N, 68, 2]
|
||||
data_motion_gt, shape [B, N, 68, 2]
|
||||
"""
|
||||
fps = 30
|
||||
|
||||
B, *_ = data_motion.shape
|
||||
B = min(B, maxsave)
|
||||
|
||||
@@ -258,4 +247,9 @@ def save_animation_with_gt(data_motion, data_motion_gt, path_save, suffix, w=128
|
||||
ipath_save = path_save.joinpath(f"{suffix}_{i:02d}.mp4")
|
||||
animation.write_videofile(str(ipath_save), fps=fps, logger=None)
|
||||
|
||||
# close
|
||||
animation_pt.close()
|
||||
animation_gt.close()
|
||||
animation.close()
|
||||
|
||||
|
||||
+5
-1
@@ -1,5 +1,9 @@
|
||||
|
||||
def debug(opt, msg, verbose=False):
|
||||
def debug(opt=None, msg="", verbose=False):
|
||||
|
||||
if opt is None or verbose:
|
||||
print(msg)
|
||||
|
||||
if opt.DEBUG or verbose:
|
||||
print(msg)
|
||||
|
||||
Reference in new issue
Block a user