forked from tyiannak/pyAudioAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertToWav.py
29 lines (24 loc) · 1021 Bytes
/
convertToWav.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
# USAGE:
# convertToWav <folder path> <sampling rate> <number of channels>
#
import glob, sys, os
def getVideoFilesFromFolder(dirPath):
types = (dirPath+os.sep+'*.avi', dirPath+os.sep+'*.mkv', dirPath+os.sep+'*.mp4', dirPath+os.sep+'*.mp3', dirPath+os.sep+'*.flac', dirPath+os.sep+'*.mov') # the tuple of file types
files_grabbed = []
for files in types:
files_grabbed.extend(glob.glob(files))
return files_grabbed
def main(argv):
if (len(argv)==4):
files = getVideoFilesFromFolder(argv[1])
samplingRate = int(argv[2])
channels = int(argv[3])
for f in files:
try:
ffmpegString = 'ffmpeg -i ' + '\"' + f + '\"' + ' -ar ' + str(samplingRate) + ' -ac ' + str(channels) + ' ' + '\"' + os.path.splitext(f)[0] + '\"' + '.wav'
os.system(ffmpegString)
except:
ffmpegString = 'avconv -i ' + '\"' + f + '\"' + ' -ar ' + str(samplingRate) + ' -ac ' + str(channels) + ' ' + '\"' + os.path.splitext(f)[0] + '\"' + '.wav'
os.system(ffmpegString)
if __name__ == '__main__':
main(sys.argv)