forked from kieranjol/IFIscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prores.py
116 lines (94 loc) · 3.36 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
#!/usr/bin/env python
import argparse
import subprocess
import sys
import os
from glob import glob
import pdb
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(
'-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')
args = parser.parse_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()
output = filename + "_prores.mov"
ffmpeg_args = ['ffmpeg',
'-i', filename,
'-c:a', 'copy',
'-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.yadif or args.scale:
filter_options = '-vf'
if args.yadif:
print 'YADIF'
filter_options += ' yadif'
if args.scale:
print '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)