-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode_videos.py
executable file
·42 lines (32 loc) · 1.02 KB
/
encode_videos.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
#!/usr/bin/env python3
import os
import subprocess
import sys
EXTENSIONS = [
'.avi',
'.mkv',
'.mov',
'.mp4'
]
TARGET_SUF = '_E'
TARGET_EXT = '.MP4'
if(len(sys.argv) < 2):
sys.exit('Directory argument is misssing!')
if(not os.path.exists(sys.argv[1])):
sys.exit('Directory does not exist: {}'.format(sys.argv[1]))
for root, _, files in os.walk(sys.argv[1]):
for fn in files:
file_name = os.path.join(root, fn)
fn_woext, extension = os.path.splitext(file_name)
if (extension.lower() not in EXTENSIONS):
print('Skipping file: {}'.format(file_name))
continue
fn_out = '{}{}{}'.format(fn_woext, TARGET_SUF, TARGET_EXT)
if(os.path.exists(fn_out)):
print('File exists: {}'.format(fn_out))
continue
print('Encoding \"{}\" to \"{}\"'.format(file_name, fn_out))
subprocess.run(
['ffmpeg', '-i', file_name, fn_out],
capture_output=True
)