-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_shotmask.py
128 lines (109 loc) · 4.25 KB
/
add_shotmask.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
# run in a folder with .mp4 files like this: python W:\04_PersonalProjects\Chris\00_Miniprojects\editbot\add_shotmask.py -i . -o ./output -p Animation -fps 30
from editbot_main import *
import os, copy, argparse
ffmpeg_bin=r"C:\Program Files\ffmpeg\bin\ffmpeg.exe"
ffprobe_bin=r"C:\Program Files\ffmpeg\bin\ffprobe.exe"
def build_edit(
name,
folder,
pass_name,
video_filename,
edit_output_path,
edit_output_name,
logo_path,
fps,
studio_name = None,
director_name =None,
subfolders = False,
):
base_config = Config(
ffmpeg_bin=ffmpeg_bin,
ffprobe_bin=ffprobe_bin,
studio_name = studio_name,
director_name =director_name,
name=name,
default_pass_name=pass_name,
enable_shotmask=True,
shot_mask_logo_path=logo_path,
clip_frame_handles=0,
fps=fps
)
# build location
storageLocation = Location(name='root', folder=folder)
storageLocation.addSublocation(Location(name=pass_name, folder=folder, priority=7, subfolders_only=subfolders))
anim_config = copy.deepcopy(base_config)
anim_config.force_pass = True,
# anim_config.default_pass_name = 'Style_Test'
animEdit = Edit(
config=anim_config,
source_folder=storageLocation,
# frameoffset = 30*5, # 5 seconds slate
)
#custom edit
footage_clip = Clip(
config=anim_config,
name = os.path.splitext(os.path.basename(video_filename))[0],
# frame_handles_in=5,
in_frame = 0,
duration= 0,
# pass_name='Layout'
)
footage_clip.findFootage(storageLocation)
footage_clip.getFrameRate()
footage_clip.getDuration()
animEdit.addClip(footage_clip)
edits = [animEdit]
for edit in edits:
edit.conformEdit(mode='in_frame')
edit.preconvertClips()
print("Building edit:")
[print(f" {editclip.name}") for editclip in edit.edit]
result_path = edit.build(os.path.join(edit_output_path, edit_output_name))
print(f"Edit saved to: {result_path}")
edit.cleanup()
def list_video_files_in_folder(foldername, ext=".mp4"):
video_files = []
folder_list = os.listdir(foldername)
for vf in [os.path.join(foldername, filename) for filename in folder_list]:
if os.path.isfile(vf) and vf.endswith(ext):
video_files.append(vf)
return video_files
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog='Automatic Shotmask Renderer',
description='Renders a shotmask with shot name and framecounter and some other information onto all videofiles in a folder')
parser.add_argument("--inputfolder", "-i", type=str, required=True)
parser.add_argument("--outputfolder", "-o", type=str, required=True)
parser.add_argument("--pass_name", "-p", type=str, default="")
parser.add_argument("--frames_per_second", "-fps", type=int, default=24)
parser.add_argument("--studio_name", "-n:s", type=str, default="")
parser.add_argument("--director_name", "-n:d", default="")
parser.add_argument("--name", "-n", type=str, default="")
args = parser.parse_args()
folder = args.inputfolder
edit_output_path= args.outputfolder
out_fps = args.frames_per_second
studio_name = args.studio_name
director_name = args.director_name
name = args.name
pass_name = args.pass_name
if not os.path.exists(edit_output_path):
print(f"Outputfolder did not exist, creating {os.path.abspath(edit_output_path)}")
os.mkdir(os.path.abspath(edit_output_path))
for videofile in list_video_files_in_folder(folder):
edit_output_name=f"{os.path.splitext(os.path.basename(videofile))[0]}_shotmask.mp4"
# print(videofile)
# print(edit_output_name)
# print(edit_output_path)
build_edit(
video_filename = videofile,
edit_output_path=edit_output_path,
edit_output_name=edit_output_name,
studio_name=studio_name,
director_name=director_name,
name = name,
pass_name = pass_name,
folder = folder,
logo_path=os.path.join(os.path.dirname(__file__),"res","ta_logo_new.png"),
fps=out_fps
)