Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Commit ebfe8ee

Browse files
committed
Add fps option
1 parent 68b760a commit ebfe8ee

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The video will be saved at the specified `savePath` (`/tmp/video.mp4` in the abo
4747
- `savePath` <[string]> Where to save the video.
4848
- `options` <[Object]>
4949
- `followPopups` <[boolean]> Whether or not to follow browser focus when popups are opened. Defaults to `false`. Note: this option will only work correctly if the popups opened are the same size as the original page. If a smaller or larger popup is open, frames will be scaled to fit the original size.
50+
- `fps` <[number]> The frames per second for the recording. Defaults to `25`. A higher number will improve the recording quality but also increase the file size.
5051
- returns: <[Promise]<[PageVideoCapture](#class-pagevideocapture)>>
5152

5253
Records video of a page and saves it at the specified path.

src/PageVideoCapture.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const debug = Debug('pw-video:PageVideoCapture');
1111

1212
export interface CaptureOptions {
1313
followPopups: boolean;
14+
fps?: number;
1415
}
1516

1617
interface ConstructorArgs {
@@ -36,7 +37,7 @@ export class PageVideoCapture {
3637

3738
const collector = await ScreencastFrameCollector.create(page, options);
3839
const queue = new SortedFrameQueue();
39-
const writer = await VideoWriter.create(savePath);
40+
const writer = await VideoWriter.create(savePath, options);
4041

4142
const capture = new PageVideoCapture({ collector, queue, page, writer });
4243
await collector.start();

src/VideoWriter.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import { ensureDir } from 'fs-extra';
55
import { dirname } from 'path';
66
import { PassThrough } from 'stream';
77
import { ensureFfmpegPath } from './utils';
8+
import { CaptureOptions } from './PageVideoCapture';
89

910
const debug = Debug('pw-video:VideoWriter');
1011

1112
export class VideoWriter extends EventEmitter {
12-
public static async create(savePath: string): Promise<VideoWriter> {
13+
public static async create(
14+
savePath: string,
15+
options?: CaptureOptions,
16+
): Promise<VideoWriter> {
1317
await ensureDir(dirname(savePath));
1418

15-
return new VideoWriter(savePath);
19+
return new VideoWriter(savePath, options);
1620
}
1721

1822
private _endedPromise: Promise<void>;
@@ -21,10 +25,13 @@ export class VideoWriter extends EventEmitter {
2125
private _stopped = false;
2226
private _stream: PassThrough = new PassThrough();
2327

24-
protected constructor(savePath: string) {
28+
protected constructor(savePath: string, options?: CaptureOptions) {
2529
super();
2630

2731
ensureFfmpegPath();
32+
if (options && options.fps) {
33+
this._framesPerSecond = options.fps;
34+
}
2835
this._writeVideo(savePath);
2936
}
3037

0 commit comments

Comments
 (0)