Download src/server/render/video.ts from bhyve/auto-lms: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/bhyve/auto-lms/resolve/main/src/server/render/video.ts
- Command line
-
hf download hf://spaces/bhyve/auto-lms/src/server/render/video.ts
-
curl -L -o video.ts https://huggingface.co/spaces/bhyve/auto-lms/resolve/main/src/server/render/video.ts
1.27 kB
| import { spawn } from 'child_process'; | |
| import ffmpegPath from 'ffmpeg-static'; | |
| // Run the bundled ffmpeg binary with the given args. | |
| export function runFfmpeg(args: string[]): Promise<void> { | |
| return new Promise((resolve, reject) => { | |
| if (!ffmpegPath) { | |
| reject(new Error('ffmpeg binary not found (ffmpeg-static)')); | |
| return; | |
| } | |
| const proc = spawn(ffmpegPath, args, { stdio: ['ignore', 'ignore', 'pipe'] }); | |
| let stderr = ''; | |
| proc.stderr.on('data', (chunk) => { | |
| stderr += chunk.toString(); | |
| }); | |
| proc.on('error', reject); | |
| proc.on('close', (code) => { | |
| if (code === 0) resolve(); | |
| else reject(new Error(`ffmpeg exited ${code}: ${stderr.slice(-600)}`)); | |
| }); | |
| }); | |
| } | |
| // Loop a still image for the duration of the audio and mux them into an mp4. | |
| export async function renderStillVideo(args: { | |
| imagePath: string; | |
| audioPath: string; | |
| outPath: string; | |
| }): Promise<void> { | |
| await runFfmpeg([ | |
| '-y', | |
| '-loglevel', | |
| 'error', | |
| '-loop', | |
| '1', | |
| '-i', | |
| args.imagePath, | |
| '-i', | |
| args.audioPath, | |
| '-c:v', | |
| 'libx264', | |
| '-tune', | |
| 'stillimage', | |
| '-pix_fmt', | |
| 'yuv420p', | |
| '-r', | |
| '30', | |
| '-c:a', | |
| 'aac', | |
| '-b:a', | |
| '192k', | |
| '-shortest', | |
| args.outPath, | |
| ]); | |
| } | |