2019-03-21 15:26:00 +00:00
|
|
|
"""Transcodes an input video file to ][Vision format."""
|
2019-03-14 21:37:43 +00:00
|
|
|
|
2019-03-21 15:26:00 +00:00
|
|
|
import argparse
|
2019-03-14 21:37:43 +00:00
|
|
|
|
2019-03-21 16:24:40 +00:00
|
|
|
import movie
|
2019-04-25 16:38:04 +00:00
|
|
|
import video
|
2019-01-02 22:16:54 +00:00
|
|
|
|
2019-03-21 15:26:00 +00:00
|
|
|
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.'
|
|
|
|
)
|
2019-03-21 22:43:02 +00:00
|
|
|
parser.add_argument(
|
2019-03-21 23:25:51 +00:00
|
|
|
'--every_n_video_frames', type=int, default=2,
|
2019-03-21 22:43:02 +00:00
|
|
|
help='Allows skipping frames of input video to lower effective output '
|
|
|
|
'frame rate, which may give better quality for some videos.'
|
|
|
|
)
|
2019-04-25 16:38:04 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--video_mode', type=str, choices=video.Mode.__members__.keys(),
|
|
|
|
help='Video display mode to encode for (HGR/DHGR)'
|
|
|
|
)
|
|
|
|
|
2019-03-03 22:21:28 +00:00
|
|
|
|
2019-03-21 15:26:00 +00:00
|
|
|
def main(args):
|
|
|
|
filename = args.input
|
|
|
|
m = movie.Movie(
|
2019-03-21 22:43:02 +00:00
|
|
|
filename,
|
|
|
|
every_n_video_frames=args.every_n_video_frames,
|
2019-03-23 21:46:35 +00:00
|
|
|
audio_normalization=args.audio_normalization,
|
2019-04-25 16:38:04 +00:00
|
|
|
max_bytes_out=1024. * 1024 * args.max_output_mb,
|
|
|
|
video_mode=video.Mode[args.video_mode]
|
2019-03-23 21:46:35 +00:00
|
|
|
)
|
2019-03-10 22:42:31 +00:00
|
|
|
|
2019-03-21 23:25:51 +00:00
|
|
|
print("Input frame rate = %f" % m.video.input_frame_rate)
|
|
|
|
|
2019-03-21 15:26:00 +00:00
|
|
|
if args.output:
|
|
|
|
out_filename = args.output
|
2019-03-14 21:37:43 +00:00
|
|
|
else:
|
2019-03-21 15:26:00 +00:00
|
|
|
# Replace suffix with .a2m
|
2019-03-14 21:37:43 +00:00
|
|
|
out_filename = ".".join(filename.split(".")[:-1] + ["a2m"])
|
2019-01-05 23:31:56 +00:00
|
|
|
|
2019-03-14 21:37:43 +00:00
|
|
|
with open(out_filename, "wb") as out:
|
2019-03-07 23:07:24 +00:00
|
|
|
for bytes_out, b in enumerate(m.emit_stream(m.encode())):
|
2019-03-14 21:45:40 +00:00
|
|
|
out.write(bytearray([b]))
|
2019-03-07 23:07:24 +00:00
|
|
|
|
2019-01-01 21:50:01 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-03-21 15:26:00 +00:00
|
|
|
main(parser.parse_args())
|