pup-recorder 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.ts CHANGED
@@ -38,3 +38,10 @@ await build({
38
38
  format: "cjs",
39
39
  outDir: "dist",
40
40
  });
41
+
42
+ await build({
43
+ ...common,
44
+ entry: ["src/audio_preload.ts"],
45
+ format: "cjs",
46
+ outDir: "dist",
47
+ });
@@ -13,12 +13,14 @@ import { FFVideoEncoder } from 'node-av/constants';
13
13
  import { FormatContext } from 'node-av';
14
14
  import { Frame } from 'node-av';
15
15
  import { HardwareContext } from 'node-av/api';
16
+ import { HardwareFramesContext } from 'node-av';
16
17
  import type { NativeImage } from 'electron';
17
18
  import { Packet } from 'node-av';
18
19
  import { Size } from 'electron';
19
20
  import { SoftwareScaleContext } from 'node-av';
20
21
  import { SpawnOptions } from 'child_process';
21
22
  import { Stream } from 'node-av';
23
+ import { WebContents } from 'electron';
22
24
  import type { WebFrameMain } from 'electron';
23
25
  import z from 'zod';
24
26
 
@@ -29,15 +31,13 @@ export declare function advanceVirtualTime(cdp: Debugger, budget: number): Promi
29
31
 
30
32
  export declare const ANNEX_B_START_CODE: Buffer<ArrayBuffer>;
31
33
 
32
- export declare interface AudioCapture {
33
- teardown(): Promise<void>;
34
- }
34
+ export declare function attachAudioListeners({ wc, encoder, getVideoTimeMs, onError }: AudioListenerOptions): AudioDisposal;
35
35
 
36
- export declare interface AudioCaptureOptions {
37
- encoder: EncoderPipeline;
38
- getVideoTimeMs: () => number;
39
- onError: (error: Error) => void;
40
- }
36
+ export declare const AUDIO_CHUNK_CHANNEL = "audio-chunk";
37
+
38
+ export declare const AUDIO_META_CHANNEL = "audio-meta";
39
+
40
+ export declare type AudioDisposal = () => void;
41
41
 
42
42
  declare class AudioEncoder_2 implements Disposable {
43
43
  private _ctx;
@@ -72,6 +72,13 @@ export declare interface AudioEncoderOptions {
72
72
  muxer: FormatMuxer;
73
73
  }
74
74
 
75
+ export declare interface AudioListenerOptions {
76
+ wc: WebContents;
77
+ encoder: EncoderPipeline;
78
+ getVideoTimeMs: () => number;
79
+ onError: (error: Error) => void;
80
+ }
81
+
75
82
  export declare class BitReader {
76
83
  private _bits;
77
84
  pos: number;
@@ -105,6 +112,11 @@ export declare function buildStegoHTML(targetURL: string, size: Size): string;
105
112
 
106
113
  export declare function buildUnifiedExtradata(opts: UnifiedExtradataOptions): Buffer;
107
114
 
115
+ export declare interface CancelMsg {
116
+ type: IpcMsgType.CANCEL;
117
+ reason?: string;
118
+ }
119
+
108
120
  export declare const canIUseGPU: Promise<boolean>;
109
121
 
110
122
  export declare function checkHTML(source: string): void;
@@ -113,7 +125,6 @@ export declare function chromiumOptions(disableGpu: boolean): Promise<string[]>;
113
125
 
114
126
  export declare interface CLIOptions {
115
127
  name: string;
116
- defaults: RenderOptions;
117
128
  run: (source: string, options: RenderOptions) => Promise<unknown>;
118
129
  }
119
130
 
@@ -155,9 +166,19 @@ declare class ConcurrencyLimiter {
155
166
  export { ConcurrencyLimiter }
156
167
  export { ConcurrencyLimiter as ConcurrencyLimiter_alias_1 }
157
168
 
158
- export declare function createStegoURL(src: string, size: Size): string;
169
+ declare type ConsoleCallback = (level: string, message: string) => void;
170
+ export { ConsoleCallback }
171
+ export { ConsoleCallback as ConsoleCallback_alias_1 }
172
+
173
+ export declare interface ConsoleMsg {
174
+ type: IpcMsgType.CONSOLE;
175
+ level: string;
176
+ message: string;
177
+ }
159
178
 
160
- export declare function createVideoEncoder(opts: VideoFactoryOptions, muxer: FormatMuxer): Promise<VideoSetup>;
179
+ export declare function createHwVideoEncoder(opts: HwVideoFactoryOptions, muxer: FormatMuxer): Promise<VideoSetup>;
180
+
181
+ export declare function createStegoURL(src: string, size: Size): string;
161
182
 
162
183
  export declare function debounce<T extends (...args: unknown[]) => void>(fn: T, delay?: number): T;
163
184
 
@@ -175,7 +196,7 @@ declare const DEFAULT_HEIGHT = 1080;
175
196
  export { DEFAULT_HEIGHT }
176
197
  export { DEFAULT_HEIGHT as DEFAULT_HEIGHT_alias_1 }
177
198
 
178
- declare const DEFAULT_OUT_FILE = "output.mp4";
199
+ declare const DEFAULT_OUT_FILE = "out/html.mp4,out/html.webm";
179
200
  export { DEFAULT_OUT_FILE }
180
201
  export { DEFAULT_OUT_FILE as DEFAULT_OUT_FILE_alias_1 }
181
202
 
@@ -189,6 +210,11 @@ export { defaultRenderOptions as defaultRenderOptions_alias_1 }
189
210
 
190
211
  export declare function disposeWindow(win: BrowserWindow): Promise<void>;
191
212
 
213
+ export declare interface DoneMsg {
214
+ type: IpcMsgType.DONE;
215
+ payload: IpcDonePayload;
216
+ }
217
+
192
218
  export declare function drainPackets(ctx: CodecContext, pkt: Packet, stream: Stream, muxer: FormatMuxer): Promise<void>;
193
219
 
194
220
  export declare function electronOpts(disableGpu: boolean): Promise<string[]>;
@@ -204,7 +230,7 @@ declare class EncoderPipeline {
204
230
  encodeBGRA(input: Buffer): Promise<void>;
205
231
  encodePNG(pngData: Buffer): Promise<void>;
206
232
  encodeAudio(pcm: Buffer): Promise<void>;
207
- finish(): Promise<string>;
233
+ finish(): Promise<string[]>;
208
234
  [Symbol.asyncDispose](): Promise<void>;
209
235
  private free;
210
236
  private bgraFrame;
@@ -227,10 +253,19 @@ declare type EnvParser<T> = (value: unknown) => T;
227
253
  export { EnvParser }
228
254
  export { EnvParser as EnvParser_alias_1 }
229
255
 
256
+ export declare interface ErrorMsg {
257
+ type: IpcMsgType.ERROR;
258
+ error: string;
259
+ }
260
+
261
+ export declare function evalIn(cdp: Debugger, expression: string): Promise<unknown>;
262
+
230
263
  declare function exec(cmd: string, options?: SpawnOptions): ProcessHandle;
231
264
  export { exec }
232
265
  export { exec as exec_alias_1 }
233
266
 
267
+ export declare function extractAlphaToYuv420pBuffer(bgraFrame: Frame, buf: Buffer): void;
268
+
234
269
  export declare interface FixedBufferWriter {
235
270
  new (path: string, bufferSize: number, queueDepth?: number): FixedBufferWriter;
236
271
  write(buffer: Buffer): void;
@@ -298,7 +333,16 @@ export declare interface HwVideoEncoderOptions {
298
333
  muxer: FormatMuxer;
299
334
  }
300
335
 
301
- export declare function interleaveAccessUnits(baseNals: NalUnit[], alphaNals: NalUnit[]): Buffer;
336
+ export declare interface HwVideoFactoryOptions {
337
+ width: number;
338
+ height: number;
339
+ fps: number;
340
+ bitrate?: number;
341
+ disableHwCodec?: boolean;
342
+ sharedHw?: HardwareContext;
343
+ }
344
+
345
+ export declare function interleaveAccessUnits(baseNals: NalUnit[], alphaNals: NalUnit[], cfg: NvencHevcConfig): Buffer;
302
346
 
303
347
  export declare interface IpcDonePayload {
304
348
  written: number;
@@ -306,23 +350,39 @@ export declare interface IpcDonePayload {
306
350
  outFile: string;
307
351
  }
308
352
 
353
+ export declare interface IpcEvents {
354
+ progress: [value: number];
355
+ console: [level: string, msg: string];
356
+ done: [payload: IpcDonePayload];
357
+ error: [error: Error];
358
+ close: [code: number | null];
359
+ }
360
+
361
+ export declare type IpcMsg = ConsoleMsg | ProgressMsg | DoneMsg | ErrorMsg | CancelMsg;
362
+
309
363
  export declare const enum IpcMsgType {
364
+ CONSOLE = "console",
310
365
  PROGRESS = "progress",
311
366
  DONE = "done",
312
- ERROR = "error"
367
+ ERROR = "error",
368
+ CANCEL = "cancel"
313
369
  }
314
370
 
315
- export declare class IpcReader extends EventEmitter<{
316
- progress: [value: number];
317
- message: [msg: Msg];
318
- done: [payload: IpcDonePayload];
319
- error: [error: Error];
320
- close: [];
321
- }> {
371
+ export declare class IpcReader extends EventEmitter<IpcEvents> {
322
372
  constructor(child: ChildProcess);
323
373
  }
324
374
 
375
+ declare interface IPCRenderOptions extends RenderOptions {
376
+ source: string;
377
+ signal: AbortSignal;
378
+ onProgress: ProgressCallback;
379
+ onConsole: ConsoleCallback;
380
+ }
381
+ export { IPCRenderOptions }
382
+ export { IPCRenderOptions as IPCRenderOptions_alias_1 }
383
+
325
384
  export declare class IpcWriter {
385
+ writeConsole(level: string, message: string): void;
326
386
  writeProgress(value: number): void;
327
387
  writeError(error: string): Promise<void>;
328
388
  writeDone(payload: IpcDonePayload): Promise<void>;
@@ -342,7 +402,7 @@ declare class Lazy<T> {
342
402
  export { Lazy }
343
403
  export { Lazy as Lazy_alias_1 }
344
404
 
345
- export declare function loadWindow({ source, onCreated, renderer }: WindowOptions): Promise<BrowserWindow>;
405
+ export declare function loadWindow({ source, renderer, preload, onCreated, signal, }: WindowOptions): Promise<BrowserWindow>;
346
406
 
347
407
  declare class Logger implements LoggerLike {
348
408
  private _level;
@@ -382,19 +442,26 @@ export declare function makeFrame(width: number, height: number, pixFmt: AVPixel
382
442
 
383
443
  export declare function makePacket(): Packet;
384
444
 
385
- declare type Msg = {
386
- type: IpcMsgType.PROGRESS;
387
- value: number;
388
- } | {
389
- type: IpcMsgType.DONE;
390
- payload: IpcDonePayload;
391
- } | {
392
- type: IpcMsgType.ERROR;
393
- error: string;
394
- };
445
+ export declare const NAL_BLA_W_LP = 16;
395
446
 
396
447
  export declare const NAL_HEADER_SIZE = 2;
397
448
 
449
+ export declare const NAL_IDR_N_LP = 20;
450
+
451
+ export declare const NAL_IDR_W_RADL = 19;
452
+
453
+ export declare const NAL_PPS = 34;
454
+
455
+ export declare const NAL_RSV_IRAP_VCL23 = 23;
456
+
457
+ export declare const NAL_SEI_PREFIX = 39;
458
+
459
+ export declare const NAL_SEI_SUFFIX = 40;
460
+
461
+ export declare const NAL_SPS = 33;
462
+
463
+ export declare const NAL_VPS = 32;
464
+
398
465
  export declare interface NalUnit {
399
466
  type: number;
400
467
  layerId: number;
@@ -413,11 +480,7 @@ export { noerr as noerr_alias_1 }
413
480
 
414
481
  export declare class NvencDualLayerEncoder implements Disposable {
415
482
  private _s;
416
- private _seiBuffer;
417
483
  private _pts;
418
- private _seiInjected;
419
- private _alphaBuf?;
420
- private _alphaFrame?;
421
484
  private constructor();
422
485
  static create(opts: HwVideoEncoderOptions): Promise<NvencDualLayerEncoder>;
423
486
  encode(bgraFrame: Frame, muxer: FormatMuxer): Promise<void>;
@@ -426,8 +489,37 @@ export declare class NvencDualLayerEncoder implements Disposable {
426
489
  private drainInterleaved;
427
490
  }
428
491
 
492
+ export declare interface NvencHevcConfig {
493
+ log2MaxPocLsb: number;
494
+ numShortTermRefPicSets: number;
495
+ numDeltaPocsSet0: number;
496
+ longTermRefPicsPresent: boolean;
497
+ spsTemporalMvpEnabled: boolean;
498
+ saoEnabled: boolean;
499
+ cabacInitPresent: boolean;
500
+ ppsHasLoopFilterAcrossSlicesFlag: boolean;
501
+ }
502
+
429
503
  export declare function openVideoCtx(opts: VideoCtxOptions, label: string): Promise<CodecContext>;
430
504
 
505
+ export declare class OutputSink implements AsyncDisposable {
506
+ private _s;
507
+ private _disposed;
508
+ private constructor();
509
+ static kindFromPath(path: string): SinkKind;
510
+ static create(opts: SinkOptions): Promise<OutputSink>;
511
+ private static mp4Video;
512
+ private static webmVideo;
513
+ private static audioFor;
514
+ setInputRate(sampleRate: number): void;
515
+ encodeBGRA(bgraFrame: Frame): Promise<void>;
516
+ encodeDecodedFrame(src: Frame): Promise<void>;
517
+ encodeAudio(pcm: Buffer): Promise<void>;
518
+ flush(): Promise<void>;
519
+ [Symbol.asyncDispose](): Promise<void>;
520
+ private swEncode;
521
+ }
522
+
431
523
  export declare function packBits(bits: number[]): Buffer;
432
524
 
433
525
  declare function pargs(): string[];
@@ -438,10 +530,15 @@ declare function parseNumber(x: unknown): number;
438
530
  export { parseNumber }
439
531
  export { parseNumber as parseNumber_alias_1 }
440
532
 
533
+ export declare function parseNvencHevcConfig(extradata: Buffer): NvencHevcConfig;
534
+
441
535
  declare function parseString(x: unknown): string;
442
536
  export { parseString }
443
537
  export { parseString as parseString_alias_1 }
444
538
 
539
+ /** Patch every VPS/SPS NAL in an Annex B bitstream so PTL matches Apple/x265. */
540
+ export declare function patchHevcAlphaPtl(bitstream: Buffer): Buffer;
541
+
445
542
  export declare function pauseVirtualTime(cdp: Debugger): Promise<void>;
446
543
 
447
544
  declare function penv<T>(name: string, parser: EnvParser<T>, defaultValue: T): T;
@@ -463,6 +560,15 @@ declare interface ProcessHandle {
463
560
  export { ProcessHandle }
464
561
  export { ProcessHandle as ProcessHandle_alias_1 }
465
562
 
563
+ declare type ProgressCallback = (progress: number) => void;
564
+ export { ProgressCallback }
565
+ export { ProgressCallback as ProgressCallback_alias_1 }
566
+
567
+ export declare interface ProgressMsg {
568
+ type: IpcMsgType.PROGRESS;
569
+ value: number;
570
+ }
571
+
466
572
  export declare function proxiedUrl(url: string): string;
467
573
 
468
574
  declare function pup(source: string, options: Partial<PupOptions>): Promise<PupResult>;
@@ -477,17 +583,9 @@ declare const pupApp: string;
477
583
  export { pupApp }
478
584
  export { pupApp as pupApp_alias_1 }
479
585
 
480
- declare const pupDeterministic: boolean;
481
- export { pupDeterministic }
482
- export { pupDeterministic as pupDeterministic_alias_1 }
483
-
484
- declare const pupDisableGPU: boolean;
485
- export { pupDisableGPU }
486
- export { pupDisableGPU as pupDisableGPU_alias_1 }
487
-
488
- declare const pupDisableHwCodec: boolean;
489
- export { pupDisableHwCodec }
490
- export { pupDisableHwCodec as pupDisableHwCodec_alias_1 }
586
+ declare const pupAudioPreload: string;
587
+ export { pupAudioPreload }
588
+ export { pupAudioPreload as pupAudioPreload_alias_1 }
491
589
 
492
590
  declare const pupLogLevel: number;
493
591
  export { pupLogLevel }
@@ -495,7 +593,8 @@ export { pupLogLevel as pupLogLevel_alias_1 }
495
593
 
496
594
  declare interface PupOptions extends Partial<RenderOptions> {
497
595
  signal?: AbortSignal;
498
- onProgress?: PupProgressCallback;
596
+ onProgress?: ProgressCallback;
597
+ onConsole?: ConsoleCallback;
499
598
  }
500
599
  export { PupOptions }
501
600
  export { PupOptions as PupOptions_alias_1 }
@@ -504,27 +603,15 @@ declare const pupPkgRoot: string;
504
603
  export { pupPkgRoot }
505
604
  export { pupPkgRoot as pupPkgRoot_alias_1 }
506
605
 
507
- declare type PupProgressCallback = (progress: number) => Promise<void> | void;
508
- export { PupProgressCallback }
509
- export { PupProgressCallback as PupProgressCallback_alias_1 }
510
-
511
606
  declare interface PupResult extends RenderResult {
512
607
  }
513
608
  export { PupResult }
514
609
  export { PupResult as PupResult_alias_1 }
515
610
 
516
- declare const pupUseInnerProxy: boolean;
517
- export { pupUseInnerProxy }
518
- export { pupUseInnerProxy as pupUseInnerProxy_alias_1 }
519
-
520
- declare const pupWindowTolerant: boolean;
521
- export { pupWindowTolerant }
522
- export { pupWindowTolerant as pupWindowTolerant_alias_1 }
523
-
524
611
  /** Remove emulation prevention bytes (00 00 03 → 00 00) from RBSP. */
525
612
  export declare function removeEmulationPrevention(data: Buffer): Buffer;
526
613
 
527
- export declare function render(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
614
+ export declare function render(options: IPCRenderOptions): Promise<IpcDonePayload>;
528
615
 
529
616
  declare type RenderOptions = z.infer<typeof RenderSchema>;
530
617
  export { RenderOptions }
@@ -565,23 +652,51 @@ declare interface RetryOptions<Args extends any[], Ret> {
565
652
  export { RetryOptions }
566
653
  export { RetryOptions as RetryOptions_alias_1 }
567
654
 
655
+ /** Alpha PPS: pps_pic_parameter_set_id 0 → 1, pps_seq_parameter_set_id 0 → 1. */
656
+ export declare function rewriteAlphaPps(pps: Buffer): Buffer;
657
+
658
+ /**
659
+ * Rewrite alpha slice header: slice_pic_parameter_set_id 0 → 1.
660
+ * The +2-bit shift is absorbed by emitting a fresh byte_alignment then appending the
661
+ * original CABAC slice_segment_data bytes verbatim. CABAC byte boundary is preserved.
662
+ */
663
+ export declare function rewriteAlphaSliceHeader(slice: Buffer, nalType: number, cfg: NvencHevcConfig): Buffer;
664
+
665
+ /** Alpha SPS: sps_seq_parameter_set_id 0 → 1. */
666
+ export declare function rewriteAlphaSps(sps: Buffer): Buffer;
667
+
568
668
  /** Rewrite nuh_layer_id in a NAL unit (returns copy). */
569
669
  export declare function rewriteNalLayerId(nal: Buffer, layerId: number): Buffer;
570
670
 
571
- export declare function runElectronApp({ args, display }: RunElectronAppOptions): Promise<ProcessHandle>;
671
+ /** Rewrite nal_unit_type in a NAL unit (returns copy). */
672
+ export declare function rewriteNalType(nal: Buffer, newType: number): Buffer;
673
+
674
+ export declare function runElectronApp({ args }: RunElectronAppOptions): Promise<ProcessHandle>;
572
675
 
573
676
  export declare interface RunElectronAppOptions {
574
677
  args: unknown[];
575
- display?: number;
576
678
  }
577
679
 
578
- export declare function setInterceptor({ source, window, useInnerProxy }: NetworkOptions): void;
680
+ export declare function send(cdp: Debugger, method: string, params?: object): Promise<unknown>;
579
681
 
580
- export declare function setupAudioCapture({ encoder, getVideoTimeMs, onError, }: AudioCaptureOptions): Promise<AudioCapture>;
682
+ export declare function setInterceptor({ source, window, useInnerProxy }: NetworkOptions): void;
581
683
 
582
684
  export declare function setupPupProtocol(): void;
583
685
 
584
- export declare function shoot(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
686
+ export declare function shoot(options: IPCRenderOptions): Promise<IpcDonePayload>;
687
+
688
+ export declare type SinkKind = "mp4" | "webm";
689
+
690
+ export declare interface SinkOptions {
691
+ outFile: string;
692
+ kind: SinkKind;
693
+ width: number;
694
+ height: number;
695
+ fps: number;
696
+ withAudio: boolean;
697
+ disableHwCodec: boolean;
698
+ sharedHw?: HardwareContext;
699
+ }
585
700
 
586
701
  export declare function sizeEquals(a: Size, b: Size): boolean;
587
702
 
@@ -594,15 +709,13 @@ export declare function splitNalUnits(bitstream: Buffer): NalUnit[];
594
709
 
595
710
  export declare function startElectronCrashReporter(): void;
596
711
 
597
- export declare function startStego(cdp: Debugger): Promise<void>;
598
-
599
- export declare function startXvfb(width: number, height: number): XvfbHandle;
712
+ export declare function startStego(cdp: Debugger): Promise<unknown>;
600
713
 
601
714
  export declare const STEGO_TICK_CHANNEL = "stego-tick";
602
715
 
603
- export declare function stopStego(cdp: Debugger): Promise<void>;
716
+ export declare function stopStego(cdp: Debugger): Promise<unknown>;
604
717
 
605
- export declare function swapBuffer(cdp: Debugger, expected: number): Promise<void>;
718
+ export declare function swapBuffer(wc: WebContents, expected: number, interval: number): Promise<void>;
606
719
 
607
720
  export declare function tick(frame: WebFrameMain | undefined, timestampMs: number): Promise<void>;
608
721
 
@@ -631,6 +744,7 @@ export declare interface VideoCtxOptions {
631
744
  codecTag?: string;
632
745
  colorRange?: AVColorRange;
633
746
  options?: Record<string, string>;
747
+ hwFramesCtx?: HardwareFramesContext;
634
748
  }
635
749
 
636
750
  declare class VideoEncoder_2 implements Disposable {
@@ -659,19 +773,12 @@ export declare interface VideoEncoderOptions {
659
773
  muxer: FormatMuxer;
660
774
  }
661
775
 
662
- export declare interface VideoFactoryOptions {
663
- width: number;
664
- height: number;
665
- fps: number;
666
- bitrate?: number;
667
- disableHwCodec?: boolean;
668
- }
669
-
670
776
  export declare interface VideoSetup {
671
777
  video?: VideoEncoder_2;
672
778
  hwVideo?: HwEncoder;
673
779
  codec?: CodecState_2;
674
780
  hw?: HardwareContext;
781
+ ownsHw: boolean;
675
782
  }
676
783
 
677
784
  export declare class VideoToolboxEncoder implements Disposable {
@@ -700,17 +807,19 @@ export declare interface WaitOptions {
700
807
  onTimeout?: () => void;
701
808
  }
702
809
 
810
+ export declare type WindowCreatedCallback = (window: BrowserWindow) => void | Promise<void>;
811
+
703
812
  export declare interface WindowOptions {
704
813
  source: string;
705
- onCreated?: (window: BrowserWindow) => Promise<void>;
706
- renderer: RenderOptions;
707
- warmup?: boolean;
814
+ renderer: IPCRenderOptions;
708
815
  tolerant?: boolean;
816
+ preload?: string;
817
+ onCreated?: WindowCreatedCallback;
818
+ signal?: AbortSignal;
709
819
  }
710
820
 
711
- export declare interface XvfbHandle {
712
- display: number;
713
- stop(): void;
714
- }
821
+ declare function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T>;
822
+ export { withTimeout }
823
+ export { withTimeout as withTimeout_alias_1 }
715
824
 
716
825
  export { }