Merge branch 'no-ffprobe' into dev

This commit is contained in:
linyuchen 2024-03-19 20:12:38 +08:00
commit 8afe0af940
4 changed files with 27 additions and 4 deletions

View File

@ -203,7 +203,14 @@ export async function getVideoInfo(filePath: string) {
}>((resolve, reject) => { }>((resolve, reject) => {
ffmpeg(filePath).ffprobe((err, metadata) => { ffmpeg(filePath).ffprobe((err, metadata) => {
if (err) { if (err) {
reject(err); resolve({
width: 720, height: 1080,
time: 15,
format: "mp4",
size: fs.statSync(filePath).size,
filePath
})
// reject(err);
} else { } else {
const videoStream = metadata.streams.find(s => s.codec_type === 'video'); const videoStream = metadata.streams.find(s => s.codec_type === 'video');
if (videoStream) { if (videoStream) {

View File

@ -17,6 +17,7 @@ import {NTQQFileApi} from "./api/file";
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF} from "../common/utils/file"; import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF} from "../common/utils/file";
import {log} from "../common/utils/log"; import {log} from "../common/utils/log";
import {sleep} from "../common/utils/helper"; import {sleep} from "../common/utils/helper";
import pathLib from "path";
export class SendMsgElementConstructor { export class SendMsgElementConstructor {
@ -108,7 +109,7 @@ export class SendMsgElementConstructor {
return element; return element;
} }
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> { static async video(filePath: string, fileName: string = "", diyThumbPath: string=""): Promise<SendVideoElement> {
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO); let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
if (fileSize === 0) { if (fileSize === 0) {
throw "文件异常大小为0"; throw "文件异常大小为0";
@ -126,6 +127,13 @@ export class SendMsgElementConstructor {
log("视频信息", videoInfo) log("视频信息", videoInfo)
const createThumb = new Promise<string>((resolve, reject) => { const createThumb = new Promise<string>((resolve, reject) => {
const thumbFileName = `${md5}_0.png` const thumbFileName = `${md5}_0.png`
const thumbPath = pathLib.join(thumb, thumbFileName)
if (diyThumbPath) {
fs.copyFile(diyThumbPath, pathLib.join(thumb, thumbFileName)).then(() => {
resolve(thumbPath);
})
return;
}
ffmpeg(filePath) ffmpeg(filePath)
.on("end", () => { .on("end", () => {
}) })
@ -138,7 +146,7 @@ export class SendMsgElementConstructor {
folder: thumb, folder: thumb,
size: videoInfo.width + "x" + videoInfo.height size: videoInfo.width + "x" + videoInfo.height
}).on("end", () => { }).on("end", () => {
resolve(pathLib.join(thumb, thumbFileName)); resolve(thumbPath);
}); });
}) })
let thumbPath = new Map() let thumbPath = new Map()

View File

@ -430,7 +430,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName)); sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
} else if (sendMsg.type === OB11MessageDataType.video) { } else if (sendMsg.type === OB11MessageDataType.video) {
log("发送视频", path, payloadFileName || fileName) log("发送视频", path, payloadFileName || fileName)
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName)); let thumb = sendMsg.data?.thumb;
if (thumb){
let uri2LocalRes = await uri2local(thumb)
if (uri2LocalRes.success){
thumb = uri2LocalRes.path;
}
}
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb));
} else if (sendMsg.type === OB11MessageDataType.voice) { } else if (sendMsg.type === OB11MessageDataType.voice) {
sendElements.push(await SendMsgElementConstructor.ptt(path)); sendElements.push(await SendMsgElementConstructor.ptt(path));
}else if (sendMsg.type === OB11MessageDataType.image) { }else if (sendMsg.type === OB11MessageDataType.image) {

View File

@ -117,6 +117,7 @@ export interface OB11MessageText {
interface OB11MessageFileBase { interface OB11MessageFileBase {
data: { data: {
thumb?: string;
name?: string; name?: string;
file: string, file: string,
url?: string; url?: string;