[LINUX] Image display and video playback on Neovim Terminal


Since the introduction of libsixel, Sixel Graphics, which displays images in the terminal, has become fairly easy to work with.

In addition to displaying directly, by using a terminal that can use the Sixel extension of a function called DRCS, it is possible to display images with sixel even on the terminal provided by Neovim running on it. @Arakiken explained in detail about the Sixel extension of DRCS in this article, but it is mentioned a little in this article. , I'm going to try Neovim's DRCS-Sixel support.

If you use Neovim's "floating windows" function, you can open a window with a size specified anywhere on the buffer, and the terminal will operate on it, so you can display images and videos anywhere you like by converting to DRCS-Sixel. It will be possible to play.

About the environment

Use a terminal emulator that can use DRCS-Sixel, such as RLogin or mlterm.

Install libsixel

It's usually included in the distribution package right now, so let's install it quickly.

~% sudo apt-get install libsixel-bin libsixel-dev

installation of libvterm

A library used by neovim and vim's : terminal feature. The libvterm introduced in "About the Sixel Extension of DRCS" is [this repository] You can build and install it by dropping it from (https://bitbucket.org/arakiken/libvterm/src/default/), but since Neovim currently requires libvterm version 0.1 or higher, follow the steps below to source code. Let's get and deploy.

~% wget http://www.leonerd.org.uk/code/libvterm/libvterm-0.1.2.tar.gz
~% tar xvzf libvterm-0.1.2.tar.gz

The diff for DRCS-Sixel support is as follows. https://bitbucket.org/arakiken/libvterm/branch/sixel#diff I tried applying the diff manually this time. Build and install after modifying the source.

~% make
~% sudo make install

Install Neovim

It seems that Neovim now has a mechanism to implement the terminal by downloading libvterm in the build process and embedding it in itself, but in this bundle version by specifying the following option at the time of make Instead, let the OS use the installed libvterm.

~% sudo apt-get install ninja-build gettext libtool libtool-bin autoconf automake cmake g++ pkg-config unzip
~% git clone https://github.com/neovim/neovim.git
~% cd neovim
~% sudo make install

This completes the installation of Neovim that supports DRCS-Sixel.

Try to display the image

You can use the command ʻimg2sixelincluded in libsixel to display the image. gif animation is also good, but it did not play well, so [Introduction of applications using Sixel Graphics](https://qiita.com/arakiken/items/3e4bc9a6e43af0198e46) in the articleFFmpeg- I decided to use mpeg4 video using sixel`.

When using floating windows, I referred to the following article. [Neovim] Translucent window can now be opened

After preparing a video called miku.mp4, add the following to the Neovim configuration file.


command! Miku call s:miku()

function! s:miku()
    "Make an empty buffer
    :let buf = nvim_create_buf(v:false, v:true)
    "Open floating windows using that buffer
    :call nvim_open_win(buf, v:true, {'relative': 'win', 'height': 30, 'width': 40, 'col': 44, 'row': 14})
    "Make it transparent
    :set winblend=100
   "Open a terminal and execute the command
    :terminal /usr/local/bin/ffmpeg2 -i ~/Desktop/images/miku.mp4 -f sixel -loglevel quiet -pix_fmt rgb24 -s 240x400 -

If you start Neovim in this state and type the command : miku


The video will play like this (sorry, the gif video is very moody, but it's actually like this Plays more smoothly Will be). If you use this mechanism, you can realize something similar to the "editor that mentors come out and encourage you if you skip for a certain period of time" that was popular on Twitter before.

I think there are many other interesting ways to use it, so please give it a try!

Recommended Posts

Image display and video playback on Neovim Terminal
Image display and video playback on Neovim Terminal
Recording and playback on Linux
Take an image with Pepper and display it on your tablet
Add lines and text on the image
Measure indoor and outdoor temperature and humidity and display on dashboard
Display and shoot webcam video with Python Kivy [GUI]
Execute the command on the web server and display the result