replay use mp4 instead of gif

This commit is contained in:
legop3
2026-01-03 21:19:07 -05:00
parent fcc71426ee
commit 242fe461d9
+8 -8
View File
@@ -250,7 +250,7 @@ function buildDriverCaption() {
return `Drivers: ${entries.join(', ')}`; return `Drivers: ${entries.join(', ')}`;
} }
async function buildReplayGif() { async function buildReplayVideo() {
const cameras = getRoomCameras(); const cameras = getRoomCameras();
if (!cameras.length) { if (!cameras.length) {
throw new Error('No room cameras configured'); throw new Error('No room cameras configured');
@@ -271,7 +271,7 @@ async function buildReplayGif() {
const filename = `frame-${String(i + 1).padStart(4, '0')}.jpg`; const filename = `frame-${String(i + 1).padStart(4, '0')}.jpg`;
await fsp.writeFile(path.join(tmpDir, filename), frames[i].buffer); await fsp.writeFile(path.join(tmpDir, filename), frames[i].buffer);
} }
const outPath = path.join(tmpDir, 'replay.gif'); const outPath = path.join(tmpDir, 'replay.mp4');
const delayMs = getRoomCameraReplayDelayMs(); const delayMs = getRoomCameraReplayDelayMs();
const fps = (1000 / delayMs).toFixed(3); const fps = (1000 / delayMs).toFixed(3);
await execFileAsync('ffmpeg', [ await execFileAsync('ffmpeg', [
@@ -283,10 +283,10 @@ async function buildReplayGif() {
fps, fps,
'-i', '-i',
'frame-%04d.jpg', 'frame-%04d.jpg',
'-filter_complex', '-c:v',
'[0:v]palettegen=stats_mode=diff[p];[0:v][p]paletteuse=dither=sierra2_4a', 'libx264',
'-loop', '-pix_fmt',
'0', 'yuv420p',
outPath, outPath,
], { cwd: tmpDir }); ], { cwd: tmpDir });
const buffer = await fsp.readFile(outPath); const buffer = await fsp.readFile(outPath);
@@ -323,8 +323,8 @@ async function handleReplayCommand(message) {
const requester = const requester =
message.member?.nickname || message.author?.globalName || message.author?.username || 'Discord'; message.member?.nickname || message.author?.globalName || message.author?.username || 'Discord';
try { try {
const buffer = await buildReplayGif(); const buffer = await buildReplayVideo();
const attachment = new AttachmentBuilder(buffer, { name: 'replay.gif' }); const attachment = new AttachmentBuilder(buffer, { name: 'replay.mp4' });
const caption = [ const caption = [
`Replay requested by ${requester}.`, `Replay requested by ${requester}.`,
buildDriverCaption(), buildDriverCaption(),