Twitch video, list, and chat in one window in ttv-tui
Published on Updated on 9 min read
I wanted to watch the stream and read the chat on the same screen in my terminal Twitch client. I tried sixel video, measured five playback setups, and kept an SDL3 and libmpv window.
I wrote ttv-tui, a Twitch client for the terminal, in Go with Bubble Tea. It lists live categories and channels, opens the chat beside them, and plays the video through streamlink, which filters out the ads, and mpv. You don’t need an account to watch or to read the chat, and since v0.10.2 the list also shows Kick channels. The code is open source under the MIT license.
What I wanted was to pick a stream, watch it, and follow the chat on the same screen. In the first versions the video opened in a separate mpv window, and Hyprland decided where that window went. In the README screenshot below, the list and the chat fill the terminal and the video is in another window.
I tried placing that window through hyprctl, but it caused scaling bugs and I removed it on the day of the first release. Then I tried two things, drawing the video inside the terminal with sixel and opening my own window that shows the TUI and the video together. I kept the second one, which in my measurements used about the same CPU as plain mpv.
All of this happened in less than two weeks. The code links point to v0.10.2 unless I name another version.
| Date | Version | Change |
|---|---|---|
| Nov 4 | v0.1.0 |
First release, with video in the mpv window |
| Nov 7 | v0.4.0 |
Sixel video as an option |
| Nov 8 | v0.6.0 |
Single window with SDL3 and libmpv, on Linux with Wayland |
| Nov 8 | v0.8.0 |
Last release with sixel |
| Nov 11 | v0.10.0 |
The window on Windows, macOS, and X11 |
| Nov 15 | v0.10.2 |
Official libmpv in the Windows package |
Sixel video inside the terminal
From the start I had kept the video outside the terminal. I configured mpv to use hardware acceleration when available, and drawing frames as sixel or as characters would cost CPU and drop the frame rate. Since I wanted everything on one screen, I decided to try it anyway.
Sixel is a protocol some terminals understand for drawing images sent as character sequences. To show video, every frame has to be converted to that format and redrawn by the terminal.
I let mpv itself encode the frames with --vo=sixel, and the TUI only placed the image in a panel. The mode was optional, turned on by video = "sixel" in the config or by --video=sixel, and it only opened if the terminal announced sixel in its DA1 reply and mpv listed that output in --vo=help. Kitty, Alacritty, and Terminal.app have no sixel, and I left Windows and tmux out. The arguments v0.8.0 passed to mpv are in internal/player/player.go, with the rate capped at 15 fps by an fps filter.
I capped it at 15 fps because of the cost I measured in foot. The mpv window used 23% CPU at about 30 fps, while sixel at 480x270 and 15 fps used 69% in mpv and 9.5% in foot, and at 30 fps it rose to 118% and 17%. When I removed the 480x270 cap so the frame could fill the panel, the cost went up again, and on a real stream mpv went from 105% at 480x270 to 125% at 640x360, with the output to the terminal going from 2.0 to 3.2 MB/s.
On top of that, the TUI had to keep the image inside its panel without painting over the chat. It read the cell size in pixels from TIOCGWINSZ and, when the terminal didn’t report it, asked with CSI 16 t before Bubble Tea took over the input. When the panel was hidden, it sent vid=no so mpv would stop decoding.
It worked, but in real use the video ran at about 5 fps, and I couldn’t watch it like that. Changing the resolution didn’t fix it, because the CPU encodes every frame and the terminal redraws it. I removed the mode in commit 611850e, after v0.8.0, touching 64 files and deleting 9,650 lines. An old config with the sixel keys still loads, and the keys disappear on the next save.
Four alternatives measured
Before choosing what would replace it, I measured four alternatives against mpv’s separate window, all with the same 1080p60 sample at 8.3 Mbps for 30 s. The numbers come from that measurement on Nov 8, and I didn’t re-run it for this post.

SDL3 with libmpv came close to the plain mpv window and dropped no frames. kitty with its own graphics protocol had the same problem as sixel on a larger sample, with 143% of one core, 465 dropped frames, and audio 24 s out of sync. Sixel isn’t in the chart because I measured it at a different resolution and frame rate.
How the single window works
I created ttv-tui-window, a separate executable, in its own Go module under window/. It uses cgo, the bridge between Go and C libraries, to talk to SDL3, which opens the window and reads the keyboard, and to libmpv, which plays the video. I kept cgo in this executable only, so ttv-tui still builds without SDL3 or libmpv for Linux, macOS, and Windows.
The window starts the TUI in a pseudoterminal (PTY), which gives the program the input and output of a terminal, and draws the cells with the charmbracelet/x/vt emulator. The excerpt from window/main.go builds that process with the environment variables that connect both sides.
flowchart TD accTitle: Processes in the ttv-tui single window accDescr: Linux and macOS path. ttv-tui-window starts ttv-tui in a pseudoterminal. ttv-tui publishes the video cells on the TTV_TUI_VIDEO_HOST socket and starts streamlink, which opens the shim named mpv and writes the video to its stdin. The shim passes that descriptor to the window through SCM_RIGHTS, and the window's libmpv serves the same JSON IPC that ttv-tui used with mpv. T["ttv-tui<br/>Bubble Tea"] -->|"video cells<br/>TTV_TUI_VIDEO_HOST"| W["ttv-tui-window<br/>SDL3 + libmpv"] T -.->|JSON IPC| W W -->|PTY| T T -->|starts| S[streamlink] S -->|"video on stdin"| M["mpv shim"] M -->|"stdin descriptor<br/>via SCM_RIGHTS"| W
The first link is a socket whose path goes in the TTV_TUI_VIDEO_HOST variable. That variable is how the TUI finds out it is inside the window (internal/app/app.go), and the socket is where it publishes, as JSON, which cells belong to the video. internal/app/host.go hands only the newest panel to a writer goroutine, so if the window stops reading, the geometry goes stale and the interface doesn’t freeze. The window makes those cells transparent and libmpv draws the video underneath, but only after the first frame, because until then the TUI writes the name of the channel it is opening there (window/layout.go and window/render.go). The chat overlay uses the same socket to say how many columns belong to the chat, which side they are on, and the background opacity.
The second link is an executable named mpv that the window puts first in the TUI’s PATH. streamlink starts this shim as its player and writes the video to the shim’s stdin. On Linux and macOS, the shim passes the descriptor of its own stdin to the window’s libmpv through SCM_RIGHTS, the Unix mechanism for passing file descriptors between processes, together with the --input-ipc-server path where libmpv opens its IPC (window/session.go). After that the shim stays alive for as long as the session lasts, so streamlink and ttv-tui can track it as if it were the player (window/shim.go and window/shim_unix.go). Without --input-ipc-server, as in mpv --version, it forwards the call to the real mpv. That kept the JSON IPC, streamlink, and the ad filter the same as in terminal mode.
The window shipped in v0.6.0, for Linux with Wayland only. In that version, ttv-tui opened the window when it found ttv-tui-window next to itself and the window’s --probe passed. With --terminal it stays in the terminal with the separate mpv window, and until v0.8.0, with sixel turned on, it also stayed in the terminal, with embedded video (internal/app/window.go at v0.6.0).
Windows, macOS, and X11
In v0.10.0 I brought the window to Windows, macOS, and X11. On Windows, ConPTY plays the role of the pseudoterminal and a named pipe carries the video, because SCM_RIGHTS doesn’t exist there. The TUI is the same on all three systems.
The Windows package took more work, because it has to ship SDL3 and libmpv. The MSYS2 libmpv depended on dozens of codec and utility DLLs, so I replaced it with the official libmpv-2.dll from the mpv project, which bundles FFmpeg, and the zip went from 134 files and 74 MiB to 9 files and about 56 MiB, licenses included.
In v0.10.2, the release ships the window prebuilt for Linux amd64 and Windows amd64, and on macOS you build it from source. I only tested it by hand on Linux amd64 with Wayland. On Windows 11 the window ran as a proof of concept, and I haven’t tested it on macOS or X11 yet, although the code compiles and the automated tests pass in CI on macOS and Windows. Installation is in the English README.