const { config } = require("../config/env"); const { run } = require("../utils/shell"); async function probe(filePath) { const { stdout } = await run(config.video.ffprobePath, [ "-v", "error", "-print_format", "json", "-show_format", "-show_streams", filePath ], { timeoutMs: 60_000 }); const data = JSON.parse(stdout); const video = data.streams.find((stream) => stream.codec_type === "video"); if (!video) throw new Error("No video stream was found in this file."); const duration = Number(data.format.duration || video.duration || 0); const bitrate = Number(data.format.bit_rate || video.bit_rate || 0); const fpsParts = String(video.avg_frame_rate || video.r_frame_rate || "0/1").split("/").map(Number); const fps = fpsParts[1] ? fpsParts[0] / fpsParts[1] : fpsParts[0] || 0; return { raw: data, duration, bitrate, size: Number(data.format.size || 0), width: Number(video.width || 0), height: Number(video.height || 0), fps, codec: video.codec_name, pixFmt: video.pix_fmt, hasAudio: data.streams.some((stream) => stream.codec_type === "audio") }; } async function verifyMedia(filePath) { await run(config.video.ffmpegPath, ["-v", "error", "-xerror", "-i", filePath, "-f", "null", "-"], { timeoutMs: 10 * 60_000 }); return true; } module.exports = { probe, verifyMedia };