---
title: "VHS でターミナルを録画・スクショする"
draft: false
publish: 2026-01-08
update: 2026-01-22
description: "VHS というターミナルを録画・スクリーンショットできるツールが便利だったので、個人的メモも兼ねて紹介します。"
tags: ["CLI", "Bash"]
---

## はじめに

コマンド実行の様子や結果をスクショしたり、録画したりするのって意外と大変じゃないですか？
わかりやすさのために地味に大切なことですが、数が多かったり、更新で撮り直したり...
そこで <b> VHS </b> の出番！

## VHS ってなに？

ターミナル操作をスクリプトで記述して、実行中のGIFや動画、任意タイミングでのスクリーンショットを出力する GO 製の CLI ツール。
つまり、**録画・スクショを自動化できる**ってこと！

本質ではない部分を削ぎ落とせるので、ドキュメント作成がはかどる！
もちろん、本ブログでもお世話になってます。

[](https://github.com/charmbracelet/vhs?tab=readme-ov-file)

また、GitHub Actions版もあるので、OSS などで常に最新版の画像にできる！素晴らしい！

[](https://github.com/charmbracelet/vhs-action)

（あんまり関係ないけど、家庭用ビデオ規格 VHS 規格は日本製らしい。）

## 前提

- VHS `v0.10.0`
- 動作には以下のツールが別途必要です：
  - [ffmpeg](https://ffmpeg.org/download.html)： エンコード用
  - [ttyd](https://github.com/tsl0922/ttyd#installation)： ターミナルのレンダリング用

## インストール

macOS、Linux、Windows など、主要な環境で簡単にインストールが可能。
Go製のツールなので、もちろん `go install` での導入も可能。お好みの方法を選んでください。

```bash
# macOS or Linux
brew install vhs

# Arch Linux
pacman -S vhs

# Nix
nix-env -iA nixpkgs.vhs

# GO
go install github.com/charmbracelet/vhs@latest

# Windows
winget install charmbracelet.vhs
```

## 使い方

VHS の使い方はシンプルで、 `.tape` ファイルに録画したいコマンドを記述し、実行するだけでOK。
まずは、以下のコマンドを実行して設定の雛形となる `.tape` ファイルを生成しましょう。

```bash
vhs new demo.tape
```

:::toggle[作成されたファイル]

詳細な設定項目やコマンドのリストがコメントで記載されている。手厚い！

```text
# VHS documentation
#
# Output:
#   Output <path>.gif               Create a GIF output at the given <path>
#   Output <path>.mp4               Create an MP4 output at the given <path>
#   Output <path>.webm              Create a WebM output at the given <path>
#
# Require:
#   Require <string>                Ensure a program is on the $PATH to proceed
#
# Settings:
#   Set FontSize <number>           Set the font size of the terminal
#   Set FontFamily <string>         Set the font family of the terminal
#   Set Height <number>             Set the height of the terminal
#   Set Width <number>              Set the width of the terminal
#   Set LetterSpacing <float>       Set the font letter spacing (tracking)
#   Set LineHeight <float>          Set the font line height
#   Set LoopOffset <float>%         Set the starting frame offset for the GIF loop
#   Set Theme <json|string>         Set the theme of the terminal
#   Set Padding <number>            Set the padding of the terminal
#   Set Framerate <number>          Set the framerate of the recording
#   Set PlaybackSpeed <float>       Set the playback speed of the recording
#   Set MarginFill <file|#000000>   Set the file or color the margin will be filled with.
#   Set Margin <number>             Set the size of the margin. Has no effect if MarginFill isn't set.
#   Set BorderRadius <number>       Set terminal border radius, in pixels.
#   Set WindowBar <string>          Set window bar type. (one of: Rings, RingsRight, Colorful, ColorfulRight)
#   Set WindowBarSize <number>      Set window bar size, in pixels. Default is 40.
#   Set TypingSpeed <time>          Set the typing speed of the terminal. Default is 50ms.
#
# Sleep:
#   Sleep <time>                    Sleep for a set amount of <time> in seconds
#
# Type:
#   Type[@<time>] "<characters>"    Type <characters> into the terminal with a
#                                   <time> delay between each character
#
# Keys:
#   Escape[@<time>] [number]        Press the Escape key
#   Backspace[@<time>] [number]     Press the Backspace key
#   Delete[@<time>] [number]        Press the Delete key
#   Insert[@<time>] [number]        Press the Insert key
#   Down[@<time>] [number]          Press the Down key
#   Enter[@<time>] [number]         Press the Enter key
#   Space[@<time>] [number]         Press the Space key
#   Tab[@<time>] [number]           Press the Tab key
#   Left[@<time>] [number]          Press the Left Arrow key
#   Right[@<time>] [number]         Press the Right Arrow key
#   Up[@<time>] [number]            Press the Up Arrow key
#   Down[@<time>] [number]          Press the Down Arrow key
#   PageUp[@<time>] [number]        Press the Page Up key
#   PageDown[@<time>] [number]      Press the Page Down key
#   Ctrl+<key>                      Press the Control key + <key> (e.g. Ctrl+C)
#
# Display:
#   Hide                            Hide the subsequent commands from the output
#   Show                            Show the subsequent commands in the output

Output demo.gif

Require echo

Set Shell "bash"
Set FontSize 32
Set Width 1200
Set Height 600

Type "echo 'Welcome to VHS!'" Sleep 500ms  Enter

Sleep 5s
```

:::

次に、作成した `.tape` ファイルを指定して VHS を実行すると録画が開始されます。

```bash
vhs demo.tape
```

![alt](./official_sample.gif "実行の様子")

録画が終わると、スクリプト内で指定した出力形式（例：`demo.gif`）でファイルが作成されます。
これが一連の基本的な使い方。

![alt](./demo.gif "いいかんじ")

export const unusedNote = `
official_sample.tape
Output official_sample.gif
Require echo
Set Shell "bash"
Set FontSize 32
Set Width 1200
Set Height 900
Type "vhs demo.tape" Sleep 500ms Enter
Wait
`;

## よく使うコマンド抜粋

多機能なツールですが、実用上は以下のコマンドをまずは覚えておけば十二分。

- `Output`： 保存先のパスとファイル形式を指定
- `Type`： ターミナルに文字を入力
- `Enter`： Enter キーを押下
- `Sleep`： 指定した時間だけ待機
- `Screenshot`： その瞬間のターミナル状態スクリーンショットとして保存<br/>（例：`Screenshot output.png`）

## おわり

ここでは足早な導入でしたが、公式ドキュメントにはさらに[詳しい使い方](https://github.com/charmbracelet/vhs?tab=readme-ov-file#vhs-command-reference)や[応用例](https://github.com/charmbracelet/vhs/tree/main/examples)が記載されているため、興味がある・楽をできそうだなって思った方はぜひチェックしてください！
また、開発元の[Charm](https://charm.land/)は他にも魅力的な CLI ツールを多数開発しているため、今後はそっちもブログで取り上げたい！
