API Reference Overview
Complete reference for the Zvid Package API, including all functions, types, and configuration options.
Main Function
renderVideo(project, outputFolder, progressCallback?)
The primary function for rendering videos from JSON configurations.
Signature:
function renderVideo(
project: Project,
outputFolder: string,
progressCallback?: (percentage: number) => void,
): Promise<void>;
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
project | Project | Yes | Video project configuration object |
outputFolder | string | Yes | Directory path where the output video will be saved |
progressCallback | function | No | Callback function to track rendering progress |
Returns: Promise<void> - Resolves when rendering is complete
Example:
import renderVideo from "video-rendering";
await renderVideo(project, "./output", (progress) => {
console.log(`Progress: ${progress}%`);
});
Project Configuration
Project Object
The main configuration object that defines your video.
interface Project {
name?: string;
width?: number;
height?: number;
duration?: number;
frameRate?: number;
backgroundColor?: string;
outputFormat?: string;
resolution?: ResolutionPreset;
visuals?: Items[];
audios?: AudioItem[];
subtitle?: Subtitle;
}
Properties:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | No | Date.now() + 'unnamed' | Output filename (without extension) |
width | number | No | 1280 | Video width in pixels (overridden by resolution) |
height | number | No | 720 | Video height in pixels (overridden by resolution) |
resolution | ResolutionPreset | No | "custom" | Preset resolution that overrides width/height |
duration | number | No | 10 | Total video duration in seconds |
frameRate | number | No | 30 | Frames per second (e.g., 30, 60) |
backgroundColor | string | No | "#ffffff" | Background color in hex format (#000000) |
outputFormat | string | No | "mp4" | Output video format |
visuals | Items[] | No | [] | Array of visual elements |
audios | AudioItem[] | No | [] | Array of audio elements |
subtitle | Subtitle | No | null | Caption and subtitle configuration |
Example:
const project = {
name: "my-video",
duration: 30,
visuals: [
// ... visual elements
],
audios: [
// ... audio elements
],
};
Resolution Presets
The resolution property allows you to use predefined video dimensions optimized for different platforms and use cases. When specified, it overrides the width and height properties.
Available Presets
| Preset | Dimensions | Aspect Ratio | Use Case |
|---|---|---|---|
sd | 640×480 | 4:3 | Standard definition |
hd | 1280×720 | 16:9 | HD content |
full-hd | 1920×1080 | 16:9 | Full HD content |
squared | 1080×1080 | 1:1 | Square format |
youtube-short | 1080×1920 | 9:16 | YouTube Shorts |
youtube-video | 1920×1080 | 16:9 | YouTube videos |
tiktok | 1080×1920 | 9:16 | TikTok videos |
instagram-reel | 1080×1920 | 9:16 | Instagram Reels |
instagram-post | 1080×1080 | 1:1 | Instagram posts |
instagram-story | 1080×1920 | 9:16 | Instagram Stories |
instagram-feed | 1080×1080 | 1:1 | Instagram feed posts |
twitter-landscape | 1200×675 | 16:9 | Twitter landscape videos |
twitter-portrait | 1080×1350 | 4:5 | Twitter portrait videos |
twitter-square | 1080×1080 | 1:1 | Twitter square videos |
facebook-video | 1080×1920 | 9:16 | Facebook videos |
facebook-story | 1080×1920 | 9:16 | Facebook Stories |
facebook-post | 1080×1080 | 1:1 | Facebook posts |
snapshat | 1080×1920 | 9:16 | Snapchat content |
custom | Uses w×h | Variable | Custom dimensions (default) |
Resolution Examples
// Using preset resolution
const instagramPost = {
name: "instagram-content",
resolution: "instagram-post", // 1080×1080
duration: 15,
visuals: [
/* ... */
],
};
// Using custom dimensions
const customVideo = {
name: "custom-content",
resolution: "custom", // or omit resolution property
width: 1600,
height: 900,
duration: 20,
visuals: [
/* ... */
],
};
// Resolution overrides width/height
const overrideExample = {
name: "override-example",
width: 1920, // This will be ignored
height: 1080, // This will be ignored
resolution: "squared", // Final dimensions: 1080×1080
duration: 10,
visuals: [
/* ... */
],
};
Platform-Specific Examples
// YouTube Short
const youtubeShort = {
name: "my-youtube-short",
resolution: "youtube-short",
duration: 60,
visuals: [
/* ... */
],
};
// TikTok Video
const tiktokVideo = {
name: "my-tiktok",
resolution: "tiktok",
duration: 30,
visuals: [
/* ... */
],
};
// Twitter Landscape
const twitterVideo = {
name: "twitter-promo",
resolution: "twitter-landscape",
duration: 45,
visuals: [
/* ... */
],
};
Position and Resize Properties
The Zvido Package includes two powerful properties that simplify element positioning and sizing:
Position Property
The position property provides preset positioning options that override the x and y coordinates for any visual element.
Available Position Presets:
| Preset | Description | Coordinates |
|---|---|---|
"top-left" | Position element at top-left corner | x=0, y=0 |
"top-right" | Position element at top-right corner | x=projectWidth - itemWidth, y=0 |
"bottom-right" | Position element at bottom-right corner | x=projectWidth - itemWidth, y=projectHeight - itemHeight |
"bottom-left" | Position element at bottom-left corner | x=0, y=projectHeight - itemHeight |
"center-center" | Position element at center of video | x=(projectWidth - itemWidth)/2, y=(projectHeight - itemHeight)/2 |
"custom" | Use explicit x and y values (default) | Uses provided x and y coordinates |
Position Examples:
// Center an image in the video
{
type: "IMAGE",
src: "https://example.com/image.jpg",
width: 400,
height: 300,
position: "center-center"
}
// Position text at top-right corner
{
type: "TEXT",
text: "Watermark",
width: 200,
height: 50,
position: "top-right",
style: { fontSize: "24px", color: "#ffffff" }
}
// Use custom positioning (same as not specifying position)
{
type: "IMAGE",
src: "https://example.com/logo.png",
x: 100,
y: 50,
position: "custom" // or omit position property
}
Resize Property
The resize property provides CSS-like resizing behavior for image, video, and GIF elements, overriding the width and height properties while maintaining aspect ratio.
Available Resize Modes:
| Mode | Description | Behavior |
|---|---|---|
"contain" | Scale to fit within bounds (letterboxing) | Entire media visible, may have empty space |
"cover" | Scale to fill bounds (cropping) | Fills entire area, may crop parts of media |
Resize Examples:
// Fit image within 400x300 bounds while maintaining aspect ratio
{
type: "IMAGE",
src: "https://example.com/photo.jpg",
width: 400, // Target width
height: 300, // Target height
resize: "contain" // Will scale to fit within 400x300
}
// Fill 400x300 area completely, cropping if necessary
{
type: "VIDEO",
src: "https://example.com/video.mp4",
width: 400, // Target width
height: 300, // Target height
resize: "cover" // Will scale to fill 400x300, may crop
}
// Combine position and resize
{
type: "IMAGE",
src: "https://example.com/background.jpg",
width: 1920, // Full video width
height: 1080, // Full video height
position: "center-center",
resize: "cover" // Fill entire background
}
Resize Behavior Details:
-
Contain: Similar to CSS
object-fit: contain- Scales media to fit entirely within the specified dimensions
- Maintains original aspect ratio
- May result in letterboxing (empty space) if aspect ratios don't match
-
Cover: Similar to CSS
object-fit: cover- Scales media to completely fill the specified dimensions
- Maintains original aspect ratio
- May crop parts of the media if aspect ratios don't match
Zoom Property
The zoom property adds zoom effects to image, video, and GIF elements. It can be used to create dynamic zoom-in effects for videos or static zoom effects for images.
Zoom Configuration:
The zoom property accepts a boolean value, which would add a zoom effect at the center of the item.
// Boolean usage (uses default settings)
zoom: true;
Zoom Examples:
// Simple zoom with defaults (2x zoom from center)
{
type: "IMAGE",
src: "https://example.com/photo.jpg",
width: 400,
height: 300,
zoom: true
}
Anchor Property
The anchor property sets the element's anchor point used for positioning, scaling and rotation. It works alongside position/x/y and affects how transforms are applied relative to the item's bounds.
export type Anchor =
| "top-left"
| "top-center"
| "top-right"
| "center-left"
| "center-center"
| "center-right"
| "bottom-left"
| "bottom-center"
| "bottom-right";
- Default:
center-center - Applies to:
IMAGE,TEXT,SVG,GIF - Description: Changes the origin point for position, rotation (
angle) and zoom/scale operations. For example,top-leftanchors transforms at the element's top-left corner, whilecenter-centeruses the element center.
Anchor Examples:
// Anchor at top-center (useful for titles that expand downward)
{
type: "TEXT",
text: "Headline",
anchor: "center-center",
x: 640,
y: 50
}
Element Types
The Zvid Package supports various element types for creating rich video content:
Visual Elements
- Text Elements - Add styled text, titles, and captions
- Image Elements - Include photos, graphics, and static images
- Video Elements - Embed video clips with timing control
- GIF Elements - Add animated GIFs and loops
- SVG Elements - Include scalable vector graphics and shapes
Audio Elements
- Audio Elements - Background music, sound effects, and voiceovers
Captions & Subtitles
- Subtitle - Add synchronized captions with word-level timing
Effects and Animations
- Animation Effects - Entrance and exit animations for all elements except GIFs
- Video Transitions - Smooth transitions between video clips
Configuration Defaults
The package is designed to be flexible, with many optional properties that have sensible default values.
Project Defaults
| Property | Default Value | Description |
|---|---|---|
width | 1280 | Video width in pixels |
height | 720 | Video height in pixels |
duration | 10 | Duration in seconds |
frameRate | 30 | Frames per second |
backgroundColor | "#ffffff" | Background color (hex) |
outputFormat | "mp4" | Output format (e.g., mp4, mov) |
name | Date.now() + 'unnamed' | Output file name (without extension) |
Visual Item Defaults
These defaults apply to all visual elements (IMAGE, VIDEO, TEXT, GIF, SVG).
| Property | Default Value | Description |
|---|---|---|
x | 0 | Horizontal position (pixels) |
y | 0 | Vertical position (pixels) |
position | "custom" | Position preset (overrides x, y) |
anchor | "center-center" | Anchor point for transforms and positioning |
resize | null | Resize mode for media items |
zoom | null | Zoom effect configuration |
enterBegin | 0 | Start time of enter animation (seconds) |
enterEnd | 0 | End time of enter animation (seconds) |
exitBegin | project.duration | Start time of exit animation (seconds) |
exitEnd | project.duration | End time of exit animation (seconds) |
opacity | 1 | Opacity (0 to 1) |
angle | 0 | Rotation angle (degrees) |
flipV | false | Flip Vertically |
flipH | false | Flip Horizontal |
track | 0 | Composition track index |
enterAnimation | null | Enter animation name (e.g., "fade") |
exitAnimation | null | Exit animation name (e.g., "fade") |
Video Item Defaults
| Property | Default Value | Description |
|---|---|---|
videoBegin | 0 | Start time within the source video |
videoEnd | source duration | End time within the source video |
volume | 1 | Audio volume (0 to 1) |
speed | 1 | Playback speed |
Audio Item Defaults
| Property | Default Value | Description |
|---|---|---|
audioBegin | 0 | Start time within the source audio |
audioEnd | source duration | End time within the source audio |
volume | 1 | Audio volume (0 to 1) |
speed | 1 | Playback speed |
Quick Examples
Basic Text Element
{
type: "TEXT",
text: "Hello World",
x: 640, y: 360,
style: {
fontSize: "48px",
color: "#000000",
textAlign: "center"
}
}
Basic Image Element
{
type: "IMAGE",
src: "https://images.pexels.com/photos/32972375/pexels-photo-32972375.jpeg",
x: 100, y: 100,
width: 607, height: 910
}
Basic Video Element
{
type: "VIDEO",
src: "https://videos.pexels.com/video-files/1409899/1409899-sd_640_360_25fps.mp4",
videoEnd: 10, // just take the first 10 seconds of the video.
}
Basic Audio Element
{
src: "https://cdn.pixabay.com/audio/2025/04/21/audio_ed6f0ed574.mp3",
volume: 0.5
}
Error Handling
The package provides structured error handling with specific error types:
Error Categories
- Configuration Errors (001-099) - Project setup and validation issues
- Media Processing Errors (100-199) - FFmpeg and encoding problems
- Resource Errors (200-299) - File access and network issues
- Validation Errors (300-399) - Data validation failures
- Rendering Errors (400-499) - Canvas and browser rendering issues
- Unexpected Errors (500-599) - System and third-party errors
Error Handling Example
try {
await renderVideo(project, "./output");
} catch (error) {
console.error("Error code:", error.code);
console.error("Error message:", error.message);
switch (error.code) {
case "VR_CONFIG_001":
console.log("Missing duration in project configuration.");
break;
case "VR_MEDIA_100":
console.log("FFmpeg processing failed.");
break;
case "VR_RESOURCE_200":
console.log("File not found. Check file paths and availability.");
break;
default:
console.log("Unexpected error occurred.");
}
}
Supported Formats
Video Formats
- Input: It supports all FFMPEG Video formats (ex: MP4, AVI, MOV, WebM, MKV)
- Output: it supports all FFMPEG Video formats (ex: MP4, AVI, MOV, WebM, MKV)
Image Formats
- Supported: All browser supported image formats
Audio Formats
- Supported: It supports all FFMPEG Audio formats (ex: MP3, WAV, AAC, OGG)
Performance Considerations
Optimization Tips
- Image Sizes: Use appropriate image dimensions to avoid unnecessary scaling
- Video Codecs: Use H.264 for best compatibility and performance
- Audio Quality: Balance quality vs file size for audio tracks
- Memory Usage: Monitor memory usage for long or high-resolution videos
- Parallel Processing: The package handles FFmpeg optimization automatically
Resource Limits
- Maximum Resolution: Limited by available system memory
- Maximum Duration: No hard limit, but longer videos require more processing time
- Concurrent Elements: No limit on number of visual elements per track
Detailed Documentation
For comprehensive information about each element type and feature:
Element Types
- Text Elements - Complete text styling and formatting guide
- Image Elements - Image handling, filters, and effects
- Video Elements - Video clips, timing, and audio control
- GIF Elements - Animated GIF integration
- SVG Elements - Vector graphics and scalable shapes
- Audio Elements - Audio mixing and synchronization
Captions & Subtitles
- Subtitle - Add synchronized captions with word-level timing
Effects and Animations
- Animation Effects - Element entrance and exit animations
- Video Transitions - Professional video-to-video transitions
Next Steps
- Quick Start - Get started with your first video
- Examples - Practical implementation examples
- FAQ - Common questions and troubleshooting