forked from hche11/VGGSound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_audio.py
41 lines (36 loc) · 902 Bytes
/
preprocess_audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import glob
import multiprocessing
import subprocess
import os
import argparse
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
'--video_input',
default='',
type=str,
help='Input directory path of videos or audios')
parser.add_argument(
'--audio_output',
default='',
type=str,
help='Output directory path of videos')
return parser.parse_args()
def convert(v):
subprocess.check_call([
'ffmpeg',
'-n',
'-i', v,
'-acodec', 'pcm_s16le',
'-ac','1',
'-ar','16000',
args.audio_output + '%s.wav' % v.split('/')[-1][:-4]])
def obtain_list():
files = []
txt = glob.glob(args.video_input + '/*.mp4') # '/*.flac'
for item in txt:
files.append(item)
return files
args = get_arguments()
p = multiprocessing.Pool(32)
p.map(convert, obtain_list())