NapCatQQ/src/common/ffmpeg-addon.ts
手瓜一十雪 e37fa59b8c
feat: 4.9.0 New Capability (#1331)
* fix: get_group_info ownerUin is "0"

* Add native module loading and improve logging

Loaded a native module in NTQQGroupApi and added test calls to sendSsoCmdReqByContend with different parameter types. Changed fileLog default to true in config. Enhanced NativePacketClient with detailed send/receive logging. Updated NodeIKernelMsgService to accept unknown type for sendSsoCmdReqByContend param. Added process PID logging in napcat shell.

* feat: new napcat-4.9.0-beta

* feat: Add FFmpeg native addon and TypeScript definitions

Introduced FFmpeg Node.js native addon binaries for multiple platforms (darwin-arm64, linux-arm64, linux-x64, win-x64) and added TypeScript type definitions for the addon interface, including video info extraction, duration detection, audio conversion, and PCM decoding.

* Remove baseClient and simplify packet client selection

Deleted baseClient.ts and moved its logic into nativeClient.ts, making NativePacketClient a standalone class. Refactored PacketClientContext to always use NativePacketClient, removing support for multiple packet backends and related selection logic. Updated binary for napi2native.win32.x64.node.

* Remove debug log for process PID in napcat.ts

Eliminated an unnecessary console.log statement that printed the process PID. This cleans up the output and removes leftover debugging code.

* fix: getQQBuildStr

* fix: 简化代码

* refactor: 大幅度调整send

* feat: ffmpeg enhance for native node addon

* Remove baseClient.ts from packet client module

Deleted the src/core/packet/client/baseClient.ts file, which contained the PacketClient class and related interfaces. This may be part of a refactor or cleanup to remove unused or redundant code.

* Remove 'bmp24' argument from getVideoInfo call

Updated the extractThumbnail method to call addon.getVideoInfo without the 'bmp24' argument, aligning with the updated addon API.

* refactor: 重构目录删除旧支持

* feat: raw包能力增强完成

* refactor: 规范化

* feat: packet能力增强

* feat: 9.9.22-40824 & 9.9.22-40768

* Refactor addon path resolution and rename Windows addon

Simplifies the logic for resolving the ffmpeg addon path by dynamically constructing the filename from process.platform and process.arch. Also renames the Windows x64 addon file to ffmpegAddon.win32.x64.node for consistency.

* Add mappings for 3.2.20 versions in napi2native.json

Added send and recv address mappings for 3.2.20-x64 and 3.2.20-arm64 builds to support additional versions in napi2native.json.

---------

Co-authored-by: Clansty <i@gao4.pw>
2025-10-30 12:50:45 +08:00

71 lines
1.8 KiB
TypeScript

/**
* FFmpeg Node.js Native Addon Type Definitions
*
* This addon provides FFmpeg functionality for Node.js including:
* - Video information extraction with thumbnail generation
* - Audio/Video duration detection
* - Audio format conversion to NTSILK
* - Audio decoding to PCM
*/
/**
* Video information result object
*/
export interface VideoInfo {
/** Video width in pixels */
width: number;
/** Video height in pixels */
height: number;
/** Video duration in seconds */
duration: number;
/** Container format name (e.g., "mp4", "mkv", "avi") */
format: string;
/** Video codec name (e.g., "h264", "hevc", "vp9") */
videoCodec: string;
/** First frame thumbnail as BMP image buffer */
image: Buffer;
}
/**
* Audio PCM decoding result object
*/
export interface AudioPCMResult {
/** PCM audio data as 16-bit signed integer samples */
pcm: Buffer;
/** Sample rate in Hz (e.g., 44100, 48000, 24000) */
sampleRate: number;
/** Number of audio channels (1 for mono, 2 for stereo) */
channels: number;
}
/**
* FFmpeg interface providing all audio/video processing methods
*/
export interface FFmpeg {
/**
* Get video information including resolution, duration, format, codec and first frame thumbnail
*/
getVideoInfo(filePath: string, format?: 'bmp' | 'bmp24'): Promise<VideoInfo>;
/**
* Get duration of audio or video file in seconds
*/
getDuration(filePath: string): Promise<number>;
/**
* Convert audio file to NTSILK format (WeChat voice message format)
*/
convertToNTSilkTct(inputPath: string, outputPath: string): Promise<void>;
/**
* Decode audio file to raw PCM data
*/
decodeAudioToPCM(filePath: string): Promise<AudioPCMResult>;
}