@video-editor/protocol
v0.0.1-beta.31
Published
Video editor protocol management, validation, and resource utilities.
Readme
@video-editor/protocol
Video editor protocol management, validation, and resource utilities.
Features
- Protocol Management: Create and manage video editor protocols with undo/redo
- Validation: JSON Schema validation for all segment types
- Resource Management: OPFS-based caching for video/audio resources
- Waveform Extraction: Extract and cache audio waveforms for visualization
- Thumbnail Generation: Extract video thumbnails with caching
Installation
pnpm add @video-editor/protocolQuick Start
Audio Waveform Extraction
import { extractWaveform, peaksToSvgPath } from '@video-editor/protocol'
// Extract waveform from audio URL
const waveform = await extractWaveform('/audio.mp3', { samples: 1000 })
// Generate SVG path for rendering
const svgPath = peaksToSvgPath(waveform.peaks, 800, 100)
console.log(waveform.peaks) // number[] - normalized 0-1
console.log(waveform.duration) // number - secondsProtocol Management
import { createVideoProtocolManager } from '@video-editor/protocol'
import type { IVideoProtocol } from '@video-editor/protocol'
const protocol: IVideoProtocol = { /* ... */ }
const manager = createVideoProtocolManager(protocol)
// Add segment
manager.addSegment({
id: 'audio-1',
segmentType: 'audio',
url: '/audio.mp3',
startTime: 0,
endTime: 3000,
})
// Undo/Redo
manager.undo()
manager.redo()Resource Caching
import { createResourceManager } from '@video-editor/protocol'
const resourceManager = createResourceManager()
// Add resource to OPFS cache
await resourceManager.add('/video-editor-res/audio.mp3', audioBlob)
// Read from cache
const cached = await resourceManager.read('/video-editor-res/audio.mp3')Documentation
See WAVEFORM.md for detailed waveform API documentation.
Exports
Waveform
extractWaveform(url, options)- Extract waveform from URLextractWaveformFromBuffer(buffer, cacheKey, options)- Extract from ArrayBufferclearWaveformCache(url?)- Clear waveform cachepeaksToSvgPath(peaks, width, height)- Generate SVG pathpeaksToBars(peaks, width)- Generate bar data
Protocol
createVideoProtocolManager(protocol)- Create protocol managercreateValidator()- Create protocol validatorparse(protocolString)- Parse and validate protocol JSON
Resources
createResourceManager(dir?)- Create resource managergenerateThumbnails(url, options)- Generate video thumbnailsgetMp4Meta(url)- Extract MP4 metadata
