-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.py
More file actions
106 lines (84 loc) · 2.71 KB
/
encode.py
File metadata and controls
106 lines (84 loc) · 2.71 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#### LIBRARIES ####
### This code assumes you are running under windows environment ###
import subprocess
import glob, os
import shutil
import random
import argparse
#### CLASSES ####
class audioEncode:
ffmpegpath = 'c:/ffmpeg/ffmpeg.exe'
input = '-i c:/ffmpeg/input.wav'
command = [ffmpegpath]
codec = ['aac', 'libmp3lame', 'hi']
def __init__(self, output):
self.output = output
def setCodec(self, codec):
if codec == '1':
self.codec = '-codec:a libmp3lame -qscale:a 1'
elif codec == '2':
self.codec = '-codec:a libmp3lame -qscale:a 2'
elif codec == '3':
self.codec = '-codec:a libmp3lame -qscale:a 3'
elif codec == '4':
self.codec = '-codec:a libmp3lame -qscale:a 4'
elif codec == '5':
self.codec = '-codec:a libmp3lame -qscale:a 5'
elif codec == '6':
self.codec = '-codec:a libmp3lame -qscale:a 6'
elif codec == '7':
self.codec = '-codec:a libmp3lame -qscale:a 7'
elif codec == '8':
self.codec = '-codec:a libmp3lame -qscale:a 8'
elif codec == '9':
self.codec = '-codec:a libmp3lame -qscale:a 9'
elif codec == '0':
self.codec = '-codec:a libmp3lame -qscale:a 0'
elif codec == 'max':
self.codec = '-codec:a libmp3lame -b:a 320k'
def getCodec(self):
return self.code
def setOutput(self, output):
self.output=output
def getOutput(self):
return self.Output
#help
parser=argparse.ArgumentParser(
description='''Convert all *.wav files from a given directory to mp3 lame /n
-b 320 320 320 CBR (non VBR) example -b:a 320k (NB this is 32KB/s, or its max)/n
-V 0 245 220-260 -q:a 0 (NB this is VBR from 22 to 26 KB/s)/n
-V 1 225 190-250 -q:a 1/n
-V 2 190 170-210 -q:a 2/n
-V 3 175 150-195 -q:a 3/n
-V 4 165 140-185 -q:a 4/n
-V 5 130 120-150 -q:a 5/n
-V 6 115 100-130 -q:a 6/n
-V 7 100 80-120 -q:a 7/n
-V 8 85 70-105 -q:a 8/n
-V 9 65 45-85 -q:a 9/n''',
epilog="""***Thank you***""")
#parser.add_argument('--foo', type=int, default=42, help='FOO!')
args=parser.parse_args()
#main
print ("Enter encode 0-9 max")
codec = input()
print ("Enter path for lossless files")
path = input()
#test
test = audioEncode('encode')
#test.setCodec('-codec:a aac')
test.setCodec(codec)
test.setOutput('test')
hi = test.getCodec()
#iterate over directories
os.chdir(path)
for file in glob.glob("*.wav"):
print (file)
mainCommand = test.ffmpegpath+' '+ '-i c:/ffmpeg/'+file +' '+ test.getCodec() + ''+' '+"output.mp3"
#print test.getCodec()
print (test.ffmpegpath+' '+ test.input +' '+ test.getCodec() + '' )
print (mainCommand)
while True:
subprocess.call(mainCommand)
#ffmpeg.exe -i input.wav -codec:a aac output.m4a
#c:/WinExec/ffmpeg.exe -i c:/WinExec/input.wav -codec:a aac output.m4a