Commit 64f5dd51 authored by Marc's avatar Marc
Browse files

Typing and nice output

parent 0b884a2f
......@@ -5,31 +5,30 @@ import sys
def change_frame_rate(input_file: str, output_file: str, framerate: int, raw_path: str, h264_path: str,
output_path: str):
output_path: str) -> None:
basename = input_file[0:-4]
input_file = os.path.join(raw_path, input_file)
h264 = os.path.join(h264_path, "%s.h264" % basename)
if not os.path.exists(h264):
print("\033[1;34mGenerating \033[0m%s\033[1;34m -> \033[0m%s" % (input_file, h264))
lib.run(["ffmpeg", "-y", "-i", input_file, "-c", "copy", "-f", "h264", h264],
check=True)
else:
print("\033[32mSkipping h264 generation \033[0m%s" % h264)
output_file = os.path.join(output_path, output_file)
if not os.path.exists(output_file):
print("\033[1;34mGenerating \033[0m%s\033[1;34m -> \033[0m%s" % (h264, output_file))
lib.run(["ffmpeg", "-y", "-r", str(framerate), "-i", h264, "-c", "copy", output_file],
check=True)
if not os.path.exists(h264):
print("\033[1;34mExtracting raw bitstream \033[0m%s\033[1;34m -> \033[0m%s" % (input_file, h264))
lib.run(["ffmpeg", "-y", "-i", input_file, "-c", "copy", "-f", "h264", h264],
check=True)
else:
print("\033[32mSkipping h264 generation \033[0m%s" % h264)
print("\033[1;34mRemuxing \033[0m%s\033[1;34m -> \033[0m%s" % (h264, output_file))
lib.run(["ffmpeg", "-y", "-r", str(framerate), "-i", h264, "-c", "copy", output_file], check=True)
else:
print("\033[32mSkipping frame rate adaptation \033[0m%s" % output_file)
def display_usage():
def display_usage() -> None:
print("%s input_file output_file framerate" % sys.argv[0])
def main():
def main() -> None:
if len(sys.argv) != 4:
display_usage()
exit(0)
......
......@@ -4,14 +4,15 @@ import typing
def concat(slow_path: str, filelist_path: str, concat_path: str,
groups: typing.Dict[str, typing.Union[typing.List[str], str]]):
groups: typing.Dict[str, typing.Union[typing.List[str], str]]) -> None:
for group_name in groups:
output_path = os.path.join(concat_path, "%s.mp4" % group_name)
if isinstance(groups[group_name], list):
groups[group_name].sort()
if not os.path.isfile(output_path):
list_file_name = "%s/%s.txt" % (filelist_path, group_name)
print("\033[1;34mConcatenating \033[0m%s\033[1;34m -> \033[0m%s" % (str(list_file_name), output_path))
print("\033[1;34mConcatenating (%d) \033[0m%s\033[1;34m -> \033[0m%s" %
(len(groups[group_name]), " ".join(map(lambda x: os.path.join(slow_path, x), groups[group_name])), output_path))
with open(list_file_name, 'w') as f:
f.write("# Autogenerated. Group: %s, files: %s\n" % (group_name, str(groups[group_name])))
for file in groups[group_name]:
......@@ -22,8 +23,9 @@ def concat(slow_path: str, filelist_path: str, concat_path: str,
else:
print("\033[32mSkipping concatenation \033[0m%s" % output_path)
else:
input_path = os.path.join(slow_path, groups[group_name])
if not os.path.isfile(output_path):
print("\033[1;34mCopying \033[0m%s" % group_name)
lib.run(["cp", os.path.join(slow_path, groups[group_name]), output_path])
print("\033[1;34mCopying \033[0m %s\033[1;34m -> \033[0m%s" % (input_path, output_path))
lib.run(["cp", input_path, output_path])
else:
print("\033[32mSkipping copy \033[0m%s" % output_path)
print("\033[32mSkipping copy \033[0m%s" % input_path)
import typing
import subprocess
from functools import reduce
dry_run = False
quiet = True
verbose = False
def run(*args, **kwargs):
class SizeTree:
def __init__(self, x):
self.leaf = isinstance(x, int)
self.content = x
def is_leaf(self) -> bool:
return self.leaf
def merge(self, other):
def aux(lhs: typing.List[SizeTree], rhs: typing.List[SizeTree]) -> typing.List[SizeTree]:
if not lhs:
return rhs
elif not rhs:
return lhs
else:
return [lhs[0].merge(rhs[0])] + aux(lhs[1:], rhs[1:])
if self.is_leaf() and other.is_leaf():
return SizeTree(max(self.content, other.content))
elif self.is_leaf():
q = self.content
(l, p) = other.content
return SizeTree((l, max(p, q)))
elif other.is_leaf():
q = other.content
(l, p) = self.content
return SizeTree((l, max(p, q)))
else:
(l, p) = self.content
(m, q) = other.content
a = aux(l, m)
return SizeTree((a, max(p, q, reduce(lambda y, x: y + (x.content if x.leaf() else x.content[1]), a, 0))))
class PrintTree:
def __init__(self, x):
self.leaf = isinstance(x, str)
self.content = x
def is_leaf(self) -> bool:
return self.leaf
def __len__(self) -> SizeTree:
if self.leaf:
return SizeTree(len(self.content))
else:
size_l = map(len, self.content)
return SizeTree((size_l, reduce(lambda a, x: a + (x.content if x.leaf() else x.content[1]), size_l, 0)))
def print_tree_with_size(self, size: SizeTree) -> str:
if self.is_leaf() and size.is_leaf():
d = max(size.content - len(self.content))
return self.content + (' '*d)
elif self.is_leaf():
d = max(size.content[1] - len(self.content))
return self.content + (' '*d)
elif size.is_leaf():
raise Exception("print_tree_with_size: string sub-tree with no size sub-tree")
else:
def aux(a, b):
if not a:
return ""
elif not b:
raise Exception("print_tree_with_size: pattern inconsistent with string tree")
else:
t1 = a[0]
q1 = a[1:]
t2 = b[0]
q2 = b[1:]
a = t1.print_tree_with_size(t2)
c = aux(q1, q2)
return a + c
l = self.content[0]
m, n = size.content
s = aux(l, m)
d = max(n - len(s), 0)
s + (' '*d)
def run(*args, **kwargs) -> None:
if dry_run:
print(args, kwargs)
else:
......
......@@ -12,7 +12,7 @@ concat_path = "../concat"
slow_rate = 18
def main():
def main() -> None:
file_list = generate_file_lists.get_all_filenames(raw_path)
for file in file_list:
basename = generate_file_lists.keep_base_name(file)
......@@ -29,13 +29,14 @@ def main():
for (i, e) in enumerate(v):
lens[i] = max(lens.get(i, 0), len(e))
print("\033[1;94mDetected groups: \033[0m")
print("\033[1;95mDetected groups: \033[0m")
for (k, v) in groups.items():
k = "%s%s " % (k, ' '*(key_len - len(k)))
if isinstance(v, str):
k = "%s%s " % (k, ' '*(key_len - len(k)))
v_s = v
print(" \033[2;96m%s:\033[0m %s" % (k, v_s))
elif isinstance(v, list):
k = "%s%s (%d) " % (k, ' '*(key_len - len(k)), len(v))
v_s = "%s%s" % (v[0], ' '*(lens[0]-len(v[0])))
for (i, e) in enumerate(v[1:]):
v_s = "%s %s%s" % (v_s, e, ' ' * (lens[i+1] - len(e)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment