update audduio2pose v1.0
This commit is contained in:
1 parent
c2797657f8
commit
3a15011f4d
28 files changed
+1817
-483
No files matched your search
@@ -1,10 +1,14 @@
|
||||
import moviepy.editor as mpy
|
||||
import numpy as np
|
||||
import os
|
||||
import cv2
|
||||
import sys
|
||||
# sys.path.insert(0, "/ssdata1/lsen/CODE/Audio2Motion")
|
||||
from common.landmark import landmark_to_images
|
||||
|
||||
import tempfile
|
||||
from scipy.io import wavfile
|
||||
|
||||
|
||||
def save_animation(data_motion, path_save, suffix, w=128*5, h=72*5, dpi=80):
|
||||
""" convert data_motion to .mp4 animation
|
||||
@@ -139,6 +143,86 @@ def save_animation_with_gts(images_list, path_save):
|
||||
# close
|
||||
animation.close()
|
||||
|
||||
|
||||
# def write_videos(images, raw_speech, path_save, fps=50):
|
||||
|
||||
def write_video(list_images, raw_speech, path_video, fps=50, sr=16000):
|
||||
""" convert images_pt to .mp4 animation
|
||||
list_images, shape len=N list [512, 512, 3], or [1080, 1920, 3]
|
||||
raw_speech, shape = (nsegmet, )
|
||||
"""
|
||||
|
||||
num_frame = len(list_images)
|
||||
H, W = list_images[0].shape[:2]
|
||||
|
||||
file_audio = tempfile.NamedTemporaryFile(suffix='.wav')
|
||||
file_video = tempfile.NamedTemporaryFile(suffix='.mp4')
|
||||
|
||||
# write audio
|
||||
wavfile.write(file_audio.name, rate=sr, data=raw_speech)
|
||||
|
||||
# write video
|
||||
if int(cv2.__version__[0]) < 3:
|
||||
writer = cv2.VideoWriter(file_video.name, cv2.cv.CV_FOURCC(*'mp4v'), fps, (W, H), True)
|
||||
else:
|
||||
writer = cv2.VideoWriter(file_video.name, cv2.VideoWriter_fourcc(*'mp4v'), fps, (W, H), True)
|
||||
|
||||
for i in range(num_frame):
|
||||
writer.write(list_images[i])
|
||||
|
||||
# close
|
||||
writer.release()
|
||||
cv2.destroyAllWindows
|
||||
|
||||
# concate to video
|
||||
cmd = f"ffmpeg -y -i {file_video.name} -i {file_audio.name} -map 0:v -vcodec libx264 -map 1:a -c:v copy -shortest -loglevel quiet {str(path_video)}"
|
||||
os.system(cmd)
|
||||
|
||||
# close tmp file
|
||||
file_audio.close()
|
||||
file_video.close()
|
||||
|
||||
|
||||
|
||||
def write_video_with_gt(images_pt, images_gt, raw_speech, path_video, fps=50, sr=16000):
|
||||
""" convert images_pt to .mp4 animation
|
||||
images_pt, shape len= N list [H, W, 3], like [224, 224, 3], [512, 512, 3], or [1080, 1920, 3]
|
||||
images_gt, shape len= N list [H, W, 3], like [224, 224, 3], [512, 512, 3], or [1080, 1920, 3]
|
||||
raw_speech, shape = (nsegmet, )
|
||||
"""
|
||||
|
||||
num_frame = len(images_pt)
|
||||
H, W = images_pt[0].shape[:2]
|
||||
|
||||
file_audio = tempfile.NamedTemporaryFile(suffix='.wav')
|
||||
file_video = tempfile.NamedTemporaryFile(suffix='.mp4')
|
||||
|
||||
# write audio
|
||||
wavfile.write(file_audio.name, rate=sr, data=raw_speech)
|
||||
|
||||
# write video
|
||||
if int(cv2.__version__[0]) < 3:
|
||||
writer = cv2.VideoWriter(file_video.name, cv2.cv.CV_FOURCC(*'mp4v'), fps, (2*W, H), True)
|
||||
else:
|
||||
writer = cv2.VideoWriter(file_video.name, cv2.VideoWriter_fourcc(*'mp4v'), fps, (2*W, H), True)
|
||||
|
||||
for i in range(num_frame):
|
||||
concate_image = np.concatenate((images_pt[i], images_gt), axis=1) # (H, 2*W, 3)
|
||||
writer.write(concate_image)
|
||||
|
||||
# close
|
||||
writer.release()
|
||||
cv2.destroyAllWindows
|
||||
|
||||
# concate to video
|
||||
cmd = f"ffmpeg -y -i {file_video.name} -i {file_audio.name} -map 0:v -vcodec libx264 -map 1:a -c:v copy -shortest -loglevel quiet {str(path_video)}"
|
||||
os.system(cmd)
|
||||
|
||||
# close tmp file
|
||||
file_audio.close()
|
||||
file_video.close()
|
||||
|
||||
|
||||
def save_images_with_audio(images, path_audio, path_save, fps=50):
|
||||
""" convert images_pt to .mp4 animation
|
||||
images_pt, shape len=N list [224, 224, 3]
|
||||
|
||||
Reference in new issue
Block a user