diff --git a/lib/video-canvas/archive-video.ts b/lib/video-canvas/archive-video.ts index 832a55452..aed301374 100644 --- a/lib/video-canvas/archive-video.ts +++ b/lib/video-canvas/archive-video.ts @@ -5,6 +5,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { promisify } from "node:util"; import { uploadFile } from "@/lib/storage/service"; +import { archiveMediaThroughQiniu } from "@/lib/storage/qiniu-image-archive"; import { downloadCanvasMedia } from "./download-media"; const probe = promisify(execFile); @@ -15,6 +16,13 @@ export async function archiveCanvasVideo(url: string): Promise { if (existing) return existing; if (pending.size >= 2) throw new Error("视频保存繁忙,请稍后重试"); const job = (async () => { + const archived = await archiveMediaThroughQiniu(url, randomUUID(), "video"); + if (archived) { + const { stdout } = await probe("ffprobe", ["-v", "error", "-rw_timeout", "15000000", "-protocol_whitelist", "http,https,tcp,tls,crypto", "-format_whitelist", "mov,matroska,webm", "-show_streams", "-show_format", "-of", "json", archived.url], { timeout: 20000, maxBuffer: 1024 * 1024 }); + const media = JSON.parse(stdout); + if (!media.streams?.some((stream: { codec_type: string }) => stream.codec_type === "video") || !(Number(media.format?.duration) > 0)) throw new Error("视频文件不完整"); + return archived.url; + } const dir = await mkdtemp(join(tmpdir(), "canvas-video-archive-")); try { const input = join(dir, "video");