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,3 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import json
|
||||
import moviepy
|
||||
@@ -38,19 +39,19 @@ if __name__ == '__main__':
|
||||
ipath_video.mkdir(parents=True, exist_ok=True)
|
||||
ipath_audio.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# # load video info & check
|
||||
if ipath_infor.exists():
|
||||
# continue
|
||||
with open(str(ipath_infor), "r") as f:
|
||||
info = json.load(f)
|
||||
nframe_info = info['nframes']
|
||||
# # # load video info & check
|
||||
# if ipath_infor.exists():
|
||||
# # continue
|
||||
# with open(str(ipath_infor), "r") as f:
|
||||
# info = json.load(f)
|
||||
# nframe_info = info['nframes']
|
||||
|
||||
# check frames
|
||||
nframe_real = len(list(ipath_frame.glob("*.jpg")))
|
||||
if nframe_real == nframe_info:
|
||||
print(f"\n Skip: have already done!")
|
||||
continue
|
||||
|
||||
# # check frames
|
||||
# nframe_real = len(list(ipath_frame.glob("*.jpg")))
|
||||
# if nframe_real == nframe_info:
|
||||
# print(f"\n Skip: have already done!")
|
||||
# continue
|
||||
|
||||
# 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)}")
|
||||
@@ -62,72 +63,80 @@ if __name__ == '__main__':
|
||||
durations += video.duration
|
||||
print(f"\n\t -> Total durations = ({durations / 60 } min) ({durations / 3600 } h))")
|
||||
# continue
|
||||
|
||||
# add
|
||||
ipath_video_sub = ipath_video.joinpath("video_trim.mp4")
|
||||
if not ipath_video_sub.exists():
|
||||
cmd = f"ffmpeg -y -ss 15 -t {int(video.duration)-15.0} -i {str(ipath_item)} -vcodec copy -acodec copy {str(ipath_video_sub)}"
|
||||
os.system(cmd)
|
||||
print(f"save video > {ipath_video_sub}")
|
||||
|
||||
# Trim
|
||||
# video = video.subclip(t_start=5.0, t_end=int(video.duration)-5.0) before 03.14
|
||||
video = video.subclip(t_start=15.0, t_end=int(video.duration)-15.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()))
|
||||
# # Trim
|
||||
# # video = video.subclip(t_start=5.0, t_end=int(video.duration)-5.0) before 03.14
|
||||
# video = video.subclip(t_start=15.0, t_end=int(video.duration)-15.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()))
|
||||
# # print(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
|
||||
|
||||
# if fps != 50
|
||||
if video.fps != 50:
|
||||
print("FPS NOT = 50!! ")
|
||||
# # if fps != 50
|
||||
# if video.fps != 50:
|
||||
# print("FPS NOT = 50!! ")
|
||||
|
||||
# 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
|
||||
else:
|
||||
video.write_videofile(str(ipath_video_sub), fps=50, audio=True)
|
||||
print(f"save video > {ipath_video_sub}")
|
||||
# # 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
|
||||
# else:
|
||||
# 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)}")
|
||||
nframes = len(list(video.iter_frames()))
|
||||
# # 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)}")
|
||||
# nframes = len(list(video.iter_frames()))
|
||||
|
||||
|
||||
# get audio
|
||||
audio_sub = video.audio
|
||||
if audio_sub is None:
|
||||
print("\nERROR: audio info is None")
|
||||
# # get audio
|
||||
# audio_sub = video.audio
|
||||
# if audio_sub is None:
|
||||
# print("\nERROR: audio info is None")
|
||||
|
||||
print(f"audio_sub duration = {audio_sub.duration}, fps = {audio_sub.fps}, (start, end)=({audio_sub.start},{audio_sub.end}), nframes={int(audio_sub.duration * audio_sub.fps)}")
|
||||
# print(f"audio_sub duration = {audio_sub.duration}, fps = {audio_sub.fps}, (start, end)=({audio_sub.start},{audio_sub.end}), nframes={int(audio_sub.duration * audio_sub.fps)}")
|
||||
|
||||
# save audio_sub
|
||||
ipath_audio_sub = ipath_audio.joinpath("audio_trim.wav")
|
||||
audio_sub.write_audiofile(str(ipath_audio_sub), fps=audio_sub.fps)
|
||||
print(f"save audio > {ipath_audio_sub}")
|
||||
# # save audio_sub
|
||||
# ipath_audio_sub = ipath_audio.joinpath("audio_trim.wav")
|
||||
# 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")
|
||||
# # # check fps
|
||||
# # if int(video.fps) != 50:
|
||||
# # print(f"\n Skip: fps != 50 realy fps={video.fps}, convert to 50fps")
|
||||
|
||||
# ipath_video_save = ipath_data.joinpath("video", f"video_50fps.mp4")
|
||||
# video.write_videofile(str(ipath_video_save), fps=50.0)
|
||||
# print(f"save video to > {ipath_video_save}...")
|
||||
# # ipath_video_save = ipath_data.joinpath("video", f"video_50fps.mp4")
|
||||
# # video.write_videofile(str(ipath_video_save), fps=50.0)
|
||||
# # print(f"save video to > {ipath_video_save}...")
|
||||
|
||||
# save video feature
|
||||
info = {"nframes": nframes,
|
||||
"fps": video.fps,
|
||||
"width": video.w,
|
||||
"height": video.h}
|
||||
# # save video feature
|
||||
# info = {"nframes": nframes,
|
||||
# "fps": video.fps,
|
||||
# "width": video.w,
|
||||
# "height": video.h}
|
||||
|
||||
with open(str(ipath_infor), 'w+') as f:
|
||||
json.dump(info, f)
|
||||
print(info)
|
||||
print(f"save video info in -> {ipath_infor}\n")
|
||||
# with open(str(ipath_infor), 'w+') as f:
|
||||
# json.dump(info, f)
|
||||
# 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"
|
||||
video.write_images_sequence(ipath_format, fps=50)
|
||||
# # save trim video
|
||||
# print(f"write_images_sequence...")
|
||||
# ipath_format = str(ipath_frame) + "/frame-%06d.jpg"
|
||||
# video.write_images_sequence(ipath_format, fps=50)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ from pathlib import Path
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path("/yrfs/lsen/DATA/Actor2/processing")
|
||||
v_dir_videos = sorted(path_data.glob("*"))
|
||||
# path_data = Path("/mfs/lsen/DATA/Actor2/processing")
|
||||
path_data = Path("/mfs/lsen/DATA/Actor2/happy")
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"), reverse=True)
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@ def landmark_resample_fps(y, source_fps = 30, target_fps=25):
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path("/yrfs/lsen/DATA/Actor2/processing")
|
||||
path_save = Path('data/Actor2/Actor2-raw-7h') # processing
|
||||
# path_data = Path("/mfs/lsen/DATA/Actor2/processing")
|
||||
path_data = Path("/mfs/lsen/DATA/Actor2/happy")
|
||||
|
||||
path_save = Path('data/Actor2/Actor2-happy-1h') # processing
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*/audio/feat_DECA_exp_trim.npy"))
|
||||
@@ -40,22 +42,20 @@ if __name__ == "__main__":
|
||||
vids = set([ipath.stem for ipath in v_dir_videos])
|
||||
# print(f"vids total= {vids}")
|
||||
|
||||
vid_test = set(["AA7A9568", "AA7A9577"])
|
||||
# vid_valid = set(["AA7A9569", "AA7A9578"])
|
||||
vid_train = set(['AA7A9570', 'AA7A9571', 'AA7A9572', 'AA7A9573', 'AA7A9574', 'AA7A9575', 'AA7A9576', 'AA7A9579',
|
||||
'AA7A9580', 'AA7A9582', 'AA7A9583', 'AA7A9584', 'AA7A9585', 'AA7A9600', 'AA7A9601', 'AA7A9602',
|
||||
'AA7A9603', 'AA7A9604', 'AA7A9605', 'AA7A9606', 'AA7A9607', 'AA7A9608', 'AA7A9609', 'AA7A9610',
|
||||
'AA7A9611', 'AA7A9612', 'AA7A9613', 'AA7A9614', 'AA7A9615', 'AA7A9616', 'AA7A9617', 'AA7A9618',
|
||||
'AA7A9619', 'AA7A9620', 'AA7A9621', 'AA7A9622', 'AA7A9623', 'AA7A9625', 'AA7A9626', 'AA7A9627',
|
||||
'AA7A9628'])
|
||||
|
||||
### for processing data
|
||||
# vid_test = set(["AA7A9568", "AA7A9577"])
|
||||
# # vid_valid = set(["AA7A9569", "AA7A9578"])
|
||||
# vid_valid = set(['AA7A9641', 'AA7A9644', 'AA7A9645', 'AA7A9648', 'AA7A9640',
|
||||
# 'AA7A9630', 'AA7A9637', 'AA7A9636', 'AA7A9569', 'AA7A9578',
|
||||
# 'AA7A9632', 'AA7A9638', 'AA7A9651', 'AA7A9647', 'AA7A9643',
|
||||
# 'AA7A9650', 'AA7A9629', 'AA7A9642', 'AA7A9631', 'AA7A9635',
|
||||
# 'AA7A9634'])
|
||||
# vid_train = vids - vid_test - vid_valid
|
||||
vid_valid = vids - vid_test - vid_train
|
||||
|
||||
# vids = set(["2021-P09", "2021-P14", "2021-P22"])
|
||||
# vid_test = set(["2021-P09" ])
|
||||
# vid_valid = set(["2021-P14" ])
|
||||
# vid_train = set(["2021-P22" ])
|
||||
|
||||
|
||||
vid_test = set(["4R3A0004"])
|
||||
vid_valid = set(["4R3A0004"])
|
||||
vid_train = vids - vid_test - vid_valid
|
||||
|
||||
print(f"vid test= {vid_test} \nvalid= {vid_valid}")
|
||||
print(f"vid train= {vid_train}")
|
||||
|
||||
Reference in new issue
Block a user