@bililive-tools/manager 1.1.0 → 1.2.0

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.
@@ -24,6 +24,7 @@ export declare class FFMPEGRecorder extends EventEmitter {
24
24
  inputOptions?: string[];
25
25
  isHls?: boolean;
26
26
  disableDanma?: boolean;
27
+ videoFormat?: "auto" | "ts" | "mkv";
27
28
  }, onEnd: (...args: unknown[]) => void);
28
29
  private createCommand;
29
30
  formatLine(line: string): {
@@ -19,7 +19,7 @@ export class FFMPEGRecorder extends EventEmitter {
19
19
  this.onEnd = onEnd;
20
20
  const hasSegment = !!opts.segment;
21
21
  this.disableDanma = opts.disableDanma ?? false;
22
- this.streamManager = new StreamManager(opts.getSavePath, hasSegment, this.disableDanma);
22
+ this.streamManager = new StreamManager(opts.getSavePath, hasSegment, this.disableDanma, opts.videoFormat);
23
23
  this.timeoutChecker = utils.createTimeoutChecker(() => this.onEnd("ffmpeg timeout"), 3 * 10e3);
24
24
  this.hasSegment = hasSegment;
25
25
  this.getSavePath = opts.getSavePath;
package/lib/recorder.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
15
15
  streamPriorities: string[];
16
16
  sourcePriorities: string[];
17
17
  formatPriorities?: string[];
18
+ source?: string;
18
19
  segment?: number;
19
20
  saveGiftDanma?: boolean;
20
21
  saveSCDanma?: boolean;
@@ -38,6 +39,8 @@ export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
38
39
  api?: "auto" | "web" | "mp";
39
40
  /** 标题关键词,如果直播间标题包含这些关键词,则不会自动录制(仅对斗鱼有效),多个关键词用英文逗号分隔 */
40
41
  titleKeywords?: string;
42
+ /** 用于指定录制文件格式,auto时,分段使用ts,不分段使用mp4 */
43
+ videoFormat?: "auto" | "ts" | "mkv";
41
44
  extra?: Partial<E>;
42
45
  }
43
46
  export type SerializedRecorder<E extends AnyObject> = PickRequired<RecorderCreateOpts<E>, "id">;
@@ -12,18 +12,22 @@ export declare class Segment extends EventEmitter {
12
12
  /** 输出文件名名,不包含拓展名 */
13
13
  outputVideoFilePath: string;
14
14
  disableDanma: boolean;
15
- constructor(getSavePath: GetSavePath, disableDanma: boolean);
15
+ videoExt: "ts" | "mkv" | "mp4";
16
+ constructor(getSavePath: GetSavePath, disableDanma: boolean, videoExt: "ts" | "mkv" | "mp4");
16
17
  handleSegmentEnd(): Promise<void>;
17
18
  onSegmentStart(stderrLine: string): Promise<void>;
19
+ get outputFilePath(): string;
18
20
  }
19
21
  export declare class StreamManager extends EventEmitter {
20
22
  private segment;
21
23
  private extraDataController;
22
24
  recordSavePath: string;
23
25
  recordStartTime?: number;
24
- constructor(getSavePath: GetSavePath, hasSegment: boolean, disableDanma: boolean);
26
+ private videoFormat?;
27
+ constructor(getSavePath: GetSavePath, hasSegment: boolean, disableDanma: boolean, videoFormat?: "auto" | "ts" | "mkv");
25
28
  handleVideoStarted(stderrLine: string): Promise<void>;
26
29
  handleVideoCompleted(): Promise<void>;
27
30
  getExtraDataController(): import("./record_extra_data_controller.js").RecordExtraDataController | null;
31
+ get videoExt(): "ts" | "mkv" | "mp4";
28
32
  get videoFilePath(): string;
29
33
  }
@@ -11,10 +11,12 @@ export class Segment extends EventEmitter {
11
11
  /** 输出文件名名,不包含拓展名 */
12
12
  outputVideoFilePath;
13
13
  disableDanma;
14
- constructor(getSavePath, disableDanma) {
14
+ videoExt;
15
+ constructor(getSavePath, disableDanma, videoExt) {
15
16
  super();
16
17
  this.getSavePath = getSavePath;
17
18
  this.disableDanma = disableDanma;
19
+ this.videoExt = videoExt;
18
20
  }
19
21
  async handleSegmentEnd() {
20
22
  if (!this.outputVideoFilePath) {
@@ -26,10 +28,10 @@ export class Segment extends EventEmitter {
26
28
  }
27
29
  try {
28
30
  await Promise.all([
29
- fs.rename(this.rawRecordingVideoPath, `${this.outputVideoFilePath}.ts`),
31
+ fs.rename(this.rawRecordingVideoPath, this.outputFilePath),
30
32
  this.extraDataController?.flush(),
31
33
  ]);
32
- this.emit("videoFileCompleted", { filename: `${this.outputVideoFilePath}.ts` });
34
+ this.emit("videoFileCompleted", { filename: this.outputFilePath });
33
35
  }
34
36
  catch (err) {
35
37
  this.emit("DebugLog", {
@@ -56,24 +58,29 @@ export class Segment extends EventEmitter {
56
58
  if (match) {
57
59
  const filename = match[1];
58
60
  this.rawRecordingVideoPath = filename;
59
- this.emit("videoFileCreated", { filename: `${this.outputVideoFilePath}.ts` });
61
+ this.emit("videoFileCreated", { filename: this.outputFilePath });
60
62
  }
61
63
  else {
62
64
  this.emit("DebugLog", { type: "ffmpeg", text: "No match found" });
63
65
  }
64
66
  }
67
+ get outputFilePath() {
68
+ return `${this.outputVideoFilePath}.${this.videoExt}`;
69
+ }
65
70
  }
66
71
  export class StreamManager extends EventEmitter {
67
72
  segment = null;
68
73
  extraDataController = null;
69
74
  recordSavePath;
70
75
  recordStartTime;
71
- constructor(getSavePath, hasSegment, disableDanma) {
76
+ videoFormat;
77
+ constructor(getSavePath, hasSegment, disableDanma, videoFormat) {
72
78
  super();
73
79
  const recordSavePath = getSavePath({ startTime: Date.now() });
74
80
  this.recordSavePath = recordSavePath;
81
+ this.videoFormat = videoFormat;
75
82
  if (hasSegment) {
76
- this.segment = new Segment(getSavePath, disableDanma);
83
+ this.segment = new Segment(getSavePath, disableDanma, this.videoExt);
77
84
  this.segment.on("DebugLog", (data) => {
78
85
  this.emit("DebugLog", data);
79
86
  });
@@ -121,7 +128,20 @@ export class StreamManager extends EventEmitter {
121
128
  getExtraDataController() {
122
129
  return this.segment?.extraDataController || this.extraDataController;
123
130
  }
131
+ get videoExt() {
132
+ if (this.videoFormat === "mkv") {
133
+ return "mkv";
134
+ }
135
+ else if (this.videoFormat === "auto") {
136
+ if (!this.segment) {
137
+ return "mp4";
138
+ }
139
+ }
140
+ return "ts";
141
+ }
124
142
  get videoFilePath() {
125
- return this.segment ? `${this.recordSavePath}-PART%03d.ts` : `${this.recordSavePath}.ts`;
143
+ return this.segment
144
+ ? `${this.recordSavePath}-PART%03d.${this.videoExt}`
145
+ : `${this.recordSavePath}.${this.videoExt}`;
126
146
  }
127
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/manager",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Batch scheduling recorders",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",