initial commit
This commit is contained in:
commit
c7175dd7ff
127 files changed
+13949
No files matched your search
@@ -0,0 +1,143 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
UNZIP_FILES = False
|
||||
MV_AUDIO_FILES = False
|
||||
MV_VIDEO_FILES = False
|
||||
EXTRACT_AUDIO = True
|
||||
|
||||
total_pid = ["s1.", "s2.", "s3.", "s4.", "s5.", "s6.", "s7.", "s8.", "s9.", "s10." ]
|
||||
# total_pid = [ "s6.", "s7.", "s8.", "s9.", "s21."]
|
||||
|
||||
def is_exist_pid(file_name):
|
||||
for iid in total_pid:
|
||||
if str(iid) in str(file_name.name):
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
path_root = Path("/yrfs/lsen/DATA/GRID/")
|
||||
|
||||
if UNZIP_FILES:
|
||||
path_zip = path_root.joinpath("zip_data")
|
||||
path_data = path_root.joinpath("unzip_data")
|
||||
path_data.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
v_zip_files = sorted(path_zip.glob("./*.tar"))
|
||||
|
||||
print(f"Have {len(v_zip_files)} zip files, \n {v_zip_files[:10]}")
|
||||
|
||||
|
||||
for i, izip in enumerate(v_zip_files):
|
||||
|
||||
if not is_exist_pid(izip): continue
|
||||
|
||||
ipath_data = path_data.joinpath(str(izip.stem))
|
||||
|
||||
# if not ipath_data.exists():
|
||||
cmd = f"cd {str(path_zip)}; tar -xf {str(izip)} -C {str(path_data)}"
|
||||
print(f"RUN: {cmd}")
|
||||
os.system(cmd)
|
||||
|
||||
#break
|
||||
|
||||
if MV_AUDIO_FILES:
|
||||
path_unzip = path_root.joinpath("unzip_data")
|
||||
v_ids_file = sorted(path_unzip.glob("*"))
|
||||
|
||||
print(f"Have {len(v_ids_file)} persons files, \n {v_ids_file[:10]}")
|
||||
|
||||
for i, iid in enumerate(v_ids_file):
|
||||
cmd = f"cd {str(iid)}; mkdir audio; mv *.wav audio"
|
||||
print(f"RUN: {cmd}")
|
||||
os.system(cmd)
|
||||
|
||||
#break
|
||||
|
||||
if MV_VIDEO_FILES:
|
||||
path_data = path_root.joinpath("unzip_data")
|
||||
v_ids = sorted(path_data.glob("*"))
|
||||
|
||||
print(f"Have {len(v_ids)} dir files, \n {v_ids[:10]}")
|
||||
|
||||
# for each person
|
||||
for i, ipath_id in enumerate(v_ids):
|
||||
id_name = ipath_id.stem
|
||||
|
||||
dir_video = path_data.joinpath(id_name, "video/mpg_6000")
|
||||
v_dir_videos = sorted(dir_video.glob("*.mpg"))
|
||||
|
||||
print(f"\nid= {id_name}, Have {len(v_dir_videos)} video files, \n {v_dir_videos[:10]}")
|
||||
|
||||
# for each video
|
||||
for ipath_videos in v_dir_videos:
|
||||
ivideo_name = ipath_videos.stem
|
||||
|
||||
# copy video
|
||||
ipath_video_target = path_root.joinpath("processing", id_name, ivideo_name, "video/video_orignal.mp4")
|
||||
|
||||
if not ipath_video_target.exists():
|
||||
ipath_video_target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(src=str(ipath_videos), dst=str(ipath_video_target))
|
||||
#print(f"copy {ipath_videos} --> {ipath_video_target}")
|
||||
|
||||
# # copy audio
|
||||
# ipath_audio_source = path_data.joinpath(id_name, f"audio/{ivideo_name}.wav")
|
||||
# ipath_audio_target = path_root.joinpath("processing", id_name, ivideo_name, "audio/audio_orignal.wav")
|
||||
|
||||
# if not ipath_audio_target.exists():
|
||||
# ipath_audio_target.parent.mkdir(parents=True, exist_ok=True)
|
||||
# shutil.copy(src=str(ipath_audio_source), dst=str(ipath_audio_target))
|
||||
# #print(f"copy {ipath_audio_source} --> {ipath_audio_target}")
|
||||
|
||||
# break
|
||||
|
||||
if EXTRACT_AUDIO:
|
||||
|
||||
path_data = path_root.joinpath("processing")
|
||||
|
||||
vpath_ids = sorted(path_data.glob("*"))
|
||||
print(f"Have {len(vpath_ids)} person folders --> {vpath_ids[0]}")
|
||||
|
||||
for i, ipath_id in enumerate(vpath_ids):
|
||||
pid = ipath_id.stem # person id
|
||||
|
||||
# if pid in ["s1", "s10", "s11", "s12", "s13", "s14"]:
|
||||
# continue
|
||||
|
||||
# video
|
||||
vpath_videos = sorted(ipath_id.glob("*/video/video_orignal.mp4"))
|
||||
print(f"\nid= {pid}, Have {len(vpath_videos)} video files, --> {vpath_videos[0]}")
|
||||
|
||||
# for each video
|
||||
list_dict = []
|
||||
for iv, ipath_video in enumerate(vpath_videos):
|
||||
vid = ipath_video.parent.parent.stem # video id
|
||||
|
||||
if iv % 50 == 0:
|
||||
print(f"--> processing the {iv}-th video --> {ipath_video}")
|
||||
|
||||
ipath_audio = ipath_video.parent.parent.joinpath("audio/audio_extract.wav")
|
||||
ipath_audio.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if ipath_audio.exists():
|
||||
continue
|
||||
|
||||
# extract audio
|
||||
cmd = f'ffmpeg -y -i {str(ipath_video)} -vn -acodec pcm_s16le -ac 1 -ar 16000 {str(ipath_audio)}'
|
||||
# print(f"RUN: {cmd}")
|
||||
os.system(cmd)
|
||||
|
||||
# break
|
||||
#break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user