@napuketto/media 0.2.3 → 0.4.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.
- package/dist/index.d.mts +31 -40
- package/dist/index.mjs +651 -316
- package/dist/silk-worker.d.mts +1 -0
- package/dist/silk-worker.mjs +8 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -34,10 +34,16 @@ interface VideoInfo {
|
|
|
34
34
|
/** 时长(毫秒)。 */
|
|
35
35
|
durationMs: number;
|
|
36
36
|
}
|
|
37
|
+
interface MediaOperationOptions {
|
|
38
|
+
signal?: AbortSignal | undefined;
|
|
39
|
+
}
|
|
37
40
|
/** 视频转码选项。 */
|
|
38
|
-
interface TranscodeOptions {
|
|
41
|
+
interface TranscodeOptions extends MediaOperationOptions {
|
|
42
|
+
/** 偶整数,2–4096。只指定一边时保持比例。 */
|
|
39
43
|
width?: number | undefined;
|
|
44
|
+
/** 偶整数,2–4096。 */
|
|
40
45
|
height?: number | undefined;
|
|
46
|
+
/** 有限数,1–60。 */
|
|
41
47
|
fps?: number | undefined;
|
|
42
48
|
}
|
|
43
49
|
/** SILK 解码产物(pcm_s16le)。 */
|
|
@@ -53,44 +59,35 @@ export declare class MediaError extends Error {
|
|
|
53
59
|
}
|
|
54
60
|
/** SILK 默认采样率(Hz)。 */
|
|
55
61
|
export declare const SILK_SAMPLE_RATE = 24e3;
|
|
62
|
+
export declare const MAX_AUDIO_SECONDS = 600;
|
|
63
|
+
export declare const MAX_AUDIO_INPUT_BYTES: number;
|
|
56
64
|
/** 解码 SILK 音频为 PCM(pcm_s16le)。 */
|
|
57
|
-
export declare function decodeSilkToPcm(input: string, sampleRate?: number): Promise<DecodedAudio>;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/** 采样率(缺省 24000,QQ 语音协议值)。 */
|
|
65
|
+
export declare function decodeSilkToPcm(input: string, sampleRate?: number, { signal }?: MediaOperationOptions): Promise<DecodedAudio>;
|
|
66
|
+
interface DecodeSilkToWavOptions extends MediaOperationOptions {
|
|
67
|
+
/** 缺省 24 kHz。 */
|
|
61
68
|
sampleRate?: number | undefined;
|
|
62
|
-
/**
|
|
69
|
+
/** 缺省输入同目录。 */
|
|
63
70
|
outDir?: string | undefined;
|
|
64
71
|
}
|
|
65
|
-
/** 解码结果(WAV)。 */
|
|
66
72
|
interface DecodedWav {
|
|
67
73
|
wavPath: string;
|
|
68
74
|
durationMs: number;
|
|
69
75
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*/
|
|
75
|
-
export declare function
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
* - 已是 SILK → 原样返回
|
|
80
|
-
* - 单声道 16-bit PCM WAV / 显式采样率的原始 pcm_s16le → silk-wasm 直接编码
|
|
81
|
-
* - 其余(立体声/浮点/非 16-bit WAV、mp3/ogg/amr/flac 等)→ ffmpeg 归一化为
|
|
82
|
-
* 24000Hz 单声道 pcm_s16le → silk-wasm 编码
|
|
83
|
-
*/
|
|
84
|
-
export declare function encodePcmToSilk(input: string, sampleRate?: number): Promise<string>;
|
|
85
|
-
/** 获取 SILK 音频信息(时长 / 采样率)。 */
|
|
86
|
-
export declare function getSilkInfo(input: string, sampleRate?: number): Promise<AudioInfo>;
|
|
76
|
+
/** 解码 SILK 为可播放 WAV,返回的文件由调用方管理。 */
|
|
77
|
+
export declare function decodeSilkToWav(input: string, { sampleRate, outDir, signal }?: DecodeSilkToWavOptions): Promise<DecodedWav>;
|
|
78
|
+
/** 编码音频为 SILK;已通过边界检查的 SILK 原样返回。 */
|
|
79
|
+
export declare function encodePcmToSilk(input: string, sampleRate?: number, { signal }?: MediaOperationOptions): Promise<string>;
|
|
80
|
+
/** 获取 SILK 音频时长。SILK 容器不携带采样率,返回调用方指定值。 */
|
|
81
|
+
export declare function getSilkInfo(input: string, sampleRate?: number, { signal }?: MediaOperationOptions): Promise<AudioInfo>;
|
|
82
|
+
/** 按协议调用方的信任边界选择远程媒体出站模式。 */
|
|
83
|
+
type MediaOutboundPolicy = "public-only" | "compat";
|
|
87
84
|
/** 下载选项。 */
|
|
88
85
|
interface DownloadUrlOptions {
|
|
89
86
|
/** 超时毫秒(缺省 15s,覆盖整个下载过程)。 */
|
|
90
87
|
timeoutMs?: number | undefined;
|
|
91
88
|
/** 大小上限字节(缺省 30MB)。 */
|
|
92
89
|
maxBytes?: number | undefined;
|
|
93
|
-
/**
|
|
90
|
+
/** 初始源的附加请求头。传输/路由头忽略,跨源重定向清空所有调用者头。 */
|
|
94
91
|
headers?: Record<string, string> | undefined;
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
@@ -100,23 +97,17 @@ interface DownloadUrlOptions {
|
|
|
100
97
|
*/
|
|
101
98
|
export declare function downloadUrl(url: string, dest: string, options?: DownloadUrlOptions): Promise<number>;
|
|
102
99
|
/** 下载公网 HTTP(S) URL。每一跳校验实际连接使用的地址。 */
|
|
103
|
-
export declare function downloadPublicUrl(url: string, dest: string, options?:
|
|
100
|
+
export declare function downloadPublicUrl(url: string, dest: string, options?: DownloadUrlOptions): Promise<number>;
|
|
104
101
|
/** 从 Content-Type / URL 路径推断扩展名(缺省 .bin;下载命名用)。 */
|
|
105
102
|
export declare function inferExtension(contentType: string | null, url: string): string;
|
|
106
|
-
/**
|
|
107
|
-
export declare function getImageSize(input: string): Promise<ImageSize>;
|
|
103
|
+
/** 只读取有限的图片头部,尺寸元数据须在前 512 KiB 内。 */
|
|
104
|
+
export declare function getImageSize(input: string, { signal }?: MediaOperationOptions): Promise<ImageSize>;
|
|
108
105
|
/** 检测文件类型(魔数识别,返回 undefined 时抛 MediaError)。 */
|
|
109
|
-
export declare function detectFileType(input: string): Promise<FileTypeResult>;
|
|
106
|
+
export declare function detectFileType(input: string, { signal }?: MediaOperationOptions): Promise<FileTypeResult>;
|
|
110
107
|
/** 转码到独占目录。成功后调用方拥有输出文件及其父临时目录,消费结束后负责删除。 */
|
|
111
108
|
export declare function transcodeVideo(input: string, opts?: TranscodeOptions): Promise<string>;
|
|
112
|
-
/**
|
|
113
|
-
export declare function getVideoInfo(input: string): Promise<VideoInfo>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* 固定 `-ss 0` 取首帧:QQ 缩略图只需要一张可解码的封面,首帧最稳定
|
|
118
|
-
* (部分视频首帧为黑屏时可改 1s,此处不引入额外配置)。转码失败 / ffmpeg
|
|
119
|
-
* 缺失 / 输出未生成均抛 MediaError,由调用方决定降级策略。
|
|
120
|
-
*/
|
|
121
|
-
export declare function extractVideoFrame(input: string, outputPath: string): Promise<string>;
|
|
122
|
-
export type { AudioInfo, DecodeSilkToWavOptions, DecodedAudio, DecodedWav, DownloadUrlOptions, FileTypeResult, ImageSize, TranscodeOptions, VideoInfo };
|
|
109
|
+
/** 读取视频显示尺寸与时长。 */
|
|
110
|
+
export declare function getVideoInfo(input: string, { signal }?: MediaOperationOptions): Promise<VideoInfo>;
|
|
111
|
+
/** 抽首帧至调用者指定路径。失败时保留原目标。 */
|
|
112
|
+
export declare function extractVideoFrame(input: string, outputPath: string, { signal }?: MediaOperationOptions): Promise<string>;
|
|
113
|
+
export type { AudioInfo, DecodeSilkToWavOptions, DecodedAudio, DecodedWav, DownloadUrlOptions, FileTypeResult, ImageSize, MediaOperationOptions, MediaOutboundPolicy, TranscodeOptions, VideoInfo };
|