Skip to content

Commit 35be816

Browse files
vo_chafa: initial commit
vo_chafa: get term_info during preinit vo_chafa: set cell geometry on chafa canvas to fix sixel pixel mode vo_chafa: get terminfo using default term_db vo_chafa: change dither-mode option to dither for consitency vo_chafa: add support for more image formats vo_chafa: fix comments vo_chafa: use mp_tprintf for pos_buf instead of snprintf vo_chafa: remove header for libswscale DOCS/main/vo.rst: remove explicit mentions of terminals in the `vo_chafa` docs vo_chafa: use chafa_calc_canvas_geometry to get width and height in cells of chafa canvas
1 parent 266cb79 commit 35be816

5 files changed

Lines changed: 672 additions & 0 deletions

File tree

DOCS/man/vo.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,108 @@ Available video output drivers are:
578578
in some terminals (``xterm``). The default (-1) will choose a palette
579579
on every frame and will have better quality.
580580

581+
``chafa``
582+
Graphical output for the terminal, using chafa.
583+
584+
Note: the image output is not synchronized with other terminal
585+
output from mpv, which can lead to broken images.
586+
The option ``--really-quiet`` can help with that, and is recommended.
587+
588+
You may need to use ``--profile=sw-fast`` to get decent performance.
589+
590+
When the pixel mode is set to ``sixels``, chafa has the same caveats that the
591+
``sixel`` VO has. See those.
592+
593+
Sixel size and alignment options:
594+
595+
``--vo-chafa-cols=<columns>``, ``--vo-chafa-rows=<rows>`` (default: 0)
596+
Specify the terminal size in character cells, otherwise (0) read it
597+
from the terminal, or fall back to 80x25. Note that mpv doesn't use the
598+
the last row with chafa because this seems to result in scrolling.
599+
600+
``--vo-chafa-width=<width>``, ``--vo-chafa-height=<height>`` (default: 0)
601+
Specify the available size in pixels, otherwise (0) read it from the
602+
terminal, or fall back to 320x240. Other than excluding the last line,
603+
the height is also further rounded down to a multiple of 6 (chafa unit
604+
height) to avoid overflowing below the designated size.
605+
606+
``--vo-chafa-left=<col>``, ``--vo-chafa-top=<row>`` (default: 0)
607+
Specify the position in character cells where the image starts (1 is
608+
the first column or row). If 0 (default) then try to automatically
609+
determine it according to the other values and the image aspect ratio
610+
and zoom.
611+
612+
``--vo-chafa-pad-x=<pad_x>``, ``--vo-chafa-pad-y=<pad_y>`` (default: -1)
613+
Used only when mpv reads the size in pixels from the terminal.
614+
Specify the number of padding pixels (on one side) which are included
615+
at the size which the terminal reports. If -1 (default) then the number
616+
of pixels is rounded down to a multiple of number of cells (per axis),
617+
to take into account padding at the report - this only works correctly
618+
when the overall padding per axis is smaller than the number of cells.
619+
620+
``--vo-chafa-config-clear=<yes|no>`` (default: yes)
621+
Whether or not to clear the terminal whenever the output is
622+
reconfigured (e.g. when video size changes).
623+
624+
``--vo-chafa-alt-screen=<yes|no>`` (default: yes)
625+
Whether or not to use the alternate screen buffer and return the
626+
terminal to its previous state on exit. When set to no, the last
627+
chafa image stays on screen after quit, with the cursor following it.
628+
629+
``--vo-chafa-pixel-mode=<pixel_mode>``
630+
Selects the graphics protocol that chafa will render graphics with.
631+
Can be one of the below list
632+
633+
symbols (Default)
634+
Writes unicode characters to the terminal
635+
sixels
636+
Uses the sixel protocol to render graphics.
637+
kitty
638+
Uses the kitty image protocol to render graphics.
639+
iterm2
640+
Uses the iterm2 image protocol to render graphics.
641+
642+
``--vo-chafa-canvas-mode=<canvas_mode>`` (default: truecolor)
643+
Selects the colorspace that chafa will render graphics with.
644+
Can be one of the below list as per chafa's documentation.
645+
646+
truecolor (Default)
647+
Truecolor (sRGB)
648+
256
649+
256 colors.
650+
240
651+
256 colors, but avoid using the lower 16 whose values vary between
652+
terminal environments.
653+
16
654+
16 colors using the aixterm ANSI extension.
655+
fgbg-bgfg
656+
Default foreground and background colors, plus inversion.
657+
fgbg
658+
Default foreground and background colors. No ANSI codes will be used.
659+
8
660+
8 colors, compatible with original ANSI X3.64.
661+
16-8
662+
16 FG colors (8 of which enabled with bold/bright) and 8 BG colors.
663+
664+
665+
chafa image quality options as per chafa's documentation:
666+
667+
``--vo-chafa-dither=<algo>``
668+
Selects the dither algorithm which chafa should apply.
669+
Can be one of the below list.
670+
671+
none (Default)
672+
Don't diffuse
673+
ordered
674+
Ordered dithering (Bayer or similar).
675+
diffusion
676+
Error diffusion dithering (Floyd-Steinberg or similar).
677+
noise
678+
Error diffusion dithering (Floyd-Steinberg or similar).
679+
680+
``--vo-chafa-work-factor=<work_factor>`` (default: 50)
681+
Sets the work/quality tradeoff factor. A higher value means more time and memory will be spent towards a higher quality output.
682+
581683
``image``
582684
Output each frame into an image file in the current directory. Each file
583685
takes the frame number padded with leading zeros as name.

meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,13 @@ if features['sixel']
10201020
sources += files('video/out/vo_sixel.c')
10211021
endif
10221022

1023+
chafa = dependency('chafa', version: '>= 1.18', required: get_option('chafa'))
1024+
features += {'chafa': chafa.found()}
1025+
if features['chafa']
1026+
dependencies += chafa
1027+
sources += files('video/out/vo_chafa.c')
1028+
endif
1029+
10231030
features += {'posix-shm': false}
10241031
if features['posix']
10251032
features += {'posix-shm': cc.has_function('shm_open', prefix: '#include <sys/mman.h>')}

meson.options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ option('wasapi', type: 'feature', value: 'auto', description: 'WASAPI audio outp
6060
option('amf', type: 'feature', value: 'auto', description: 'AMD AMF')
6161
option('caca', type: 'feature', value: 'auto', description: 'CACA')
6262
option('cocoa', type: 'feature', value: 'auto', description: 'Cocoa')
63+
option('chafa', type: 'feature', value: 'auto', description: 'Chafa')
6364
option('d3d11', type: 'feature', value: 'auto', description: 'Direct3D 11 video output')
6465
option('direct3d', type: 'feature', value: 'auto', description: 'Direct3D support')
6566
option('dmabuf-wayland', type: 'feature', value: 'auto', description: 'dmabuf-wayland video output')

video/out/vo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern const struct vo_driver video_out_dmabuf_wayland;
6565
extern const struct vo_driver video_out_wlshm;
6666
extern const struct vo_driver video_out_tct;
6767
extern const struct vo_driver video_out_sixel;
68+
extern const struct vo_driver video_out_chafa;
6869
extern const struct vo_driver video_out_kitty;
6970

7071
static const struct vo_driver *const video_out_drivers[] =
@@ -114,6 +115,9 @@ static const struct vo_driver *const video_out_drivers[] =
114115
#endif
115116
#if HAVE_SIXEL
116117
&video_out_sixel,
118+
#endif
119+
#if HAVE_CHAFA
120+
&video_out_chafa,
117121
#endif
118122
&video_out_kitty,
119123
&video_out_lavc,

0 commit comments

Comments
 (0)