1+ #### LIBRARIES ####
2+
3+ import subprocess
4+ import glob , os
5+ import shutil
6+ import random
7+ import argparse
8+
9+ #### CLASSES ####
10+
11+ class audioEncode :
12+ ffmpegpath = 'c:/ffmpeg/ffmpeg.exe'
13+ input = '-i c:/ffmpeg/input.wav'
14+ command = [ffmpegpath ]
15+ codec = ['aac' , 'libmp3lame' , 'hi' ]
16+
17+ def __init__ (self , output ):
18+ self .output = output
19+
20+ def setCodec (self , codec ):
21+ if codec == '1' :
22+ self .codec = '-codec:a libmp3lame -qscale:a 1'
23+ elif codec == '2' :
24+ self .codec = '-codec:a libmp3lame -qscale:a 2'
25+ elif codec == '3' :
26+ self .codec = '-codec:a libmp3lame -qscale:a 3'
27+ elif codec == '4' :
28+ self .codec = '-codec:a libmp3lame -qscale:a 4'
29+ elif codec == '5' :
30+ self .codec = '-codec:a libmp3lame -qscale:a 5'
31+ elif codec == '6' :
32+ self .codec = '-codec:a libmp3lame -qscale:a 6'
33+ elif codec == '7' :
34+ self .codec = '-codec:a libmp3lame -qscale:a 7'
35+ elif codec == '8' :
36+ self .codec = '-codec:a libmp3lame -qscale:a 8'
37+ elif codec == '9' :
38+ self .codec = '-codec:a libmp3lame -qscale:a 9'
39+ elif codec == '0' :
40+ self .codec = '-codec:a libmp3lame -qscale:a 0'
41+ elif codec == 'max' :
42+ self .codec = '-codec:a libmp3lame -b:a 320k'
43+
44+ def getCodec (self ):
45+ return self .codec
46+
47+ def setOutput (self , output ):
48+ self .output = output
49+
50+ def getOutput (self ):
51+ return self .Output
52+
53+ #help
54+ parser = argparse .ArgumentParser (
55+ description = '''Convert all *.wav files from a given directory to mp3 lame /n
56+ -b 320 320 320 CBR (non VBR) example -b:a 320k (NB this is 32KB/s, or its max)/n
57+ -V 0 245 220-260 -q:a 0 (NB this is VBR from 22 to 26 KB/s)/n
58+ -V 1 225 190-250 -q:a 1/n
59+ -V 2 190 170-210 -q:a 2/n
60+ -V 3 175 150-195 -q:a 3/n
61+ -V 4 165 140-185 -q:a 4/n
62+ -V 5 130 120-150 -q:a 5/n
63+ -V 6 115 100-130 -q:a 6/n
64+ -V 7 100 80-120 -q:a 7/n
65+ -V 8 85 70-105 -q:a 8/n
66+ -V 9 65 45-85 -q:a 9/n''' ,
67+ epilog = """***Thank you***""" )
68+ #parser.add_argument('--foo', type=int, default=42, help='FOO!')
69+ args = parser .parse_args ()
70+
71+ #main
72+
73+ print ("Enter encode 0-9 max" )
74+ codec = input ()
75+ print ("Enter path for lossless files" )
76+ path = input ()
77+ #test
78+ test = audioEncode ('encode' )
79+ #test.setCodec('-codec:a aac')
80+ test .setCodec (codec )
81+ test .setOutput ('test' )
82+ hi = test .getCodec ()
83+
84+ #iterate over directories
85+
86+ os .chdir (path )
87+ for file in glob .glob ("*.wav" ):
88+ print (file )
89+ mainCommand = test .ffmpegpath + ' ' + '-i c:/ffmpeg/' + file + ' ' + test .getCodec () + '' + ' ' + "output.mp3"
90+ #print test.getCodec()
91+ print (test .ffmpegpath + ' ' + test .input + ' ' + test .getCodec () + '' )
92+
93+ print (mainCommand )
94+ while True :
95+ subprocess .call (mainCommand )
96+
97+
98+
99+ #ffmpeg.exe -i input.wav -codec:a aac output.m4a
100+
101+ #c:/WinExec/ffmpeg.exe -i c:/WinExec/input.wav -codec:a aac output.m4a
102+
103+
104+
105+
106+
107+
108+
109+
110+
0 commit comments