@napuketto/media 0.0.4 → 0.0.5
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/dist/index.cjs +99 -47
- package/dist/index.d.cts +9 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +99 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2804,7 +2804,7 @@ function parseMilliseconds(milliseconds) {
|
|
|
2804
2804
|
throw new TypeError("Expected a finite number or bigint");
|
|
2805
2805
|
}
|
|
2806
2806
|
//#endregion
|
|
2807
|
-
//#region ../../node_modules/.pnpm/pretty-ms@9.3.
|
|
2807
|
+
//#region ../../node_modules/.pnpm/pretty-ms@9.3.1/node_modules/pretty-ms/index.js
|
|
2808
2808
|
const isZero = (value) => value === 0 || value === 0n;
|
|
2809
2809
|
const pluralize = (word, count) => count === 1 || count === 1n ? word : `${word}s`;
|
|
2810
2810
|
const SECOND_ROUNDING_EPSILON = 1e-7;
|
|
@@ -2867,7 +2867,9 @@ function prettyMilliseconds(milliseconds, options) {
|
|
|
2867
2867
|
} else {
|
|
2868
2868
|
const millisecondsAndBelow = milliseconds + microseconds / 1e3 + nanoseconds / 1e6;
|
|
2869
2869
|
const millisecondsDecimalDigits = typeof options.millisecondsDecimalDigits === "number" ? options.millisecondsDecimalDigits : 0;
|
|
2870
|
-
const
|
|
2870
|
+
const roundedMilliseconds = millisecondsAndBelow >= 1 ? Math.round(millisecondsAndBelow) : Math.ceil(millisecondsAndBelow);
|
|
2871
|
+
const maximumMilliseconds = 1e3 - 10 ** -millisecondsDecimalDigits;
|
|
2872
|
+
const millisecondsString = millisecondsDecimalDigits ? Math.min(millisecondsAndBelow, maximumMilliseconds).toFixed(millisecondsDecimalDigits) : Math.min(roundedMilliseconds, maximumMilliseconds);
|
|
2871
2873
|
add(Number.parseFloat(millisecondsString), "millisecond", "ms", millisecondsString);
|
|
2872
2874
|
}
|
|
2873
2875
|
} else {
|
|
@@ -7523,7 +7525,7 @@ var require_ms = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
7523
7525
|
}
|
|
7524
7526
|
}));
|
|
7525
7527
|
//#endregion
|
|
7526
|
-
//#region ../../node_modules/.pnpm/debug@4.4.
|
|
7528
|
+
//#region ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js
|
|
7527
7529
|
var require_common = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7528
7530
|
/**
|
|
7529
7531
|
* This is the common logic for both the Node.js and web browser
|
|
@@ -7726,7 +7728,7 @@ var require_common = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
7726
7728
|
module.exports = setup;
|
|
7727
7729
|
}));
|
|
7728
7730
|
//#endregion
|
|
7729
|
-
//#region ../../node_modules/.pnpm/debug@4.4.
|
|
7731
|
+
//#region ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js
|
|
7730
7732
|
var require_browser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7731
7733
|
/**
|
|
7732
7734
|
* This is the web browser implementation of `debug()`.
|
|
@@ -7932,19 +7934,21 @@ var require_has_flag = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
7932
7934
|
};
|
|
7933
7935
|
}));
|
|
7934
7936
|
//#endregion
|
|
7935
|
-
//#region ../../node_modules/.pnpm/supports-color@
|
|
7937
|
+
//#region ../../node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js
|
|
7936
7938
|
var require_supports_color = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7937
7939
|
const os = __require("os");
|
|
7938
7940
|
const tty$2 = __require("tty");
|
|
7939
7941
|
const hasFlag = require_has_flag();
|
|
7940
7942
|
const { env } = process;
|
|
7941
|
-
let
|
|
7942
|
-
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never"))
|
|
7943
|
-
else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always"))
|
|
7944
|
-
|
|
7945
|
-
if (
|
|
7946
|
-
|
|
7947
|
-
|
|
7943
|
+
let flagForceColor;
|
|
7944
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
|
|
7945
|
+
else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
|
|
7946
|
+
function envForceColor() {
|
|
7947
|
+
if ("FORCE_COLOR" in env) {
|
|
7948
|
+
if (env.FORCE_COLOR === "true") return 1;
|
|
7949
|
+
if (env.FORCE_COLOR === "false") return 0;
|
|
7950
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
7951
|
+
}
|
|
7948
7952
|
}
|
|
7949
7953
|
function translateLevel(level) {
|
|
7950
7954
|
if (level === 0) return false;
|
|
@@ -7955,10 +7959,15 @@ var require_supports_color = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
7955
7959
|
has16m: level >= 3
|
|
7956
7960
|
};
|
|
7957
7961
|
}
|
|
7958
|
-
function supportsColor(haveStream, streamIsTTY) {
|
|
7962
|
+
function supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
7963
|
+
const noFlagForceColor = envForceColor();
|
|
7964
|
+
if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
|
|
7965
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
7959
7966
|
if (forceColor === 0) return 0;
|
|
7960
|
-
if (
|
|
7961
|
-
|
|
7967
|
+
if (sniffFlags) {
|
|
7968
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
|
|
7969
|
+
if (hasFlag("color=256")) return 2;
|
|
7970
|
+
}
|
|
7962
7971
|
if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
|
|
7963
7972
|
const min = forceColor || 0;
|
|
7964
7973
|
if (env.TERM === "dumb") return min;
|
|
@@ -7974,14 +7983,15 @@ var require_supports_color = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
7974
7983
|
"APPVEYOR",
|
|
7975
7984
|
"GITLAB_CI",
|
|
7976
7985
|
"GITHUB_ACTIONS",
|
|
7977
|
-
"BUILDKITE"
|
|
7986
|
+
"BUILDKITE",
|
|
7987
|
+
"DRONE"
|
|
7978
7988
|
].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
|
|
7979
7989
|
return min;
|
|
7980
7990
|
}
|
|
7981
7991
|
if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
7982
7992
|
if (env.COLORTERM === "truecolor") return 3;
|
|
7983
7993
|
if ("TERM_PROGRAM" in env) {
|
|
7984
|
-
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
7994
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
7985
7995
|
switch (env.TERM_PROGRAM) {
|
|
7986
7996
|
case "iTerm.app": return version >= 3 ? 3 : 2;
|
|
7987
7997
|
case "Apple_Terminal": return 2;
|
|
@@ -7992,17 +8002,20 @@ var require_supports_color = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
7992
8002
|
if ("COLORTERM" in env) return 1;
|
|
7993
8003
|
return min;
|
|
7994
8004
|
}
|
|
7995
|
-
function getSupportLevel(stream) {
|
|
7996
|
-
return translateLevel(supportsColor(stream,
|
|
8005
|
+
function getSupportLevel(stream, options = {}) {
|
|
8006
|
+
return translateLevel(supportsColor(stream, {
|
|
8007
|
+
streamIsTTY: stream && stream.isTTY,
|
|
8008
|
+
...options
|
|
8009
|
+
}));
|
|
7997
8010
|
}
|
|
7998
8011
|
module.exports = {
|
|
7999
8012
|
supportsColor: getSupportLevel,
|
|
8000
|
-
stdout:
|
|
8001
|
-
stderr:
|
|
8013
|
+
stdout: getSupportLevel({ isTTY: tty$2.isatty(1) }),
|
|
8014
|
+
stderr: getSupportLevel({ isTTY: tty$2.isatty(2) })
|
|
8002
8015
|
};
|
|
8003
8016
|
}));
|
|
8004
8017
|
//#endregion
|
|
8005
|
-
//#region ../../node_modules/.pnpm/debug@4.4.
|
|
8018
|
+
//#region ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js
|
|
8006
8019
|
var require_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8007
8020
|
/**
|
|
8008
8021
|
* Module dependencies.
|
|
@@ -8574,7 +8587,7 @@ function getUintBE(view) {
|
|
|
8574
8587
|
if (byteLength === 1) return view.getUint8(0);
|
|
8575
8588
|
}
|
|
8576
8589
|
//#endregion
|
|
8577
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
8590
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/tokens.js
|
|
8578
8591
|
function stringToBytes(string, encoding) {
|
|
8579
8592
|
if (encoding === "utf-16le") {
|
|
8580
8593
|
const bytes = [];
|
|
@@ -8618,7 +8631,7 @@ const uint32SyncSafeToken = {
|
|
|
8618
8631
|
len: 4
|
|
8619
8632
|
};
|
|
8620
8633
|
//#endregion
|
|
8621
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
8634
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/supported.js
|
|
8622
8635
|
const extensions = [
|
|
8623
8636
|
"jpg",
|
|
8624
8637
|
"png",
|
|
@@ -8985,7 +8998,7 @@ const mimeTypes = [
|
|
|
8985
8998
|
"application/vnd.apple.pages"
|
|
8986
8999
|
];
|
|
8987
9000
|
//#endregion
|
|
8988
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9001
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/parser.js
|
|
8989
9002
|
const maximumUntrustedSkipSizeInBytes = 16777216;
|
|
8990
9003
|
var ParserHardLimitError = class extends Error {};
|
|
8991
9004
|
function getSafeBound(value, maximum, reason) {
|
|
@@ -9021,7 +9034,7 @@ function hasExceededUnknownSizeScanBudget(tokenizer, startOffset, maximumBytes)
|
|
|
9021
9034
|
return hasUnknownFileSize(tokenizer) && tokenizer.position - startOffset > maximumBytes;
|
|
9022
9035
|
}
|
|
9023
9036
|
//#endregion
|
|
9024
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9037
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/detectors/zip.js
|
|
9025
9038
|
const maximumZipEntrySizeInBytes = 1048576;
|
|
9026
9039
|
const maximumZipEntryCount = 1024;
|
|
9027
9040
|
const maximumZipBufferedReadSizeInBytes = 2 ** 31 - 1;
|
|
@@ -9056,11 +9069,13 @@ async function decompressDeflateRawWithLimit(data, { maximumLength = maximumZipE
|
|
|
9056
9069
|
if (done) break;
|
|
9057
9070
|
totalLength += value.length;
|
|
9058
9071
|
if (totalLength > maximumLength) {
|
|
9059
|
-
await reader.cancel();
|
|
9072
|
+
await reader.cancel().catch(() => {});
|
|
9060
9073
|
throw new Error(`ZIP entry decompressed data exceeds ${maximumLength} bytes`);
|
|
9061
9074
|
}
|
|
9062
9075
|
chunks.push(value);
|
|
9063
9076
|
}
|
|
9077
|
+
} catch (error) {
|
|
9078
|
+
if (error.code !== "ERR_TRAILING_JUNK_AFTER_STREAM_END") throw error;
|
|
9064
9079
|
} finally {
|
|
9065
9080
|
reader.releaseLock();
|
|
9066
9081
|
}
|
|
@@ -9453,7 +9468,7 @@ async function detectZip(tokenizer) {
|
|
|
9453
9468
|
};
|
|
9454
9469
|
}
|
|
9455
9470
|
//#endregion
|
|
9456
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9471
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/detectors/ebml.js
|
|
9457
9472
|
const maximumEbmlDocumentTypeSizeInBytes = 64;
|
|
9458
9473
|
const maximumEbmlElementPayloadSizeInBytes = 1048576;
|
|
9459
9474
|
const maximumEbmlElementCount = 256;
|
|
@@ -9521,7 +9536,7 @@ async function detectEbml(tokenizer) {
|
|
|
9521
9536
|
}
|
|
9522
9537
|
}
|
|
9523
9538
|
//#endregion
|
|
9524
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9539
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/detectors/png.js
|
|
9525
9540
|
const maximumPngChunkCount = 512;
|
|
9526
9541
|
const maximumPngStreamScanBudgetInBytes = 16777216;
|
|
9527
9542
|
const maximumPngChunkSizeInBytes = 1048576;
|
|
@@ -9580,7 +9595,7 @@ async function detectPng(tokenizer) {
|
|
|
9580
9595
|
return pngFileType;
|
|
9581
9596
|
}
|
|
9582
9597
|
//#endregion
|
|
9583
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9598
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/detectors/asf.js
|
|
9584
9599
|
const maximumAsfHeaderObjectCount = 512;
|
|
9585
9600
|
const maximumAsfHeaderPayloadSizeInBytes = 1048576;
|
|
9586
9601
|
async function detectAsf(tokenizer) {
|
|
@@ -9707,12 +9722,12 @@ async function detectAsf(tokenizer) {
|
|
|
9707
9722
|
};
|
|
9708
9723
|
}
|
|
9709
9724
|
//#endregion
|
|
9710
|
-
//#region ../../node_modules/.pnpm/file-type@22.0.
|
|
9725
|
+
//#region ../../node_modules/.pnpm/file-type@22.0.2/node_modules/file-type/source/index.js
|
|
9711
9726
|
/**
|
|
9712
9727
|
Primary entry point, Node.js specific entry point is index.js
|
|
9713
9728
|
*/
|
|
9714
9729
|
const reasonableDetectionSizeInBytes = 4100;
|
|
9715
|
-
const maximumMpegOffsetTolerance =
|
|
9730
|
+
const maximumMpegOffsetTolerance = 4096;
|
|
9716
9731
|
const maximumNestedGzipDetectionSizeInBytes = maximumUntrustedSkipSizeInBytes;
|
|
9717
9732
|
const maximumNestedGzipProbeDepth = 1;
|
|
9718
9733
|
const unknownSizeGzipProbeTimeoutInMilliseconds = 100;
|
|
@@ -11305,10 +11320,10 @@ var FileTypeParser = class FileTypeParser {
|
|
|
11305
11320
|
mime: "image/x-icon"
|
|
11306
11321
|
};
|
|
11307
11322
|
await tokenizer.peekBuffer(this.buffer, {
|
|
11308
|
-
length: Math.min(
|
|
11323
|
+
length: Math.min(4 + this.options.mpegOffsetTolerance, fileSize),
|
|
11309
11324
|
mayBeLess: true
|
|
11310
11325
|
});
|
|
11311
|
-
if (this.buffer.length >=
|
|
11326
|
+
if (this.buffer.length >= 4 + this.options.mpegOffsetTolerance) for (let depth = 0; depth <= this.options.mpegOffsetTolerance; ++depth) {
|
|
11312
11327
|
const type = this.scanMpeg(depth);
|
|
11313
11328
|
if (type) return type;
|
|
11314
11329
|
}
|
|
@@ -11394,19 +11409,23 @@ var FileTypeParser = class FileTypeParser {
|
|
|
11394
11409
|
if (this.check([16], {
|
|
11395
11410
|
offset: offset + 1,
|
|
11396
11411
|
mask: [22]
|
|
11397
|
-
})) {
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
}
|
|
11412
|
+
})) return {
|
|
11413
|
+
ext: "aac",
|
|
11414
|
+
mime: "audio/aac"
|
|
11415
|
+
};
|
|
11416
|
+
if (this.check([255, 254], { offset })) return;
|
|
11417
|
+
if (this.check([8], {
|
|
11418
|
+
offset: offset + 1,
|
|
11419
|
+
mask: [24]
|
|
11420
|
+
})) return;
|
|
11421
|
+
if (this.check([240], {
|
|
11422
|
+
offset: offset + 2,
|
|
11423
|
+
mask: [240]
|
|
11424
|
+
})) return;
|
|
11425
|
+
if (this.check([12], {
|
|
11426
|
+
offset: offset + 2,
|
|
11427
|
+
mask: [12]
|
|
11428
|
+
})) return;
|
|
11410
11429
|
if (this.check([2], {
|
|
11411
11430
|
offset: offset + 1,
|
|
11412
11431
|
mask: [6]
|
|
@@ -11470,6 +11489,7 @@ async function detectFileType(input) {
|
|
|
11470
11489
|
* ffmpeg 由 execa 以子进程方式调用(非 node 内置),依赖系统 PATH 中的 ffmpeg。
|
|
11471
11490
|
* - `transcodeVideo`:转码 / 缩放 / 帧率
|
|
11472
11491
|
* - `getVideoInfo`:解析 ffprobe 输出取宽高与时长
|
|
11492
|
+
* - `extractVideoFrame`:抽首帧作缩略图(QQ 视频消息发送需要)
|
|
11473
11493
|
*/
|
|
11474
11494
|
const MS_PER_SECOND = 1e3;
|
|
11475
11495
|
/** 替换扩展名(保持目录,父目录由调用方保证存在)。 */
|
|
@@ -11544,7 +11564,38 @@ async function getVideoInfo(input) {
|
|
|
11544
11564
|
durationMs: Math.round(Number(durationStr) * MS_PER_SECOND)
|
|
11545
11565
|
};
|
|
11546
11566
|
}
|
|
11567
|
+
/**
|
|
11568
|
+
* 抽视频首帧为 PNG 缩略图(QQ 视频消息发送契约:thumbPath 指向真实图片文件)。
|
|
11569
|
+
*
|
|
11570
|
+
* 固定 `-ss 0` 取首帧:QQ 缩略图只需要一张可解码的封面,首帧最稳定
|
|
11571
|
+
* (部分视频首帧为黑屏时可改 1s,此处不引入额外配置)。转码失败 / ffmpeg
|
|
11572
|
+
* 缺失 / 输出未生成均抛 MediaError,由调用方决定降级策略。
|
|
11573
|
+
*/
|
|
11574
|
+
async function extractVideoFrame(input, outputPath) {
|
|
11575
|
+
const args = [
|
|
11576
|
+
"-y",
|
|
11577
|
+
"-ss",
|
|
11578
|
+
"0",
|
|
11579
|
+
"-i",
|
|
11580
|
+
input,
|
|
11581
|
+
"-frames:v",
|
|
11582
|
+
"1",
|
|
11583
|
+
"-q:v",
|
|
11584
|
+
"3",
|
|
11585
|
+
"-f",
|
|
11586
|
+
"image2",
|
|
11587
|
+
outputPath
|
|
11588
|
+
];
|
|
11589
|
+
let exitCode;
|
|
11590
|
+
try {
|
|
11591
|
+
exitCode = (await execa("ffmpeg", args, { reject: false })).exitCode;
|
|
11592
|
+
} catch (err) {
|
|
11593
|
+
throw new MediaError(`ffmpeg 不可用或抽帧失败: ${input}`, { cause: err });
|
|
11594
|
+
}
|
|
11595
|
+
if (exitCode !== 0 || !existsSync(outputPath)) throw new MediaError(`ffmpeg 抽帧失败: ${input}(exit ${exitCode ?? "?"})`);
|
|
11596
|
+
return outputPath;
|
|
11597
|
+
}
|
|
11547
11598
|
//#endregion
|
|
11548
|
-
export { MediaError, SILK_SAMPLE_RATE, decodeSilkToPcm, decodeSilkToWav, detectFileType, downloadUrl, encodePcmToSilk, getImageSize, getSilkInfo, getVideoInfo, inferExtension, transcodeVideo };
|
|
11599
|
+
export { MediaError, SILK_SAMPLE_RATE, decodeSilkToPcm, decodeSilkToWav, detectFileType, downloadUrl, encodePcmToSilk, extractVideoFrame, getImageSize, getSilkInfo, getVideoInfo, inferExtension, transcodeVideo };
|
|
11549
11600
|
|
|
11550
11601
|
//# sourceMappingURL=index.mjs.map
|