mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Merge remote-tracking branch 'origin/main' into hls
This commit is contained in:
@@ -34,15 +34,15 @@ Mediabunny is a JavaScript library for reading, writing, and converting media fi
|
|||||||
<a href="https://kino.ai/" target="_blank" rel="sponsored">
|
<a href="https://kino.ai/" target="_blank" rel="sponsored">
|
||||||
<img src="./docs/public/sponsors/kino.jpg" width="60" height="60" alt="Kino">
|
<img src="./docs/public/sponsors/kino.jpg" width="60" height="60" alt="Kino">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a href="https://screen.studio/" target="_blank" rel="sponsored">
|
||||||
|
<img src="./docs/public/sponsors/screen-studio.webp" width="60" height="60" alt="Screen Studio">
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### Silver sponsors
|
### Silver sponsors
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<a href="https://pqina.nl/pintura/" target="_blank" rel="sponsored">
|
|
||||||
<img src="./docs/public/sponsors/pintura-labs.png" width="50" height="50" alt="Pintura Labs">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="https://ponder.ai/" target="_blank" rel="sponsored">
|
<a href="https://ponder.ai/" target="_blank" rel="sponsored">
|
||||||
<img src="./docs/public/sponsors/ponder.png" width="50" height="50" alt="Ponder">
|
<img src="./docs/public/sponsors/ponder.png" width="50" height="50" alt="Ponder">
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
+2
-1
@@ -95,9 +95,9 @@ const sponsors = {
|
|||||||
{ image: '/sponsors/gling.svg', name: 'Gling AI', url: 'https://www.gling.ai/' },
|
{ image: '/sponsors/gling.svg', name: 'Gling AI', url: 'https://www.gling.ai/' },
|
||||||
{ image: '/sponsors/diffusionstudio.png', name: 'Diffusion Studio', url: 'https://diffusion.studio/' },
|
{ image: '/sponsors/diffusionstudio.png', name: 'Diffusion Studio', url: 'https://diffusion.studio/' },
|
||||||
{ image: '/sponsors/kino.jpg', name: 'Kino', url: 'https://kino.ai/' },
|
{ image: '/sponsors/kino.jpg', name: 'Kino', url: 'https://kino.ai/' },
|
||||||
|
{ image: '/sponsors/screen-studio.webp', name: 'Screen Studio', url: 'https://screen.studio/' },
|
||||||
],
|
],
|
||||||
silver: [
|
silver: [
|
||||||
{ image: '/sponsors/pintura-labs.png', name: 'Pintura Labs', url: 'https://pqina.nl/pintura/' },
|
|
||||||
{ image: '/sponsors/ponder.png', name: 'Ponder', url: 'https://ponder.ai/' },
|
{ image: '/sponsors/ponder.png', name: 'Ponder', url: 'https://ponder.ai/' },
|
||||||
],
|
],
|
||||||
bronze: [
|
bronze: [
|
||||||
@@ -107,6 +107,7 @@ const sponsors = {
|
|||||||
{ image: '/sponsors/jellypod.png', name: 'Jellypod', url: 'https://jellypod.ai/' },
|
{ image: '/sponsors/jellypod.png', name: 'Jellypod', url: 'https://jellypod.ai/' },
|
||||||
],
|
],
|
||||||
individual: [
|
individual: [
|
||||||
|
{ image: '/sponsors/pintura-labs.png', name: 'Pintura Labs', url: 'https://pqina.nl/pintura/' },
|
||||||
{ image: 'https://avatars.githubusercontent.com/u/82552321', name: 'Polotno', url: 'https://github.com/polotno-project' },
|
{ image: 'https://avatars.githubusercontent.com/u/82552321', name: 'Polotno', url: 'https://github.com/polotno-project' },
|
||||||
{ image: 'https://avatars.githubusercontent.com/u/489051', name: 'Roman Rädle', url: 'https://github.com/raedle' },
|
{ image: 'https://avatars.githubusercontent.com/u/489051', name: 'Roman Rädle', url: 'https://github.com/raedle' },
|
||||||
{ image: 'https://avatars.githubusercontent.com/u/197597', name: 'Christopher Chedeau', url: 'https://github.com/vjeux' },
|
{ image: 'https://avatars.githubusercontent.com/u/197597', name: 'Christopher Chedeau', url: 'https://github.com/vjeux' },
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -143,7 +143,7 @@ loadUrlButton.addEventListener('click', () => {
|
|||||||
const url = prompt(
|
const url = prompt(
|
||||||
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
||||||
+ ' right CORS headers set.',
|
+ ' right CORS headers set.',
|
||||||
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
'https://remotion.media/BigBuckBunny.mp4',
|
||||||
);
|
);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ loadUrlButton.addEventListener('click', () => {
|
|||||||
const url = prompt(
|
const url = prompt(
|
||||||
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
||||||
+ ' right CORS headers set.',
|
+ ' right CORS headers set.',
|
||||||
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
'https://remotion.media/BigBuckBunny.mp4',
|
||||||
);
|
);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ loadUrlButton.addEventListener('click', () => {
|
|||||||
const url = prompt(
|
const url = prompt(
|
||||||
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
||||||
+ ' right CORS headers set.',
|
+ ' right CORS headers set.',
|
||||||
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
'https://remotion.media/BigBuckBunny.mp4',
|
||||||
);
|
);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ loadUrlButton.addEventListener('click', () => {
|
|||||||
const url = prompt(
|
const url = prompt(
|
||||||
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
'Please enter a URL of a media file. Note that it must be HTTPS and support cross-origin requests, so have the'
|
||||||
+ ' right CORS headers set.',
|
+ ' right CORS headers set.',
|
||||||
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
|
'https://remotion.media/BigBuckBunny.mp4',
|
||||||
);
|
);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Generated
+7
-7
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
@@ -7743,9 +7743,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mediabunny": {
|
"node_modules/mediabunny": {
|
||||||
"version": "1.34.0",
|
"version": "1.34.3",
|
||||||
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.34.0.tgz",
|
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.34.3.tgz",
|
||||||
"integrity": "sha512-mjn/7QVEPbPEakuNKD8OIPDhaoe2NlgWVyyqftuLVWvsgLol7g2MQzXWCjx523CP8Y9jE2H09hbYCuTwSI7pSQ==",
|
"integrity": "sha512-Jb0x3jyvadGVpo8aZSn53NZduPbPdbx9foQsAGOmKBz7Hai9B38Kf+7eXbxXFcXoXxcTyNaZeDhoA0agoBQldA==",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"peer": true,
|
"peer": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@@ -12069,7 +12069,7 @@
|
|||||||
},
|
},
|
||||||
"packages/ac3": {
|
"packages/ac3": {
|
||||||
"name": "@mediabunny/ac3",
|
"name": "@mediabunny/ac3",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/emscripten": "^1.40.1"
|
"@types/emscripten": "^1.40.1"
|
||||||
@@ -12084,7 +12084,7 @@
|
|||||||
},
|
},
|
||||||
"packages/mp3-encoder": {
|
"packages/mp3-encoder": {
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/emscripten": "^1.40.1"
|
"@types/emscripten": "^1.40.1"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@mediabunny/ac3",
|
"name": "@mediabunny/ac3",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"description": "AC-3 and E-AC-3 (Dolby Digital) decoder and encoder extension for Mediabunny, based on FFmpeg.",
|
"description": "AC-3 and E-AC-3 (Dolby Digital) decoder and encoder extension for Mediabunny, based on FFmpeg.",
|
||||||
"main": "./dist/bundles/mediabunny-ac3.mjs",
|
"main": "./dist/bundles/mediabunny-ac3.mjs",
|
||||||
"module": "./dist/bundles/mediabunny-ac3.mjs",
|
"module": "./dist/bundles/mediabunny-ac3.mjs",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
EncodedPacket,
|
EncodedPacket,
|
||||||
registerDecoder,
|
registerDecoder,
|
||||||
} from 'mediabunny';
|
} from 'mediabunny';
|
||||||
import { sendCommand } from './worker-client';
|
import { sendCommand, refWorker, unrefWorker } from './worker-client';
|
||||||
|
|
||||||
class Ac3Decoder extends CustomAudioDecoder {
|
class Ac3Decoder extends CustomAudioDecoder {
|
||||||
private ctx = 0;
|
private ctx = 0;
|
||||||
@@ -23,6 +23,8 @@ class Ac3Decoder extends CustomAudioDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
await refWorker();
|
||||||
|
|
||||||
const result = await sendCommand({
|
const result = await sendCommand({
|
||||||
type: 'init-decoder',
|
type: 'init-decoder',
|
||||||
data: { codec: this.codec },
|
data: { codec: this.codec },
|
||||||
@@ -53,8 +55,9 @@ class Ac3Decoder extends CustomAudioDecoder {
|
|||||||
await sendCommand({ type: 'flush-decoder', data: { ctx: this.ctx } });
|
await sendCommand({ type: 'flush-decoder', data: { ctx: this.ctx } });
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
async close() {
|
||||||
void sendCommand({ type: 'close-decoder', data: { ctx: this.ctx } });
|
void sendCommand({ type: 'close-decoder', data: { ctx: this.ctx } });
|
||||||
|
await unrefWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
EncodedPacket,
|
EncodedPacket,
|
||||||
registerEncoder,
|
registerEncoder,
|
||||||
} from 'mediabunny';
|
} from 'mediabunny';
|
||||||
import { sendCommand } from './worker-client';
|
import { sendCommand, refWorker, unrefWorker } from './worker-client';
|
||||||
import { assert } from './shared';
|
import { assert } from './shared';
|
||||||
import { AC3_SAMPLE_RATES, EAC3_REDUCED_SAMPLE_RATES } from '../../../shared/ac3-misc';
|
import { AC3_SAMPLE_RATES, EAC3_REDUCED_SAMPLE_RATES } from '../../../shared/ac3-misc';
|
||||||
|
|
||||||
@@ -38,11 +38,14 @@ class Ac3Encoder extends CustomAudioEncoder {
|
|||||||
return (codec === 'ac3' || codec === 'eac3')
|
return (codec === 'ac3' || codec === 'eac3')
|
||||||
&& config.numberOfChannels >= 1
|
&& config.numberOfChannels >= 1
|
||||||
&& config.numberOfChannels <= 8
|
&& config.numberOfChannels <= 8
|
||||||
&& sampleRates.includes(config.sampleRate);
|
&& sampleRates.includes(config.sampleRate)
|
||||||
|
&& config.bitrate !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
assert(this.config.bitrate);
|
await refWorker();
|
||||||
|
|
||||||
|
assert(this.config.bitrate !== undefined);
|
||||||
this.sampleRate = this.config.sampleRate;
|
this.sampleRate = this.config.sampleRate;
|
||||||
this.numberOfChannels = this.config.numberOfChannels;
|
this.numberOfChannels = this.config.numberOfChannels;
|
||||||
|
|
||||||
@@ -130,6 +133,7 @@ class Ac3Encoder extends CustomAudioEncoder {
|
|||||||
|
|
||||||
close() {
|
close() {
|
||||||
void sendCommand({ type: 'close-encoder', data: { ctx: this.ctx } });
|
void sendCommand({ type: 'close-encoder', data: { ctx: this.ctx } });
|
||||||
|
void unrefWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async encodeOneFrame() {
|
private async encodeOneFrame() {
|
||||||
|
|||||||
@@ -10,13 +10,51 @@ import { assert, type WorkerCommand, type WorkerResponse, type WorkerResponseDat
|
|||||||
// @ts-expect-error An esbuild plugin handles this, TypeScript doesn't need to understand
|
// @ts-expect-error An esbuild plugin handles this, TypeScript doesn't need to understand
|
||||||
import createWorker from './codec.worker';
|
import createWorker from './codec.worker';
|
||||||
|
|
||||||
let workerPromise: Promise<Worker> | null;
|
type ExtendedWorker = Worker & {
|
||||||
|
ref?: () => void;
|
||||||
|
unref?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
let workerPromise: Promise<ExtendedWorker> | null;
|
||||||
let nextMessageId = 0;
|
let nextMessageId = 0;
|
||||||
const pendingMessages = new Map<number, {
|
const pendingMessages = new Map<number, {
|
||||||
resolve: (value: WorkerResponseData) => void;
|
resolve: (value: WorkerResponseData) => void;
|
||||||
reject: (reason?: unknown) => void;
|
reject: (reason?: unknown) => void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
let refCount = 0;
|
||||||
|
let keepAliveInterval: ReturnType<typeof setInterval> | null = null;
|
||||||
|
|
||||||
|
export const refWorker = async () => {
|
||||||
|
refCount++;
|
||||||
|
if (refCount === 1) {
|
||||||
|
keepAliveInterval = setInterval(() => {}, 2 ** 31 - 1);
|
||||||
|
const worker = await ensureWorker();
|
||||||
|
worker.ref?.();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const unrefWorker = async () => {
|
||||||
|
refCount--;
|
||||||
|
if (refCount === 0) {
|
||||||
|
if (keepAliveInterval !== null) {
|
||||||
|
clearInterval(keepAliveInterval);
|
||||||
|
keepAliveInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const worker = await workerPromise;
|
||||||
|
if (worker) {
|
||||||
|
if (worker.unref) {
|
||||||
|
worker.unref(); // If we don't do this, then the Node process never terminates by itself
|
||||||
|
} else if (typeof window === 'undefined') {
|
||||||
|
// Non-browser environment without unref - terminate instead
|
||||||
|
worker.terminate();
|
||||||
|
workerPromise = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const sendCommand = async <T extends string>(
|
export const sendCommand = async <T extends string>(
|
||||||
command: WorkerCommand & { type: T },
|
command: WorkerCommand & { type: T },
|
||||||
transferables?: Transferable[],
|
transferables?: Transferable[],
|
||||||
@@ -41,7 +79,8 @@ export const sendCommand = async <T extends string>(
|
|||||||
const ensureWorker = () => {
|
const ensureWorker = () => {
|
||||||
return workerPromise ??= (async () => {
|
return workerPromise ??= (async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
const worker = (await createWorker()) as Worker;
|
const worker = (await createWorker()) as ExtendedWorker;
|
||||||
|
worker.unref?.(); // Start unreffed
|
||||||
|
|
||||||
const onMessage = (data: WorkerResponse) => {
|
const onMessage = (data: WorkerResponse) => {
|
||||||
const pending = pendingMessages.get(data.id);
|
const pending = pendingMessages.get(data.id);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.34.2",
|
"version": "1.34.4",
|
||||||
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
||||||
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default function Worker() {
|
|||||||
const inlineWorkerFunctionCode = `
|
const inlineWorkerFunctionCode = `
|
||||||
export default async function inlineWorker(scriptText) {
|
export default async function inlineWorker(scriptText) {
|
||||||
if (typeof Worker !== 'undefined' && typeof Bun === 'undefined') {
|
if (typeof Worker !== 'undefined' && typeof Bun === 'undefined') {
|
||||||
// Browser, Deno
|
// Browser, Deno (Deno can't do dynamic import of worker_threads)
|
||||||
|
|
||||||
const blob = new Blob([scriptText], { type: "text/javascript" });
|
const blob = new Blob([scriptText], { type: "text/javascript" });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
@@ -39,10 +39,10 @@ export default async function inlineWorker(scriptText) {
|
|||||||
// Node, Bun (Bun's Worker is flaky, worker_threads works much better)
|
// Node, Bun (Bun's Worker is flaky, worker_threads works much better)
|
||||||
|
|
||||||
let Worker;
|
let Worker;
|
||||||
|
const workerModule = 'node:worker_threads';
|
||||||
try {
|
try {
|
||||||
Worker = (await import('worker_threads')).Worker;
|
Worker = (await import(workerModule)).Worker;
|
||||||
} catch {
|
} catch {
|
||||||
const workerModule = 'worker_threads';
|
|
||||||
Worker = require(workerModule).Worker;
|
Worker = require(workerModule).Worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user