Happy new years
This commit is contained in:
1 parent
c7175dd7ff
commit
8c4865effb
53 files changed
+4604
-61
No files matched your search
+29
-2
@@ -145,7 +145,15 @@ def save_images_with_audio(images, path_audio, path_save):
|
||||
N = len(images)
|
||||
|
||||
# load audio
|
||||
# if isinstance(path_audio, str):
|
||||
# print(f"load audio form str")
|
||||
audioclip = mpy.AudioFileClip(str(path_audio))
|
||||
|
||||
# elif isinstance(path_audio, np.ndarray):
|
||||
# print(f"load audio form np.ndarray")
|
||||
# audioclip = mpy.AudioFileClip(path_audio, fps=16000)
|
||||
|
||||
|
||||
duration = audioclip.duration
|
||||
|
||||
# add video
|
||||
@@ -182,14 +190,15 @@ def save_animation_with_gt5(images_pt, images_gt, images_A, images_B, images_C,
|
||||
animation.write_videofile(str(path_save), fps=fps, logger=None)
|
||||
|
||||
|
||||
def save_animation_with_gt2(images_pt, images_gt, path_save):
|
||||
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
|
||||
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
|
||||
fps = fps if fps else 30
|
||||
|
||||
N = len(images_pt)
|
||||
duration = N / fps
|
||||
# print(f"fps = {fps}, N ={N}, duration={duration}")
|
||||
@@ -200,6 +209,24 @@ def save_animation_with_gt2(images_pt, images_gt, path_save):
|
||||
|
||||
# mixture & save
|
||||
animation = mpy.clips_array([[animation_pt, animation_gt]])
|
||||
|
||||
|
||||
if path_audio is not None:
|
||||
audioclip = mpy.AudioFileClip(str(path_audio))
|
||||
|
||||
# cut-off
|
||||
if (start_time is not None) and (end_time is not None):
|
||||
print(f"subclip clips {start_time}:{end_time}")
|
||||
audioclip = audioclip.subclip(start_time, end_time)
|
||||
|
||||
# alignment to video
|
||||
audioclip = audioclip.set_duration(duration)
|
||||
|
||||
# add audio to animation
|
||||
animation = animation.set_audio(audioclip)
|
||||
animation = animation.set_duration(duration)
|
||||
|
||||
|
||||
animation.write_videofile(str(path_save), fps=fps)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user