peasy-video
v0.2.2
Published
Video processing library for Node.js — trim, resize, rotate, thumbnails, GIF conversion. FFmpeg-powered, TypeScript-first.
Maintainers
Readme
peasy-video
Video processing library for Node.js -- trim, resize, rotate, extract audio, generate thumbnails, convert to GIF, concatenate clips, adjust speed, and reverse video. FFmpeg-powered, TypeScript-first with full type safety. Handles MP4, WebM, MKV, AVI, MOV, and any container format supported by FFmpeg.
Built from PeasyVideo, a free online video toolkit with 15 browser-based tools for trimming, resizing, format conversion, thumbnail extraction, and GIF creation.
Try the interactive tools at peasyvideo.com -- video trimming, resizing, audio extraction, GIF conversion, and thumbnail generation
Table of Contents
- Prerequisites
- Install
- Quick Start
- What You Can Do
- TypeScript Types
- API Reference
- REST API Client
- Learn More
- Also Available
- Peasy Developer Tools
- License
Prerequisites
peasy-video uses FFmpeg under the hood. Install it before using this library:
| Platform | Command |
|----------|---------|
| macOS | brew install ffmpeg |
| Ubuntu/Debian | sudo apt install ffmpeg |
| Fedora/RHEL | sudo dnf install ffmpeg-free |
| Windows | choco install ffmpeg |
Install
npm install peasy-videoQuick Start
import { info, trim, resize, thumbnail, videoToGif } from "peasy-video";
// Get video metadata
const meta = await info("movie.mp4");
console.log(meta.width, meta.height, meta.duration); // 1920 1080 7200
// Trim to a 30-second clip
const clip = await trim("movie.mp4", { start: 60, duration: 30 });
// Resize to 720p
const resized = await resize("movie.mp4", { width: 1280, height: 720 });
// Extract a thumbnail at 5 seconds
const thumb = await thumbnail("movie.mp4", { time: 5 });
// Convert a clip to GIF
const gif = await videoToGif("clip.mp4", { fps: 15, width: 480 });What You Can Do
Video Info & Metadata
Extract comprehensive metadata from video files without decoding frames. FFprobe reads container headers and stream information to report resolution, frame rate, codec, bitrate, duration, and whether an audio track is present.
import { info } from "peasy-video";
// Extract video metadata using FFprobe
const meta = await info("presentation.mp4");
console.log(meta.width); // 1920
console.log(meta.height); // 1080
console.log(meta.fps); // 30
console.log(meta.duration); // 3600.5 (seconds)
console.log(meta.codec); // "h264"
console.log(meta.hasAudio); // true
console.log(meta.bitrate); // 5000000Learn more: Video Metadata & EXIF Data Explained · What is Bitrate? · What is a Keyframe?
Trimming & Concatenation
Video trimming extracts a segment using keyframe-accurate seeking. Concatenation joins multiple clips sequentially using the FFmpeg concat demuxer, maintaining codec compatibility across segments.
import { trim, concatenate } from "peasy-video";
// Extract a 30-second clip starting at 1 minute
const clip = await trim("lecture.mp4", { start: 60, duration: 30 });
// Trim from start to end time
const intro = await trim("movie.mp4", { start: 0, end: 15 });
// Join multiple clips into one video
const combined = await concatenate([
"chapter1.mp4",
"chapter2.mp4",
"chapter3.mp4",
]);Learn more: How to Trim & Cut Video in Browser · What is Trimming? · What is GOP?
Resize & Transform
Video resizing scales frames to target dimensions while maintaining aspect ratio. Rotation applies transpose filters for 90/180/270 degree rotations, handling both the video stream and any embedded rotation metadata.
| Resolution | Dimensions | Common Name | |-----------|------------|-------------| | 4K UHD | 3840 x 2160 | Ultra HD | | 1080p | 1920 x 1080 | Full HD | | 720p | 1280 x 720 | HD | | 480p | 854 x 480 | SD |
import { resize, rotate } from "peasy-video";
// Resize to 720p (maintains aspect ratio)
const hd = await resize("4k-video.mp4", { width: 1280, height: 720 });
// Resize by width only (auto-calculates height)
const small = await resize("video.mp4", { width: 640 });
// Rotate 90 degrees clockwise
const rotated = await rotate("portrait.mp4", { degrees: 90 });
// Rotate 180 degrees (flip upside down)
const flipped = await rotate("upside-down.mp4", { degrees: 180 });Learn more: Video Aspect Ratios & Resolution Guide · Social Media Video Specs · What is Letterboxing?
Audio Extraction
Extract the audio track from a video file as a standalone audio file, or strip the audio track entirely to produce a silent video. Audio extraction preserves the original codec when possible, avoiding re-encoding for faster processing.
import { extractAudio, stripAudio } from "peasy-video";
// Extract audio as MP3
const audio = await extractAudio("interview.mp4", "mp3");
// Extract audio as WAV (lossless)
const wav = await extractAudio("concert.mp4", "wav");
// Remove audio track from video (silent output)
const silent = await stripAudio("presentation.mp4");Learn more: How to Extract Audio from Video · What is Transcoding? · What is a Container Format?
Thumbnails
Extract individual frames as images for preview thumbnails, video galleries, or content analysis. Single-frame extraction uses precise seeking, while multi-frame extraction distributes captures evenly across the video duration.
import { thumbnail, thumbnails } from "peasy-video";
// Extract a frame at 5 seconds as PNG
const frame = await thumbnail("video.mp4", { time: 5 });
// Extract a frame with custom dimensions
const small = await thumbnail("video.mp4", {
time: 10,
width: 320,
height: 180,
});
// Generate 10 evenly-spaced thumbnails
const frames = await thumbnails("video.mp4", 10, { width: 320 });
// Returns array of paths: ["/tmp/peasy-video-xxx-0.png", ...]Learn more: Video Thumbnails Best Practices · Video Thumbnail Extraction Techniques · What is Frame Rate?
GIF Conversion
Convert video clips to animated GIFs with palette optimization for smaller file sizes and better color reproduction. Convert GIFs back to MP4 for efficient playback and embedding.
import { videoToGif, gifToVideo } from "peasy-video";
// Convert video to GIF with custom settings
const gif = await videoToGif("clip.mp4", {
fps: 15, // frames per second
width: 480, // pixel width
start: 2, // start at 2 seconds
duration: 5, // 5-second GIF
});
// Convert GIF back to MP4 (much smaller file size)
const mp4 = await gifToVideo("animation.gif");Learn more: GIF Creation & Optimization Guide · How to Create Animated GIFs from Video · Creating Seamless Video Loops
Speed & Reverse
Adjust playback speed using FFmpeg's setpts (video) and atempo (audio) filters. Speed factors below 1.0 create slow motion, above 1.0 create fast motion. Reverse plays the video backwards, re-encoding all frames.
import { speed, reverseVideo } from "peasy-video";
// Double the playback speed
const fast = await speed("lecture.mp4", { factor: 2.0 });
// Slow motion at half speed
const slow = await speed("action.mp4", { factor: 0.5 });
// Reverse the entire video
const reversed = await reverseVideo("clip.mp4");Learn more: Video Codecs Explained · What is Motion Estimation? · What is Optical Flow?
TypeScript Types
import type {
VideoFormat,
VideoInfo,
TrimOptions,
ResizeOptions,
RotateOptions,
ThumbnailOptions,
GifOptions,
SpeedOptions,
ThumbnailResult,
} from "peasy-video";
// VideoFormat — "mp4" | "webm" | "mkv" | "avi" | "mov" | "gif"
const format: VideoFormat = "mp4";
// VideoInfo — metadata from info()
const meta: VideoInfo = {
duration: 120.5,
width: 1920,
height: 1080,
fps: 30,
codec: "h264",
format: "mov,mp4,m4a,3gp,3g2,mj2",
bitrate: 5_000_000,
size: 75_000_000,
hasAudio: true,
};API Reference
| Function | Description |
|----------|-------------|
| info(input) | Get video metadata (resolution, fps, codec, duration, bitrate) |
| trim(input, options) | Extract a segment by start/end/duration |
| resize(input, options) | Scale video to target dimensions |
| rotate(input, options) | Rotate video 90/180/270 degrees |
| concatenate(inputs) | Join multiple video files sequentially |
| extractAudio(input, format?) | Extract audio track as standalone file |
| stripAudio(input) | Remove audio track from video |
| thumbnail(input, options?) | Extract a single frame as PNG |
| thumbnails(input, count, options?) | Extract multiple evenly-spaced frames |
| videoToGif(input, options?) | Convert video clip to animated GIF |
| gifToVideo(input) | Convert GIF to MP4 |
| reverseVideo(input) | Play video in reverse |
| speed(input, options) | Adjust playback speed (0.5x to 4.0x) |
REST API Client
The API client connects to the PeasyVideo developer API for tool discovery and content.
import { PeasyVideoClient } from "peasy-video";
const client = new PeasyVideoClient();
// List available tools
const tools = await client.listTools();
console.log(tools.results);
// Search across all content
const results = await client.search("trim");
console.log(results);
// Browse the glossary
const glossary = await client.listGlossary({ search: "format" });
for (const term of glossary.results) {
console.log(`${term.term}: ${term.definition}`);
}
// Discover guides
const guides = await client.listGuides({ category: "video" });
for (const guide of guides.results) {
console.log(`${guide.title} (${guide.audience_level})`);
}Full API documentation at peasyvideo.com/developers/.
Learn More
- Tools: Video Resolution Calculator · Video Bitrate Calculator · Video Framerate Converter · Video Aspect Ratio Calculator · Video File Size Calculator · Video Codec Analyzer · All Video Tools
- Guides: Video Codecs Explained · Video Compression for Web Delivery · GIF Creation & Optimization Guide · H.264 vs H.265 vs AV1 Comparison · Video Thumbnails Best Practices · Social Media Video Specs · Frame Rate Guide: 24, 30, 60 fps · All Guides
- Glossary: H.264 · H.265 · AV1 · Frame Rate · Container Format · Keyframe · Transcoding · Color Grading · All Terms
- Formats: MP4 · WebM · MKV · AVI · MOV · GIF · All Formats
- API: REST API Docs · OpenAPI Spec
Also Available
| Language | Package | Install |
|----------|---------|---------|
| Python | peasy-video | pip install "peasy-video[all]" |
| Go | peasy-video-go | go get github.com/peasytools/peasy-video-go |
| Rust | peasy-video | cargo add peasy-video |
| Ruby | peasy-video | gem install peasy-video |
Peasy Developer Tools
Part of the Peasy Tools open-source developer ecosystem.
| Package | PyPI | npm | Description | |---------|------|-----|-------------| | peasy-pdf | PyPI | npm | PDF merge, split, rotate, compress, 21 operations — peasypdf.com | | peasy-image | PyPI | npm | Image resize, crop, convert, compress — peasyimage.com | | peasy-audio | PyPI | npm | Audio trim, merge, convert, normalize — peasyaudio.com | | peasy-video | PyPI | npm | Video trim, resize, thumbnails, GIF — peasyvideo.com | | peasy-css | PyPI | npm | CSS minify, format, analyze — peasycss.com | | peasy-compress | PyPI | npm | ZIP, TAR, gzip compression — peasytools.com | | peasy-document | PyPI | npm | Markdown, HTML, CSV, JSON conversion — peasyformats.com | | peasytext | PyPI | npm | Text case conversion, slugify, word count — peasytext.com |
License
MIT
