Screen Recording GIF Demos

Screen Recording GIF Demos

Shows how to capture frames with Playwright and assemble annotated animated GIF demos for pull requests and docs, including timing and per-frame annotations.

Skill files1 file
SKILL.md239 lines
1
---
2
name: screen-recording
3
description: 'Create annotated animated GIF demos and screen recordings for pull requests and documentation. Covers frame capture, timing, imageio-based GIF creation, and per-frame annotation workflows.'
4
---
5
6
# Screen Recording
7
8
Create animated GIF demos that show a feature or workflow in action — with annotations, variable timing, and proper pacing. Useful for PR descriptions, documentation, and release notes.
9
10
## When to Use This Skill
11
12
Use this skill when you need to:
13
14
- Record a multi-step UI interaction as an animated GIF
15
- Create a demo showing before/after behavior
16
- Build annotated walkthroughs for documentation or release notes
17
- Show a bug reproduction or fix in action
18
19
## Prerequisites
20
21
```bash
22
pip install playwright Pillow imageio numpy scipy mss -q
23
playwright install chromium
24
```
25
26
## Core Workflow
27
28
### 1. Capture frames
29
30
Use Playwright to step through the interaction and capture each frame:
31
32
```python
33
from playwright.async_api import async_playwright
34
35
async def record_frames(url, steps, width=1400, height=900):
36
"""
37
steps: list of dicts with 'action' (async callable taking page)
38
and 'name' (frame filename)
39
"""
40
async with async_playwright() as p:
41
browser = await p.chromium.launch()
42
page = await browser.new_page(viewport={"width": width, "height": height})
43
await page.goto(url, wait_until="networkidle")
44
45
for step in steps:
46
if step.get("action"):
47
await step["action"](page)
48
await page.wait_for_timeout(step.get("wait", 500))
49
await page.screenshot(path=step["name"])
50
51
await browser.close()
52
```
53
54
### 2. Assemble GIF with imageio
55
56
**Use imageio, not PIL, for GIF writing** — PIL's GIF encoder merges visually similar frames, which kills animations.
57
58
```python
59
import imageio.v3 as iio
60
from PIL import Image
61
import numpy as np
62
63
frames = []
64
durations = []
65
66
for frame_path, duration_ms in frame_list:
67
img = Image.open(frame_path)
68
frames.append(np.array(img))
69
durations.append(duration_ms)
70
71
iio.imwrite("demo.gif", frames, duration=durations, loop=0)
72
```
73
74
### 3. Variable frame timing
75
76
Uniform timing makes everything feel either too fast or too slow. Use variable durations:
77
78
| Phase | Duration | Why |
79
|-------|----------|-----|
80
| Fast action (typing, clicking) | 100ms | Feels natural, keeps energy |
81
| Pause after action | 600-800ms | Let the viewer process what happened |
82
| Hero/final message | 500ms+ | Main takeaway needs time to land |
83
84
### 4. Annotate frames
85
86
Apply annotations to specific frames using the `image-annotations` skill:
87
88
```python
89
from PIL import Image, ImageDraw, ImageFont
90
91
def annotate_frame(frame_path, annotations, out_path):
92
img = Image.open(frame_path)
93
draw = ImageDraw.Draw(img)
94
95
for ann in annotations:
96
# Apply annotation (rect, arrow, label, etc.)
97
pass
98
99
img.save(out_path)
100
```
101
102
### 5. Fade-in annotations
103
104
For smooth annotation appearance:
105
106
```python
107
def apply_fade(base_frame, annotation_layer, alpha):
108
"""Blend annotation onto frame at given alpha (0.0 to 1.0)"""
109
blended = Image.blend(
110
base_frame.convert("RGBA"),
111
annotation_layer.convert("RGBA"),
112
alpha
113
)
114
return blended.convert("RGB")
115
116
# 2-frame pop-in at 10fps: 50% then 100%
117
faded_frames = [
118
apply_fade(base, annotations, 0.5), # frame 1: half opacity
119
apply_fade(base, annotations, 1.0), # frame 2: full opacity
120
]
121
```
122
123
At 10fps, use 2 fade frames (0.2s total). At 30fps, use 3-4 frames. Easing curves look bad at low FPS — simple pop-in is snappier and more readable.
124
125
## Build as a Script
126
127
The annotation logic gets complex for anything beyond trivial demos. Write a dedicated script (e.g., `annotate_gif.py`) with functions instead of inline code. You'll iterate on timing and placement.
128
129
## Testing Animations
130
131
**Always test in isolation first** — don't rebuild the full demo to test a fade tweak:
132
133
```python
134
# Small test GIF: 10 bare frames → fade frames → 15 hold frames
135
# Add a frame counter overlay for debugging:
136
draw.text((10, height - 30), f"F{i}/{total} a={alpha:.0%} FADE",
137
fill="white", font=small_font)
138
```
139
140
## Desktop Screen Recording (mss)
141
142
For recording desktop apps, terminals, or anything outside a browser. Uses `mss` for fast screen capture.
143
144
```python
145
import mss
146
from PIL import Image
147
import time
148
149
def record_gif(output_path, region=None, duration=5, fps=8):
150
"""Record screen region to GIF. region = {left, top, width, height} or None for full screen."""
151
with mss.mss() as sct:
152
if region is None:
153
region = sct.monitors[1] # primary monitor
154
155
frames = []
156
t_end = time.time() + duration
157
while time.time() < t_end:
158
t0 = time.time()
159
shot = sct.grab(region)
160
frames.append(Image.frombytes('RGB', shot.size, shot.rgb))
161
time.sleep(max(0, 1 / fps - (time.time() - t0)))
162
163
frames[0].save(output_path, save_all=True, append_images=frames[1:],
164
duration=int(1000 / fps), loop=0, optimize=True)
165
return len(frames)
166
167
record_gif('demo.gif', region={'left': 0, 'top': 0, 'width': 800, 'height': 500}, duration=3)
168
```
169
170
Tested: 3s at 8fps → 24 frames, ~31KB. Keep fps ≤ 10 for reasonable file sizes.
171
172
**Note:** `PIL.save(save_all=True)` works for simple recordings but merges visually similar frames. For annotated GIFs with fade effects, use `imageio.v3.imwrite` instead.
173
174
### Combining with window capture
175
176
```python
177
# Find window rect, then record it as a GIF
178
# Reuse find_window() from the ui-screenshots skill
179
import ctypes
180
from ctypes import c_int, Structure, byref, windll
181
182
class RECT(Structure):
183
_fields_ = [('left', c_int), ('top', c_int), ('right', c_int), ('bottom', c_int)]
184
185
hwnd = find_window('My App')[0][0]
186
rect = RECT()
187
windll.user32.GetWindowRect(hwnd, byref(rect))
188
region = {'left': rect.left, 'top': rect.top,
189
'width': rect.right - rect.left, 'height': rect.bottom - rect.top}
190
record_gif('app-demo.gif', region=region, duration=5, fps=8)
191
```
192
193
## Diff-Based Cluster Detection
194
195
Programmatically find changed regions between frames to decide what to annotate:
196
197
```python
198
import numpy as np
199
from scipy import ndimage
200
201
def find_changed_clusters(frame_a, frame_b, threshold=30, min_pixels=300, dilate=5):
202
"""Find bounding boxes of changed regions between two frames."""
203
diff = np.abs(frame_b.astype(float) - frame_a.astype(float)).max(axis=2)
204
mask = diff > threshold
205
dilated = ndimage.binary_dilation(mask, iterations=dilate)
206
labeled, n = ndimage.label(dilated)
207
clusters = []
208
for i in range(1, n + 1):
209
ys, xs = np.where(labeled == i)
210
if len(ys) < min_pixels:
211
continue
212
clusters.append((xs.min(), ys.min(), xs.max(), ys.max(), len(ys)))
213
return sorted(clusters, key=lambda c: -c[4]) # largest first
214
```
215
216
## Format Compatibility
217
218
| Format | VS Code Preview | GitHub | Browser |
219
|--------|----------------|--------|---------|
220
| GIF | ✅ Animates | ✅ | ✅ |
221
| WebP | ⚠️ Static only | ✅ | ✅ |
222
| MP4 | ❌ Broken | ⚠️ | ✅ |
223
224
**GIF is the only universally supported animated format** across VS Code preview, GitHub markdown, and browsers.
225
226
## Guidelines
227
228
1. **Type → pause → annotate** — during fast action, show NO annotation. Pause first, then annotate
229
2. **Hero message gets the biggest font** — 64pt+ for the main takeaway, 38pt for details
230
3. **GIF palette does NOT kill gradients** — 20 distinct alpha steps survive 256-color palette
231
4. **10fps minimum** for typing/interaction — lower looks stuttery
232
5. **Build iteratively** — get the frame sequence right first, add annotations second, tune timing last
233
234
## Limitations
235
236
- GIF is limited to 256 colors per frame — fine for UI screenshots, may show banding on photographic content
237
- Large GIFs (50+ frames at high resolution) can be several MB — consider cropping to the relevant area
238
- No audio support in GIF — use MP4 for narrated demos (but lose VS Code preview support)
239

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,275 prompts

More by @OpenSourceBuffGuy

See all
Edible Landscape Cake of a City prompt image

Edible Landscape Cake of a City

Makes a macro food photo of a rectangular landscape cake for any city, with edible terrain, fruit lettering of the place name and a tiny sugar landmark.

image-prompt, nano-banana, placeholders, template, conditional-logic, food-photography, baking, landscape, macro, bokeh, photorealistic, natural-light, soft-lighting, text-rendering, typography, cooking, creativity, step-by-step-guide, for-artists, concept-art, miniature, cityscape, travel

Half photo, half black-ink illustration poster prompt image

Half photo, half black-ink illustration poster

Turns an uploaded photo into a 2:3 editorial poster, with the original photograph on top and a minimalist black-ink illustration of its subject below, plus handwritten notes.

image-prompt, poster, reference-image, split-screen, ink-drawing, illustration, minimalist, black-and-white, negative-space, editorial, typography, text-rendering, vertical-format, style-transfer, photography, limited-palette, structured-output, nano-banana, for-artists, for-photographers, for-designers, long-form

Student Feedback Coach prompt image

Student Feedback Coach

Helps teachers write specific, strength-first, growth-oriented feedback on student work, naming one or two highest-leverage improvements and concrete next steps.

system-prompt, act-as, coach, education, k12-education, higher-education, grading, critique, rewriting, for-teachers, for-students, xml-tags, structured-output, guardrails, encouraging, empathetic, template, expert-advice, rubric, iterative-refinement, task-decomposition, long-form

Reviews

Loading reviews…

Discussion

Loading comments…