Files
rrweb/packages/rrvideo/src/cli.ts
Yun Feng 937e3b42ce rrvideo: improve the video quality and add a progress bar for the CLI tool (#1197)
* refactor rrvideo: use playwright rather than puppeteer

* add a progress bar for the tool

* add tests for cli.ts

* fix build error

* add change log

* update readme file

* Apply a scaling method to improve the resolution of the output video
2026-04-01 12:00:00 +08:00

49 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
import * as fs from 'fs';
import * as path from 'path';
import minimist from 'minimist';
import { ProgressBar } from '@open-tech-world/cli-progress-bar';
import type { RRwebPlayerOptions } from 'rrweb-player';
import { transformToVideo } from './index';
const argv = minimist(process.argv.slice(2));
if (!argv.input) {
throw new Error('please pass --input to your rrweb events file');
}
let config = {};
if (argv.config) {
const configPathStr = argv.config as string;
const configPath = path.isAbsolute(configPathStr)
? configPathStr
: path.resolve(process.cwd(), configPathStr);
config = JSON.parse(fs.readFileSync(configPath, 'utf-8')) as Omit<
RRwebPlayerOptions['props'],
'events'
>;
}
const pBar = new ProgressBar({ prefix: 'Transforming' });
const onProgressUpdate = (percent: number) => {
if (percent < 1) pBar.run({ value: percent * 100, total: 100 });
else
pBar.run({ value: 100, total: 100, prefix: 'Transformation Completed!' });
};
transformToVideo({
input: argv.input as string,
output: argv.output as string,
rrwebPlayer: config,
onProgressUpdate,
})
.then((file) => {
console.log(`Successfully transformed into "${file}".`);
})
.catch((error) => {
console.log('Failed to transform this session.');
console.error(error);
process.exit(1);
});