@henteko/kumiki
Version:
A video generation tool that creates videos from JSON configurations
67 lines • 2 kB
JavaScript
import { existsSync } from 'node:fs';
import { mkdir } from 'node:fs/promises';
import path from 'node:path';
import { RenderError } from '../utils/errors.js';
import { logger } from '../utils/logger.js';
export class BaseScene {
scene;
options;
narrationPath;
constructor(scene, options) {
this.scene = scene;
this.options = options;
}
/**
* Get the output path for static image
*/
getStaticOutputPath() {
return path.join(this.options.tempDir, `scene_${this.scene.id}.png`);
}
/**
* Get the output path for video
*/
getVideoOutputPath() {
return path.join(this.options.tempDir, `scene_${this.scene.id}.mp4`);
}
/**
* Get the output path for narration audio
*/
getNarrationOutputPath() {
return path.join(this.options.tempDir, `narration_${this.scene.id}.wav`);
}
/**
* Set the narration audio path
*/
setNarrationPath(path) {
this.narrationPath = path;
}
/**
* Ensure the output directory exists
*/
async ensureOutputDirectory() {
if (!existsSync(this.options.tempDir)) {
logger.debug('Creating output directory', { path: this.options.tempDir });
await mkdir(this.options.tempDir, { recursive: true });
}
}
/**
* Parse resolution string to width and height
*/
parseResolution() {
const [width, height] = this.options.resolution.split('x').map(Number);
if (!width || !height) {
throw new RenderError(`Invalid resolution format: ${this.options.resolution}`, 'INVALID_RESOLUTION', { resolution: this.options.resolution });
}
return { width, height };
}
/**
* Calculate position coordinates
*/
calculatePosition(pos, dimension, elementSize) {
if (pos === 'center') {
return (dimension - elementSize) / 2;
}
return pos;
}
}
//# sourceMappingURL=base.js.map