
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
webpage-video-capture
Advanced tools
webpage-video-capture 是一个可以录制网页视频的Node.js程序,它能录制使用JavaScript动画的网页生成流畅视频。它采用timecut和puppeteer打开一个网页,覆盖其时间处理函数,生成网页快照图片,然后将这些图片帧序列传递给ffmpeg编码成视频。它可以精准的生成任意低于或高于网页实时FPS的视频,且生成的视频是平滑流畅的,同时支持在视频中插入背景音乐。
你可以从命令行或Node.js库运行webpage-video-capture。它依赖ffmpeg,Node.js v10.0.0或更高版本以及npm,请确保系统环境中已安装相关依赖。
使用以下命令来安装webpage-video-capture:
npm install webpage-video-capture -g
由于puppeteer的一个权限问题,Mac或Linux的用户在安装全局包时可能出现权限错误。你可以配置npm将全局包安装到当前用户的指定目录,详细方法请参考这篇教程: https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-two-change-npms-default-directory
你也可以选择直接用root用户来安装,通过以下命令:
sudo npm install -g webpage-video-capture --unsafe-perm=true --allow-root
国内用户可能会遇到下载puppeteer很慢而导致安装卡住或报错的情况,可以尝试使用cnpm来安装或这使用以下命令修改puppeteer的下载源后再来安装:
npm config set PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors
npm install webpage-video-capture -g
接下来你就可以在命令行中直接使用webpage-video-capture命令了:
webpage-video-capture --help
使用方式:
webpage-video-capture "url" [options]
url可以是web url(例如https://example.com)或文件路径。如果未指定url,则默认为index.html。注意用引号括起包含特殊字符(如#和&)的网址,options相关参数下面会进行详细说明
下面是一些使用示例,默认行为:
webpage-video-capture
上面的命令将打开当前工作目录下的index.html,将视口设置为800 x 600,以每秒60帧的速度录制5秒,并使用yuv420p像素格式生成名为video.mp4的视频文件到当前工作目录中。默认值可能在将来发生变化,所以对于长期脚本来说,建议明确的传递相关的选项参数,如下例所示。
录制一个网络上的https://example.com页面,并输出到./videos/example.mp4:
webpage-video-capture https://example.com --output ./videos/example.mp4
设置页面视口尺寸为1920 x 1080(这通常也等于视频的分辨率),FPS为24,录制时长为10秒:
webpage-video-capture index.html --viewport 1920,1080 --fps 24 --duration 10 --output video-24fps-10s.mp4
为视频添加背景音乐:
webpage-video-capture index.html --audio audio.mp3 --output video-with-audio.mp4
录制页面中的指定区域,宽800像素,高600像素,距离页面左上角偏移x轴100像素,y轴200像素,此时输出的视频分辨率将是800 x 600像素:
webpage-video-capture index.html -V 1920,1080 --width 800 --height 600 -x 100 -y 200 video-800x600.mp4
音频:-a, --audio path
输出: -O, --output path
帧率:-R, --fps frame rate
时长:-d, --duration seconds
CSS选择器:-S, --selector "selector"
视口尺寸:-V, --viewport dimensions
800(宽度)或800,600(宽度和高度,默认值)。Canvas模式:--canvas-capture-mode [format]
png),否则它使用保存的图像的扩展名,或者png如果未指定或支持格式则默认使用。可以使格式前缀immediate:(例如immediate:png)以在渲染后立即获取像素数据,这有时是某些WebGL渲染器所需要的。使用--selector选项指定Canvas元素,否则默认为网页中的第一个Canvas元素。动画起始秒数:-s, --start n seconds
0)。延迟开始录制:--start-delay n seconds
X轴偏移:-x, --x-offset pixels
0)。Y轴偏移:-y, --y-offset pixels
0)。录制宽度:-W, --width pixels
录制宽度:-H, --height pixels
左边缘:-l, --left pixels
--x-offset。右边缘:-r, --right pixels
--width时,该参数将被忽略。上边缘:-t, --top pixels
--y-offset.下边缘:-b, --bottom pixels
--height时,该参数将被忽略。禁用偶数自动宽度:--no-round-to-even-width
禁用偶数自动高度:--no-round-to-even-height
浏览器可执行文件路径:--executable-path path
Puppeteer启动参数:-L, --launch-arguments arguments
--launch-arguments="--single-process"。可以在这里找到参数列表。禁用无头模式:--no-headless
快照模式:--snapshot-mode
FFmpeg输入参数:-e, --input-options options
--input-options="-framerate 30"FFmpeg输出参数:-E, --output-options options
--output-options="-vf scale=320:240"静默模式:-q, --quiet
版本号:-v, --version
帮助:-h, --help
Node API的使用方式及参数选项与命令行工具类似,你以通过调用webpage-video-capture导出的capture函数实现同样的功能:
const capture = require('webpage-video-capture');
capture({
url: './index.html',
fps: 30,
duration: 20,
viewport: {
width: 1920,
height: 1080
},
output: './video-30fps.mp4',
audio: './resources/audio.mp3'
});
FAQs
Capture webpage animation and generate video
We found that webpage-video-capture demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.