AI 跟练的素材生产工具,产物写入 TUICallKit-Vue3/training: - 教练动作帧:AI 设定稿 → 切帧对齐、锁脸、插帧 → 导出小程序帧与 COS 高清帧 - 示范视频:Remotion 渲染四个动作的示范视频 - 背景音乐:程序合成的原创循环音乐(npm run bgm)
39 lines
1.9 KiB
JavaScript
39 lines
1.9 KiB
JavaScript
// 本地联调用静态服务(小程序开发者工具访问):/squat.mp4 → out/ 下渲染好的示范视频(支持 Range 拖动进度),
|
|
// /coach/sq_00.webp → out/coach/ 下的教练高清帧,/music/calm.mp3 → out/music/ 下的背景音乐
|
|
import { createServer } from 'node:http'
|
|
import { createReadStream, statSync, existsSync } from 'node:fs'
|
|
import { join, normalize, extname } from 'node:path'
|
|
|
|
const PORT = Number(process.env.PORT || 5179)
|
|
const ROOT = join(import.meta.dirname, '..')
|
|
const TYPES = { '.mp4': 'video/mp4', '.webp': 'image/webp', '.mp3': 'audio/mpeg' }
|
|
|
|
function resolve(url) {
|
|
const name = normalize(decodeURIComponent((url || '/').split('?')[0])).replace(/^([/\\.])+/, '')
|
|
const base = join(ROOT, 'out')
|
|
const file = join(base, name)
|
|
const type = TYPES[extname(file)]
|
|
if (!file.startsWith(base) || !type || !existsSync(file)) return null
|
|
return { file, type }
|
|
}
|
|
|
|
createServer((req, res) => {
|
|
const hit = resolve(req.url)
|
|
if (!hit) {
|
|
res.writeHead(404).end('not found')
|
|
return
|
|
}
|
|
const size = statSync(hit.file).size
|
|
const headers = { 'Content-Type': hit.type, 'Accept-Ranges': 'bytes', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'max-age=60' }
|
|
const range = /bytes=(\d*)-(\d*)/.exec(req.headers.range || '')
|
|
if (range) {
|
|
const start = range[1] ? Number(range[1]) : 0
|
|
const end = range[2] ? Math.min(Number(range[2]), size - 1) : size - 1
|
|
res.writeHead(206, { ...headers, 'Content-Range': `bytes ${start}-${end}/${size}`, 'Content-Length': end - start + 1 })
|
|
createReadStream(hit.file, { start, end }).pipe(res)
|
|
return
|
|
}
|
|
res.writeHead(200, { ...headers, 'Content-Length': size })
|
|
createReadStream(hit.file).pipe(res)
|
|
}).listen(PORT, process.env.HOST || '0.0.0.0', () => console.log(`示范视频服务已启动: http://127.0.0.1:${PORT}/squat.mp4`))
|