Source code for cgl.core.utils.amc_batch_extract_wav
import glob
import os
import re
import subprocess
import sys
from cgl.core.utils.general import load_json, save_json
MATCH = r".+/0000/amc/default/.+[.]mp4"
[docs]
def find_msd(dir_path):
files = []
for glob_str in ("*.msd",):
g = glob.glob(f"{dir_path}/{glob_str}") or []
files.extend(g)
if files:
return files[0]
return None
[docs]
def update_msd_json(wav_file_path):
msd_path = find_msd(os.path.dirname(wav_file_path))
if not msd_path:
return
data = load_json(msd_path)
render_files = data.get('render_files', {})
render_files['.wav'] = wav_file_path.replace("Z:/prod/", "")
data['render_files'] = render_files
save_json(msd_path, data)
[docs]
def amc_batch_extract_wav(root_path):
media = []
# print(MATCH)
for root, dirs, files in os.walk(root_path, topdown=False):
for name in files:
path = os.path.join(root, name)
path = path.replace("\\", '/')
m = re.match(MATCH, path)
if m:
if path.count(".preview"):
continue
print(path)
media.append(path)
for mp4_file in media:
name, _ = os.path.splitext(mp4_file)
wav_file = f"{name}.wav"
if os.path.exists(wav_file):
continue
cmd = ['ffmpeg', '-y', '-i', mp4_file, '-acodec', 'pcm_s16le', '-ac', '2', wav_file]
print(subprocess.list2cmdline(cmd))
subprocess.check_call(cmd)
update_msd_json(wav_file)
if __name__ == "__main__":
root_path = sys.argv[1]
amc_batch_extract_wav(root_path)