ii-vision/transcoder/main.py
kris fd49736b71 FrameSequencer:
- Extract out a (File)FrameSequencer class from Video to encapsulate
the generation of still frames.  This also makes Video easier to test.

- Fix FileFrameSequencer.frames() to correctly handle filenames
  containing '.'

- Temporarily switch to the BMP2DHR NTSC palette (#5) for evaluation.

Video:
- Temporarily hardcode DHGR decoding

- Optimize _heapify_priorities() by using numpy to vectorize the
  construction of the list of tuples.  This requires changing the
  random nonce to an int so the intermediate array has a uniform type.

- Use the efficient 28-bit representation of DHGR (aux, main, aux,
  main) tuples introduced in DHGRBitmap to evaluate diffs

- Switch to np.int type for accumulating diffs, and random.randint(0,
  10000) instead of float for nonce values.

- Fix/improve some of the error evaluation in _index_changes:
  - skip offsets whose diffs have already been cleared
  - hoist some stuff out of _compute_error into the parent

- Add some validation that when we run out of work to do with a frame,
  the source and target memory maps should be equal.  This isn't
  happening sometimes, i.e. there is a bug.
2019-06-19 22:02:13 +01:00

58 lines
1.7 KiB
Python

"""Transcodes an input video file to ][Vision format."""
import argparse
import movie
import video
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.__members__.keys(),
help='Video display mode to encode for (HGR/DHGR)'
)
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[args.video_mode]
)
print("Input frame rate = %f" % m.frame_sequencer.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())