UNPKG

chzzk-z

Version:

chzzk-z is naver streaming platform Chzzk Library

85 lines 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StreamRecorder = void 0; const node_child_process_1 = require("node:child_process"); const node_path_1 = require("node:path"); class StreamRecorder { constructor(streamUrl, outputDir, segmentTime = 10) { this.streamUrl = streamUrl; this.outputDir = outputDir; this.segmentTime = segmentTime; } async start() { this.streamlinkProcess = (0, node_child_process_1.spawn)("streamlink", [ "--http-header", "User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", "--http-header", "Referer=https://chzzk.naver.com/", "--http-header", "Origin=https://chzzk.naver.com", "-O", this.streamUrl, "best", ]); this.videoProcess = (0, node_child_process_1.spawn)("ffmpeg", [ "-i", "-", "-map", "0:v", "-c:v", "copy", "-f", "segment", "-segment_time", this.segmentTime.toString(), "-reset_timestamps", "1", (0, node_path_1.join)(this.outputDir, "video_%03d.mp4"), ]); this.audioProcess = (0, node_child_process_1.spawn)("ffmpeg", [ "-i", "-", "-map", "0:a", "-c:a", "copy", "-f", "segment", "-segment_time", this.segmentTime.toString(), "-reset_timestamps", "1", (0, node_path_1.join)(this.outputDir, "audio_%03d.aac"), ]); this.captureProcess = (0, node_child_process_1.spawn)("ffmpeg", [ "-i", "-", "-vf", "fps=0.1", (0, node_path_1.join)(this.outputDir, "capture_%03d.jpg"), ]); this.streamlinkProcess.stdout.pipe(this.videoProcess.stdin); this.streamlinkProcess.stdout.pipe(this.audioProcess.stdin); this.streamlinkProcess.stdout.pipe(this.captureProcess.stdin); this.streamlinkProcess.stderr.on("data", (data) => { console.error(`Streamlink error: ${data}`); }); this.videoProcess.stderr.on("data", (data) => { console.error(`Video ffmpeg error: ${data}`); }); this.audioProcess.stderr.on("data", (data) => { console.error(`Audio ffmpeg error: ${data}`); }); this.captureProcess.stderr.on("data", (data) => { console.error(`Capture ffmpeg error: ${data}`); }); } stop() { this.streamlinkProcess?.kill(); this.videoProcess?.kill(); this.audioProcess?.kill(); this.captureProcess?.kill(); } } exports.StreamRecorder = StreamRecorder; //# sourceMappingURL=stream-recorder.js.map