-
Notifications
You must be signed in to change notification settings - Fork 34
/
prores.py
executable file
·150 lines (127 loc) · 4.73 KB
/
prores.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
import argparse
import subprocess
import sys
import os
from glob import glob
import pdb
import ififuncs
def set_options(args_):
'''
Parse command line options.
'''
parser = argparse.ArgumentParser(description='IFI Pro Res 4:2:2 ffmpeg Encoder.'
' Written by Kieran O\'Leary.')
parser.add_argument('input')
parser.add_argument(
'-hq',
action='store_true',help='-profile:v 3 aka Prores HQ')
parser.add_argument(
'-yadif',
action='store_true',help='Yet Another DeInterlace Filter')
parser.add_argument(
'-wide',
action='store_true',help='Adds 16:9 metadata flag')
parser.add_argument(
'-scale',
help='Rescale video.'
' Usage: -scale 1920x1080 or -scale 720x576 etc')
parser.add_argument(
'-md5',
action='store_true',
help='Get md5 sidecar for your output file')
parser.add_argument(
'-map',
action='store_true',
help='Force default mapping, eg. 1 audio/video stream')
parser.add_argument(
'-o',
help='Set output directory.'
'The default directory is the same as the input directory')
parsed_args = parser.parse_args(args_)
return parsed_args
def main(args_):
'''
Launch the various functions that will make a h264/mp4 access copy.
'''
ififuncs.check_existence(['ffmpeg'])
args = set_options(args_)
prores_options = []
if args.yadif:
prores_options.append('-yadif')
if args.scale:
prores_options.append('-scale')
width_height = args.scale
number_of_effects = len(prores_options)
# Input, either file or firectory, that we want to process.
input = args.input
# Store the directory containing the input file/directory.
wd = os.path.dirname(input)
# Change current working directory to the value stored as "wd"
os.chdir(wd)
# Store the actual file/directory name without the full path.
file_without_path = os.path.basename(input)
# Check if input is a file.
# AFAIK, os.path.isfile only works if full path isn't present.
if os.path.isfile(file_without_path):
video_files = [] # Create empty list
video_files.append(file_without_path) # Add filename to list
# Check if input is a directory.
elif os.path.isdir(file_without_path):
os.chdir(file_without_path)
video_files = (
glob('*.mov') +
glob('*.mp4') +
glob('*.mxf') +
glob('*.mkv') +
glob('*.avi')
)
# Prints some stuff if input isn't a file or directory.
else:
print("Your input isn't a file or a directory.")
for filename in video_files:
#pdb.set_trace()
if args.o:
output = args.o + '/' + os.path.basename(filename) + "_prores.mov"
else:
output = filename + "_prores.mov"
ffmpeg_args = [
'ffmpeg',
'-i', filename,
]
pix_fmt = ififuncs.get_ffmpeg_fmt(filename, 'video')
ffmpeg_args = ['ffmpeg',
'-i', filename,
'-c:a', 'copy',]
if ('rgb' in pix_fmt) or ('gbr' in pix_fmt):
ffmpeg_args.extend(['-c:v', 'prores_ks'])
else:
ffmpeg_args.extend(['-c:v', 'prores'])
if not args.map:
ffmpeg_args.append('-map')
ffmpeg_args.append('0:a?')
ffmpeg_args.append('-map')
ffmpeg_args.append('0:v')
if args.hq:
ffmpeg_args.append('-profile:v')
ffmpeg_args.append('3')
if args.wide:
ffmpeg_args.append('-aspect')
ffmpeg_args.append('16:9')
if args.yadif or args.scale:
filter_options = '-vf'
if args.yadif:
filter_options += ' yadif'
if args.scale:
if number_of_effects > 1:
filter_options += (',scale=%s' % width_height)
else:
filter_options += (' scale=%s' % width_height)
filter_options = filter_options.split()
for item in filter_options:
ffmpeg_args.append(item)
ffmpeg_args.append(output)
print(ffmpeg_args)
subprocess.call(ffmpeg_args)
if __name__ == "__main__":
main(sys.argv[1:])