-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg_webp2png.py
54 lines (46 loc) · 1.79 KB
/
ffmpeg_webp2png.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Version 1.0
"""
import concurrent.futures, os, sys
class ConvertThread(object):
def __init__(self, workpath):
self.workpath = workpath
def find_dirs(self, directory):
for r, Dirs, File, in os.walk(directory):
yield r
for F in File:
yield os.path.join(r, F)
def work(self):
for Files2 in self.find_dirs(self.workpath):
if os.path.exists(os.path.dirname(Files2)):
os.chdir(os.path.dirname(Files2))
else:
os.chdir(os.path.dirname(os.path.abspath(Files2)))
concurrent.futures.ThreadPoolExecutor(os.cpu_count() * 9999).submit(self.convert, Files2.split('/')[-1]).result()
os.chdir(self.workpath)
print('\nConverting Done!')
def convert(self, fname):
if fname.split('.')[-1].lower() == 'webp':
os.system('ffmpeg -i "{}" -hide_banner -y -vf scale=iw:ih -vcodec png "{}"'.format(fname, '{}.png'.format(fname.split('.webp')[0])))
try:
os.remove(fname)
except:
print('Error! Old File Not Removed!')
def main():
try:
if sys.argv[1] == '-h':
print('{} [input_directory]'.format(sys.argv[0].split('/')[-1]))
sys.exit(0)
elif sys.argv[1] == '--help':
print('{} [input_directory]'.format(sys.argv[0].split('/')[-1]))
sys.exit(0)
except IndexError:
print('{} [input_directory]'.format(sys.argv[0].split('/')[-1]))
sys.exit(0)
os.chdir('{}'.format(sys.argv[1]))
print('converting......')
concurrent.futures.ThreadPoolExecutor(os.cpu_count() * 999999999999999999).submit(ConvertThread(os.getcwd()).work).result()
if __name__ == '__main__':
main()