-
Notifications
You must be signed in to change notification settings - Fork 309
fix: improve demo recording pipeline and regenerate GIFs #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Extract a preview frame from each demo GIF for quick visual inspection. | ||
| * Saves individual PNG frames to demo-previews/ directory. | ||
| * | ||
| * Requires: ffmpeg, gifsicle (for frame delay info) | ||
| * | ||
| * Usage: | ||
| * node preview-gifs.js # default: 3s before end | ||
| * node preview-gifs.js --before 5 # 5s before end | ||
| */ | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const { readdirSync, existsSync, mkdirSync, rmSync } = require('fs'); | ||
| const { join, basename } = require('path'); | ||
|
|
||
| const rootDir = join(__dirname, '..', '..'); | ||
| const previewDir = join(rootDir, 'demo-previews'); | ||
|
|
||
| // Parse CLI args | ||
| const args = process.argv.slice(2); | ||
| let beforeSeconds = 3; | ||
|
|
||
| for (let i = 0; i < args.length; i++) { | ||
| if (args[i] === '--before' && args[i + 1]) { | ||
| beforeSeconds = parseFloat(args[++i]); | ||
| } | ||
| } | ||
|
|
||
| // Find all demo GIFs | ||
| function findGifs() { | ||
| const gifs = []; | ||
| for (const entry of readdirSync(rootDir)) { | ||
| if (!/^\d{2}-/.test(entry)) continue; | ||
| const imagesDir = join(rootDir, entry, 'images'); | ||
| if (!existsSync(imagesDir)) continue; | ||
| for (const file of readdirSync(imagesDir)) { | ||
| if (file.endsWith('-demo.gif')) { | ||
| gifs.push({ path: join(imagesDir, file), chapter: entry }); | ||
| } | ||
| } | ||
| } | ||
| return gifs.sort((a, b) => a.path.localeCompare(b.path)); | ||
| } | ||
|
|
||
| // Get frame delays from a GIF | ||
| function getFrameDelays(gifPath) { | ||
| const output = execSync(`gifsicle --info "${gifPath}"`, { encoding: 'utf8', maxBuffer: 50 * 1024 * 1024 }); | ||
| const delays = []; | ||
| const delayRegex = /delay (\d+(?:\.\d+)?)s/g; | ||
| let match; | ||
| while ((match = delayRegex.exec(output)) !== null) { | ||
| delays.push(parseFloat(match[1])); | ||
| } | ||
| return delays; | ||
| } | ||
|
|
||
| // Find frame index at N seconds before the end | ||
| function frameAtSecondsBeforeEnd(delays, seconds) { | ||
| const totalTime = delays.reduce((a, b) => a + b, 0); | ||
| const targetTime = totalTime - seconds; | ||
| if (targetTime <= 0) return 0; | ||
|
|
||
| let cumulative = 0; | ||
| for (let i = 0; i < delays.length; i++) { | ||
| cumulative += delays[i]; | ||
| if (cumulative >= targetTime) return i; | ||
| } | ||
| return delays.length - 1; | ||
| } | ||
|
|
||
| // Main | ||
| if (existsSync(previewDir)) rmSync(previewDir, { recursive: true }); | ||
| mkdirSync(previewDir, { recursive: true }); | ||
|
|
||
| const gifs = findGifs(); | ||
| if (gifs.length === 0) { | ||
| console.log('No demo GIFs found'); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| console.log(`\nExtracting frames (${beforeSeconds}s before end) from ${gifs.length} GIFs...\n`); | ||
|
|
||
| let count = 0; | ||
| for (const { path: gif, chapter } of gifs) { | ||
| const name = basename(gif, '.gif'); | ||
| const delays = getFrameDelays(gif); | ||
| const frameIndex = frameAtSecondsBeforeEnd(delays, beforeSeconds); | ||
| const prefix = chapter.replace(/^(\d+)-.+/, '$1'); | ||
| const outName = `${prefix}-${name}.png`; | ||
| const outPath = join(previewDir, outName); | ||
|
|
||
| try { | ||
| execSync( | ||
| `ffmpeg -y -i "${gif}" -vf "select=eq(n\\,${frameIndex})" -vframes 1 -update 1 "${outPath}" 2>/dev/null`, | ||
| { stdio: 'pipe' } | ||
| ); | ||
| console.log(` ✓ ${outName} (frame #${frameIndex}/${delays.length})`); | ||
| count++; | ||
| } catch (e) { | ||
| console.log(` ✗ ${name}: extraction failed`); | ||
| } | ||
| } | ||
|
|
||
| console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`); | ||
| console.log(`✓ ${count} preview frames saved to demo-previews/`); | ||
| console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`); | ||
| console.log(`\nOpen in Finder: open demo-previews/`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,3 +100,4 @@ Desktop.ini | |
| .claude | ||
| .plans | ||
| .plans.vhs-wrapper | ||
| demo-previews | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
framerate: 15default added here diverges from theframerate: 10used indemos.json(line 8). Similarly,responseWait: 25andexitWait: 2here don't match the updateddemos.jsonvalues ofresponseWait: 40andexitWait: 3. Whilescan:demoswas removed from thegenerate:demospipeline, it's still available as a standalone script (npm run scan:demos). Running it would overwritedemos.jsonwith these stale defaults, undoing the curated settings. Consider updating the defaults here to matchdemos.json, or adding a comment noting these are intentionally different.