网友回复
以下是使用命令行将 Chrome 浏览器打开的网页动画录制成 PNG 图片序列 的完整方案,包含 Puppeteer 自动化脚本和 FFmpeg 屏幕录制两种方法:
方法一:使用 Puppeteer CLI(推荐)
1. 安装 Puppeteer(需 Node.js 环境)
npm init -y npm install puppeteer
2. 创建截图脚本 capture.js
const puppeteer = require('puppeteer'); const fs = require('fs'); const path = require('path'); (async () => { const browser = await puppeteer.launch({ headless: false, defaultViewport: null, args: ['--window-size=1080,1920'] }); const page = await browser.newPage(); await page.goto('https://your-animation-url.com'); // 替换为你的网页地址 // 等待动画加载(根据实际情况调整) await page.waitForTimeout(2000); const totalFrames = 60; const frameInterval = 100; // 每帧间隔时间(毫秒) for (let i = 0; i < totalFrames; i++) { const framePath = path.join(__dirname, 'frames', `frame_${String(i).padStart(4, '0')}.png`); await page.screenshot({ path: framePath, ...
点击查看剩余70%