Skip to content

Adapt video to the current terminal size #32

Description

@vxgmichel

There have been ongoing discussions about adapting the video to the current terminal size:

In particular, @jquast proposes the use of sextants and octants that respectively reduce the video size to 80x48 and 80x36 terminal characters.

There is also another approach that I quickly implemented here: c2caf7d
It uses PIL.image.thumbnail to scale the video buffer down to a size that fits within the current terminal size. It uses the NEAREST scaling method by default, but F1 can be used at runtime to cycle the scaling methods.

scale-to-term.mp4

Both approach have their merits:

  • The sextants approach has higher fidelity (only a small fraction of the pixels are rendered with the wrong color), but it jumps from sextants to half blocks with nothing in between, and the aspect ratio is not preserved
  • The thumbnail approach smoothly scales the video, but more information is lost during the process (as it changes the size in pixels). Also Pillow is a pretty big wheel (about 6MB), so that would probably mean re-write the scaling code in a cython extension rather than depending on Pillow.

What I would like to experiment next is a hybrid approach: if we consider that the proper aspect ratio is given by the fact that a terminal character is 1:2, then we could squeeze the 160x144 pixels in a video frame to a160x108 pixel image, that we can then blit using sextants. That means we'll get 80x36 terminal characters, exactly like we would with octants, achieving the same aspect ratio as the current implementation. Similarly, we can stretch the frame into a 214x144 pixel image, for a sextants result of 107x48 terminal characters.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions