-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplexify.py
More file actions
57 lines (44 loc) · 1.86 KB
/
Copy pathplexify.py
File metadata and controls
57 lines (44 loc) · 1.86 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
from optparse import OptionParser
from pymediainfo import MediaInfo
import subprocess
import os
import ntpath
parser = OptionParser()
parser.add_option("-i", "--input_dir", dest="input_dir", help="Input dir with mkv files to be encoded", metavar="FILE")
parser.add_option("-o", "--output_dir", dest="output_dir", help="Output dir for encoded video", metavar="FILE", default=".")
(options, args) = parser.parse_args()
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
def change_ext(filename, new_ext):
return os.path.splitext(filename)[0]+new_ext
def encode_video(filename, output_dir):
media_info = MediaInfo.parse(filename)
for track in media_info.tracks:
if track.track_type == 'Video':
height = track.height
width = track.width
print "%s dimensions are %sx%s" % (filename, height, width)
basename=path_leaf(filename)
print("Filename is %s" % (basename))
output_file=os.path.join(output_dir, change_ext(basename, ".mp4"))
subprocess.call(["HandBrakeCLI",
"-N", "eng",
"-l", str(height),
"-w", str(width),
"-o", str(output_file),
"-i", str(filename),
"-e", "x264",
"-q", "20",
"--crop", "0:0:0:0",
"--loose-anamorphic",
"-O"])
output_dir_files = []
for filename in os.listdir(options.output_dir):
if filename.endswith(".mp4"):
output_dir_files.append(filename)
for filename in os.listdir(options.input_dir):
if filename.endswith(".mkv"):
if change_ext(filename, ".mp4") not in output_dir_files:
print("Haven't yet encoded %s so doing so now" % (filename))
encode_video(os.path.join(options.input_dir,filename), options.output_dir)