ii-vision/transcoder/main.py
kris f3d03a1b87 Update comments and fix some bugs
make_edit_distance
- use MASKED_DOTS since it does not have a simple relationship to the
  HEADER_BITS/BODY_BITS for HGR
- try disabling transposition distances for Damerau-Levenshtein, this
  may give better quality

screen
- introduce separate notion of MASKED_DOTS which is the number of
  (coloured) pixels we can extract from MASKED_BITS.  For HGR this is
  not the same.
- fix bug in _fix_array_neighbours that was not fixing headers for HGR
- don't cache everything in byte_pair_differences, it's effectively
  unbounded.  Using 1M for LRU size seems to work just as well in
  practise, without leaking memory.
- fix bug in _diff_weights when comparing content, we want to evaluate
  the effect of storing content byte in each offset separately, not
  cumulatively.
- add a consistency check function (not currently wired up) to assert
  that headers/footers are in sync across columns
- HGR should have 16 body bits, this was causing headers not to
  propagate correctly to/from neighbouring column
- add test case for this bug

video
- Use 8 random bits consistently, using 16 in some places may have
  introduced bias
- ignore palette bit when comparing 0x00 and 0x7f in sanity check
2019-07-11 23:40:00 +01:00

68 lines
2.0 KiB
Python

"""Transcodes an input video file to ][-Vision format."""
import argparse
import movie
import palette
import video_mode
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.'
)
parser.add_argument(
'--every_n_video_frames', type=int, default=2,
help='Allows skipping frames of input video to lower effective output '
'frame rate, which may give better quality for some videos.'
)
parser.add_argument(
'--video_mode', type=str, choices=video_mode.VideoMode.__members__.keys(),
default=video_mode.VideoMode.DHGR.name,
help='Video display mode to encode for (HGR/DHGR)'
)
parser.add_argument(
'--palette', type=str, choices=palette.Palette.__members__.keys(),
default=palette.Palette.NTSC.name,
help='Video palette to encode for (default=NTSC)'
)
def main(args):
filename = args.input
m = movie.Movie(
filename,
every_n_video_frames=args.every_n_video_frames,
audio_normalization=args.audio_normalization,
max_bytes_out=1024. * 1024 * args.max_output_mb,
video_mode=video_mode.VideoMode[args.video_mode],
palette=palette.Palette[args.palette],
)
print("Palette %s" % args.palette)
print("Input frame rate = %f" % m.frame_grabber.input_frame_rate)
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 __name__ == "__main__":
main(parser.parse_args())