mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2024-12-21 05:30:20 +00:00
Switch to argparse and parametrize some flags
This commit is contained in:
parent
0a9e83fa22
commit
c53cf76df0
39
main.py
39
main.py
@ -1,33 +1,48 @@
|
||||
"""Transcodes an input video file to Apple II format."""
|
||||
"""Transcodes an input video file to ][Vision format."""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
import movie
|
||||
|
||||
MAX_OUT = 100 * 1024 * 1024
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Transcode videos to ][Vision format.')
|
||||
parser.add_argument(
|
||||
'input', help='Path to input video file.')
|
||||
parser.add_argument(
|
||||
'--output', default=None, help='Path to output video file.')
|
||||
parser.add_argument(
|
||||
'--max_output_mb', type=float, default=0,
|
||||
help='Maximum number of MB to output (0 = Unlimited).'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--audio_normalization', type=float, default=None,
|
||||
help='Override auto-detected multiplier for audio normalization.'
|
||||
)
|
||||
|
||||
|
||||
# TODO: flags
|
||||
# - max out
|
||||
def main(args):
|
||||
filename = args.input
|
||||
m = movie.Movie(
|
||||
filename, audio_normalization=args.audio_normalization)
|
||||
|
||||
def main(argv):
|
||||
filename = argv[1]
|
||||
m = movie.Movie(filename)
|
||||
max_bytes_out = 1024. * 1024 * args.max_output_mb
|
||||
|
||||
if len(argv) >= 3:
|
||||
out_filename = argv[2]
|
||||
if args.output:
|
||||
out_filename = args.output
|
||||
else:
|
||||
# Replace suffix with .a2m
|
||||
out_filename = ".".join(filename.split(".")[:-1] + ["a2m"])
|
||||
|
||||
with open(out_filename, "wb") as out:
|
||||
for bytes_out, b in enumerate(m.emit_stream(m.encode())):
|
||||
out.write(bytearray([b]))
|
||||
|
||||
if bytes_out >= MAX_OUT:
|
||||
if max_bytes_out and bytes_out >= max_bytes_out:
|
||||
break
|
||||
|
||||
out.write(bytes(m.done()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
main(parser.parse_args())
|
||||
|
Loading…
Reference in New Issue
Block a user