|
1 | | -<p align="center"> |
2 | | - <img src="./assets/banner.png" alt="Library Banner" style="aspect-ratio: 1200/500;width: 100%;" /> |
3 | | - <h1 align="center">diffusionstudio/core</h1> |
4 | | -</p> |
5 | | - |
6 | | -<p align="center"> |
7 | | - <img src="https://img.shields.io/badge/Made with-Typescript-blue?color=000000&logo=typescript&logoColor=ffffff" alt="Static Badge"> |
8 | | - <a href="https://vitejs.dev"><img src="https://img.shields.io/badge/Powered%20by-Vite-000000?style=flat&logo=Vite&logoColor=ffffff" alt="powered by vite"></a> |
9 | | - <a href="https://discord.com/invite/zPQJrNGuFB"><img src="https://img.shields.io/discord/1115673443141156924?style=flat&logo=discord&logoColor=fff&color=000000" alt="discord"></a> |
10 | | - <a href="https://x.com/diffusionhq"><img src="https://img.shields.io/badge/Follow for-Updates-blue?color=000000&logo=X&logoColor=ffffff" alt="Static Badge"></a> |
11 | | - <a href="https://www.ycombinator.com/companies/diffusion-studio"><img src="https://img.shields.io/badge/Combinator-F24-blue?color=000000&logo=ycombinator&logoColor=ffffff" alt="Static Badge"></a> |
12 | | -</p> |
13 | | -<br/> |
14 | | - |
15 | | -# Getting Started |
16 | | -`@diffusionstudio/core` is a 2D motion graphics and video rendering engine powered by WebCodecs. Developers commonly use it for video editing automations and to build editing [playgrounds/web apps](https://playground.diffusion.studio). |
| 1 | +# The video engine for your timeline |
17 | 2 |
|
18 | | -## Documentation |
19 | | -Explore the full documentation at [docs.diffusion.studio](https://docs.diffusion.studio/docs). |
| 3 | +[](https://www.typescriptlang.org/) |
| 4 | +[](https://discord.com/invite/zPQJrNGuFB) |
| 5 | +[](https://x.com/diffusionhq) |
| 6 | +[](https://www.ycombinator.com/companies/diffusion-studio) |
| 7 | + |
| 8 | +Diffusion Studio Core is a browser based video engine built in TypeScript for fast media composition. Think of it like a game engine that is optimized for video, audio and image workloads. It supports both interactive playback for editing and a high fidelity rendering mode for final output. Developers often use it to build non linear editors or other timeline based media applications (e.g. [Diffusion Studio Pro](https://pro.diffusion.studio)). Under the hood it takes advantage of Canvas2DContext and the WebCodecs API to tap directly into hardware accelerated processing in the browser. |
20 | 9 |
|
21 | | -## Credits |
22 | | -This project owes much to [@Vanilagy's](https://github.com/Vanilagy) exceptional muxer implementations. |
23 | 10 |
|
24 | | -## Why Use Diffusion Studio |
25 | | -💻 100% **client-side**<br/> |
26 | | -🪽 **Small bundle size** – Only 75 KB with a single dependency<br/> |
27 | | -🩸 Blazingly **fast** WebCodecs renderer<br/> |
28 | | -🦾 **AI-first** architecture<br/> |
| 11 | +https://github.com/user-attachments/assets/3878f293-ab1b-4bb1-8088-b9493546180a |
| 12 | + |
| 13 | + |
| 14 | +## Documentation |
| 15 | +Visit the [Docs](https://docs.diffusion.studio/docs) for comprehensive guides |
29 | 16 |
|
30 | 17 | ## Getting Started |
31 | 18 | ```sh |
32 | 19 | npm install @diffusionstudio/core |
33 | 20 | ``` |
34 | 21 |
|
35 | | -## Benchmarks |
36 | | - |
37 | | - |
38 | | -## Basic Usage |
39 | | -Here’s an example of how to use the library: |
40 | | - |
41 | | -```javascript |
42 | | -import * as core from '@diffusionstudio/core'; |
| 22 | +Recommended usage: |
43 | 23 |
|
44 | | -const url = 'https://diffusion-studio-public.s3.eu-central-1.amazonaws.com/videos/big_buck_bunny_1080p_30fps.mp4'; |
45 | | - |
46 | | -// create a video clip and trim it |
47 | | -const video = new core.VideoClip(url).subclip(0, '10s'); |
48 | | - |
49 | | -// create a text clip and add styles |
50 | | -const text = new core.TextClip({ |
51 | | - text: 'Bunny - Our Brave Hero', |
52 | | - position: 'center', |
53 | | - duration: '5s', |
54 | | - stroke: { color: '#000000' } |
55 | | -}); |
56 | | - |
57 | | -const composition = new core.Composition(); // 1920x1080 |
58 | | - |
59 | | -// this is how to compose your clips |
60 | | -await composition.add(video); // convenience function for |
61 | | -await composition.add(text); // clip -> layer -> composition |
| 24 | +```typescript |
| 25 | +import * as core from "@diffusionstudio/core"; |
62 | 26 |
|
63 | | -await new core.Encoder(composition).render('hello_world.mp4'); |
| 27 | +const composition = new core.Composition(); |
64 | 28 | ``` |
65 | 29 |
|
66 | | -The API models the structure of conventional video editing applications like Adobe Premiere or CapCut, using a layer-based system. Each layer contains zero or more clips of a single type, arranged in ascending chronological order. |
| 30 | +## Features |
| 31 | +A few highlights: declarative timeline compositions, layering, splitting, shapes, captions, rich text, silence removal, effects, transitions, keyframing, bounding boxes, masking, audio ramps, font management, checkpoints, realtime playback and hardware accelerated rendering. |
67 | 32 |
|
68 | | -Layers are created implicitly with `composition.add(clip)`, but you can also create them manually: |
| 33 | +Let’s look at some of these in action. |
69 | 34 |
|
| 35 | +### Concatenate two videos |
70 | 36 | ```typescript |
71 | | -const layer = composition.createLayer(); |
72 | | -await layer.add(text0); |
73 | | -await layer.add(text1); |
74 | | -await layer.add(text2); |
75 | | -... |
| 37 | +const sources = await Promise.all([ |
| 38 | + core.Source.from<core.VideoSource>('/intro.webm'), |
| 39 | + core.Source.from<core.VideoSource>('/outro.mp4'), |
| 40 | +]); |
| 41 | + |
| 42 | +const layer = await composition.add( |
| 43 | + new core.Layer({ |
| 44 | + mode: 'SEQUENTIAL' |
| 45 | + }) |
| 46 | +); |
| 47 | + |
| 48 | +await layer.add( |
| 49 | + new core.VideoClip(sources[0], { |
| 50 | + range: [2, 8], |
| 51 | + }) |
| 52 | +); |
| 53 | + |
| 54 | +await layer.add( |
| 55 | + new core.VideoClip(sources[1], { |
| 56 | + range: [2, 12], |
| 57 | + }) |
| 58 | +); |
76 | 59 | ``` |
77 | 60 |
|
78 | | -## Examples |
79 | | -Find more [examples here.](https://github.com/diffusionstudio/examples), or test all capabilities on our [Playground.]( https://app.diffusion.studio) |
80 | | - |
81 | | -https://github.com/user-attachments/assets/7a943407-e916-4d9f-b46a-3163dbff44c3 |
82 | | - |
83 | | -## How Does Diffusion Studio Compare? |
| 61 | +### Apply basic transitions |
| 62 | +```typescript |
| 63 | +new core.VideoClip(/** source **/, { |
| 64 | + transition: { |
| 65 | + duration: 1, |
| 66 | + type: 'dissolve', |
| 67 | + } |
| 68 | +}) |
| 69 | +``` |
84 | 70 |
|
85 | | -### Remotion |
86 | | -A React-based video creation tool that converts the DOM into videos. It’s beginner-friendly, allowing web developers to leverage their existing skills. |
| 71 | +### Mask an image |
| 72 | +```typescript |
| 73 | +const mask = new core.RectangleMask({ |
| 74 | + width: 640, |
| 75 | + height: 1080, |
| 76 | + radius: 100, |
| 77 | +}); |
87 | 78 |
|
88 | | -### Motion Canvas |
89 | | -A standalone editor designed for high-quality animations. It features an imperative API, adding elements procedurally rather than relying on keyframes, making it ideal for detailed animations. |
| 79 | +new core.ImageClip(/** source **/, { mask }); |
| 80 | +``` |
90 | 81 |
|
91 | | -### Diffusion Studio |
92 | | -A video editing **library** rather than a framework with a visual interface. It’s lightweight, operates entirely on the **client-side**, and supports WebCodecs without relying on WebAssembly/ffmpeg. Ideal for integration into existing projects. |
| 82 | +### Animate your clips with key frames |
| 83 | +```typescript |
| 84 | +new core.TextClip({ |
| 85 | + text: "Hello World", |
| 86 | + align: 'center', |
| 87 | + baseline: 'middle', |
| 88 | + position: 'center', |
| 89 | + animations: [ |
| 90 | + { |
| 91 | + key: 'rotation', |
| 92 | + frames: [ |
| 93 | + { time: 0, value: 0 }, |
| 94 | + { time: 2, value: 720 }, |
| 95 | + ], |
| 96 | + }, |
| 97 | + ] |
| 98 | +}); |
| 99 | +``` |
93 | 100 |
|
94 | | -## Contributing |
| 101 | +### Add basic effects to visual clips |
| 102 | +```typescript |
| 103 | +new core.RectangleClip({ |
| 104 | + position: 'center', |
| 105 | + delay: 6, |
| 106 | + duration: 4, |
| 107 | + effects: [ |
| 108 | + { |
| 109 | + type: 'blur', |
| 110 | + value: 10, |
| 111 | + }, |
| 112 | + { |
| 113 | + type: 'hue-rotate', |
| 114 | + value: 90 |
| 115 | + } |
| 116 | + ] |
| 117 | +}) |
| 118 | +``` |
95 | 119 |
|
96 | | -Currently, version ^2.0.0 is invite-only. You can request access on our Discord if you're interested in contributing. The source code for version ^1.0.0 is available in this repository. |
| 120 | +## Required Headers |
97 | 121 |
|
98 | | -## Current features |
99 | | -* **Video/Audio** trimming and offsets |
100 | | -* **Layering** |
101 | | -* **Splitting** clips |
102 | | -* **Html & Image** rendering |
103 | | -* **Relative** units (e.g. 80% clip height) |
104 | | -* **Shapes** (e.g., rectangles, circles) |
105 | | -* **Text** with multiple styles |
106 | | -* **Audio Visualization** |
107 | | -* High Quality **Captions** |
108 | | -* **Silence Removal** for audio |
109 | | -* Web & Local **Fonts** |
110 | | -* **Custom Clips** |
111 | | -* **Filters** |
112 | | -* **Masks** |
113 | | -* **Blending** modes |
114 | | -* **Keyframe** animations |
115 | | - * **Numbers, Text and Colors** |
116 | | - * **Easing** (ease in, ease out etc.) |
117 | | - * **Extrapolation** `'clamp' | 'extend'` |
118 | | -* **Realtime playback** |
119 | | -* **Hardware accelerated** encoding via WebCodecs |
120 | | -* **Dynamic render resolution and framerate** |
| 122 | +Diffusion Studio Core requires specific HTTP headers to be set for proper operation. These headers enable the use of SharedArrayBuffer and other advanced browser APIs needed for video processing. |
121 | 123 |
|
122 | | -## Background |
| 124 | +The following headers are required: |
| 125 | +- `Cross-Origin-Opener-Policy: same-origin` |
| 126 | +- `Cross-Origin-Embedder-Policy: credentialless` |
123 | 127 |
|
124 | | -This project was initiated in March 2023 with the mission of creating a “video processing toolkit for the era of AI.” As someone passionate about video editing for over a decade, the release of WebCodecs and WebGPU without feature flags in Chrome presented the perfect opportunity to build something new. |
| 128 | +## Pricing |
125 | 129 |
|
126 | | -Traditional browser-based video editors rely on server-side rendering, requiring time-consuming uploads and downloads of large files. With WebCodecs, video processing can now be done directly in the browser, making it significantly faster and more efficient. |
| 130 | +You can use the engine for free as long as you keep the "Made with Diffusion Studio" watermark on the rendered video. To remove the watermark, you can purchase a [license key](https://www.diffusion.studio/core-rendering-engine#pricing). |
127 | 131 |
|
128 | | -I’m excited to contribute to the next generation of video editing technology. |
| 132 | +## FAQ |
129 | 133 |
|
130 | | -## License |
| 134 | +### Do I have to renew the license key? |
131 | 135 |
|
132 | | -This library is free to use under the **Diffusion Studio Non-Commercial License**, as long as your project is **not monetized**. |
| 136 | +No. It’s a one time purchase and your key stays valid forever. |
133 | 137 |
|
134 | | -### ✅ You Can Use This Library for Free If: |
135 | | -- You are an **individual or a company** and your project is **not generating revenue** (no sales, ads, donations beyond operational costs, or other forms of monetization). |
136 | | -- Your project **may become commercial in the future**, as long as you obtain a commercial license before monetization. |
| 138 | +### What happens if the license server is down? |
137 | 139 |
|
138 | | -### 💼 If Your Project Becomes Commercial: |
139 | | -- If you decide to **monetize your project** (e.g., through sales, ads, premium features, or enterprise use), you must purchase a commercial license. |
140 | | -- Visit our website to obtain a license when you’re ready to monetize. |
| 140 | +There is no license server. Your key is a signed payload created with our private key. The library includes a public key that verifies it locally so it works even without an internet connection. |
141 | 141 |
|
142 | | -### 📄 More Details: |
143 | | -- See LICENSE for the Non-Commercial License. |
144 | | -- See LICENSE_COMMERCIAL for the Commercial License terms. |
| 142 | +### What if I lose my key? |
145 | 143 |
|
146 | | -For any questions, feel free to [contact us](https://diffusion.studio). |
| 144 | +We can regenerate it any time. Just email contact |at| diffusion.studio. |
147 | 145 |
|
148 | | -## Version History |
| 146 | +### What are the limitations of the key? |
149 | 147 |
|
150 | | -### v1.x _(Released October 2024)_ |
151 | | -- Fully open-source (MPL-2.0 license) |
152 | | -- Relied on Pixi.js for rendering (resulting in a large library size) |
153 | | -- WebGPU support |
154 | | -- FFmpeg-compiled demuxer |
155 | | -- Limited to short-form content |
| 148 | +You can’t share your key with other organizations. Other than that, feel free to use it across as many of your own apps or domains as you need. |
156 | 149 |
|
157 | | -### v2.x _(Released February 1, 2025)_ |
158 | | -- **Source code access by invite only** (Commercial & Non-Commercial license) |
159 | | -- Removed Pixi.js, significantly reducing library size |
160 | | -- Introduced a custom Canvas 2D renderer |
161 | | -- Continued FFmpeg-based demuxing |
162 | | -- Still limited to short-form content |
| 150 | +## When to use Diffusion Studio Core |
| 151 | +- You’re building a timeline based application such as an NLE that needs to render video in the browser |
| 152 | +- Your app needs to compose multiple assets into a video or audio output |
| 153 | +- You want a framework agnostic and efficient video engine that works with Svelte, Vue, Solid, Angular and others |
163 | 154 |
|
164 | | -### v3.x _(Released February 18, 2025)_ |
165 | | -- **Source code access by invite only** (Commercial & Non-Commercial license) |
166 | | -- Removed all FFmpeg dependencies |
167 | | -- Retained Canvas 2D rendering |
168 | | -- Introduced pure TypeScript-based muxers/demuxers |
169 | | -- Added support for long-form content |
| 155 | +## When not to use Diffusion Studio Core |
| 156 | +- You need to render videos server side |
| 157 | + - Use Remotion |
| 158 | +- You want to compose videos with HTML or React |
| 159 | + - Use Remotion |
| 160 | +- You want a framework that already includes frontend components like a timeline or inspector |
| 161 | + - Use Remotion with the [Editor Starter](https://www.remotion.dev/docs/editor-starter) |
| 162 | +- You need low level encoding, decoding, muxing, demuxing or transcoding capabilities |
| 163 | + - Use Mediabunny |
170 | 164 |
|
171 | | -### v4.x _(Estimated Release: July 2025)_ |
172 | | -- **Source code access by invite only** (Commercial & Non-Commercial license) |
173 | | -- Introducing a custom WebGL2 renderer |
| 165 | +## How it works |
| 166 | +Diffusion Studio Core is written in TypeScript and built on top of [Mediabunny](https://github.com/Vanilagy/mediabunny) ([Sponsoring is welcome!](https://github.com/Vanilagy/mediabunny?tab=readme-ov-file#sponsoring)). The architecture is inspired by Pixi.js but built from scratch, optimized for media processing. Decoding and encoding are performed using the [WebCodecs API](https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API), which taps into your system's hardware acceleration. Decoded frames are then painted using the [Canvas 2D Context API](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D). Nearly all features of the Canvas 2D API are available in Diffusion Studio Core. |
0 commit comments