From f5bd540863dd75c54e57f035fbc394c41ede91bc Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Tue, 5 May 2026 23:38:14 +0200 Subject: [PATCH] Add the video portion of @mediabunny/server --- .gitignore | 3 +- eslint.config.mjs | 1 + package-lock.json | 835 ++++++++++++++++++++++++++- packages/aac-encoder/src/encoder.ts | 7 + packages/ac3/src/decoder.ts | 7 + packages/flac-encoder/src/encoder.ts | 7 + packages/mp3-encoder/src/index.ts | 7 + packages/server/LICENSE | 373 ++++++++++++ packages/server/README.md | 1 + packages/server/api-extractor.json | 37 ++ packages/server/package.json | 54 ++ packages/server/src/index.ts | 28 + packages/server/src/misc.ts | 182 ++++++ packages/server/src/video-decoder.ts | 211 +++++++ packages/server/src/video-encoder.ts | 563 ++++++++++++++++++ packages/server/src/video-sample.ts | 520 +++++++++++++++++ packages/server/tsconfig.json | 24 + packages/server/tsdoc.json | 4 + scripts/bundle.ts | 18 + scripts/check.sh | 3 + src/isobmff/isobmff-muxer.ts | 2 +- src/misc.ts | 10 +- src/sample.ts | 64 +- test/node/server-extension.test.ts | 794 +++++++++++++++++++++++++ tsconfig.vitest.json | 2 + vitest.config.ts | 2 + 26 files changed, 3721 insertions(+), 38 deletions(-) create mode 100644 packages/server/LICENSE create mode 100644 packages/server/README.md create mode 100644 packages/server/api-extractor.json create mode 100644 packages/server/package.json create mode 100644 packages/server/src/index.ts create mode 100644 packages/server/src/misc.ts create mode 100644 packages/server/src/video-decoder.ts create mode 100644 packages/server/src/video-encoder.ts create mode 100644 packages/server/src/video-sample.ts create mode 100644 packages/server/tsconfig.json create mode 100644 packages/server/tsdoc.json create mode 100644 test/node/server-extension.test.ts diff --git a/.gitignore b/.gitignore index 3c8896f..10904ca 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ node_modules packages/mp3-encoder/dist packages/ac3/dist packages/aac-encoder/dist -packages/flac-encoder/dist \ No newline at end of file +packages/flac-encoder/dist +packages/server/dist \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index 19c75a8..b0330c2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -47,6 +47,7 @@ export default tseslint.config( 'packages/aac-encoder/build', 'packages/flac-encoder/dist', 'packages/flac-encoder/build', + 'packages/server/dist', 'eslint.config.mjs', 'docs/.vitepress/cache', 'test/public', diff --git a/package-lock.json b/package-lock.json index 849b007..0e4eb7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -381,7 +381,6 @@ "version": "7.28.3", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.3.tgz", "integrity": "sha512-9uIQ10o0WGdpP6GDhXcdOJPJuDgFtIDtN/9+ArJQ2NAfAmiuhTQdzkaTGR33v43GYS2UrSA0eX2pPPHoFVvpxA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -1108,6 +1107,28 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@fidm/asn1": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@fidm/asn1/-/asn1-1.0.4.tgz", + "integrity": "sha512-esd1jyNvRb2HVaQGq2Gg8Z0kbQPXzV9Tq5Z14KNIov6KfFD6PTaRIO8UpcsYiTNzOqJpmyzWgVTrUwFV3UF4TQ==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@fidm/x509": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@fidm/x509/-/x509-1.2.1.tgz", + "integrity": "sha512-nwc2iesjyc9hkuzcrMCBXQRn653XuAUKorfWM8PZyJawiy1QzLj4vahwzaI25+pfpwOLvMzbJ0uKpWLDNmo16w==", + "license": "MIT", + "dependencies": { + "@fidm/asn1": "^1.0.4", + "tweetnacl": "^1.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/@fontsource-variable/rubik": { "version": "5.2.6", "resolved": "https://registry.npmjs.org/@fontsource-variable/rubik/-/rubik-5.2.6.tgz", @@ -1413,6 +1434,12 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@leichtgewicht/ip-codec": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz", + "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==", + "license": "MIT" + }, "node_modules/@mediabunny/aac-encoder": { "resolved": "packages/aac-encoder", "link": true @@ -1429,6 +1456,10 @@ "resolved": "packages/mp3-encoder", "link": true }, + "node_modules/@mediabunny/server": { + "resolved": "packages/server", + "link": true + }, "node_modules/@mermaid-js/mermaid-mindmap": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@mermaid-js/mermaid-mindmap/-/mermaid-mindmap-9.3.0.tgz", @@ -1533,6 +1564,196 @@ "resolve": "~1.22.2" } }, + "node_modules/@minhducsun2002/leb128": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@minhducsun2002/leb128/-/leb128-1.0.0.tgz", + "integrity": "sha512-eFrYUPDVHeuwWHluTG1kwNQUEUcFjVKYwPkU8z9DR1JH3AW7JtJsG9cRVGmwz809kKtGfwGJj58juCZxEvnI/g==", + "license": "MIT" + }, + "node_modules/@noble/curves": { + "version": "1.9.7", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.9.7.tgz", + "integrity": "sha512-gbKGcRUYIjA3/zCCNaWDciTMFI0dCkvou3TL8Zmy5Nc7sJ47a0jtOeZoTaMxkuqRo9cRhjOdZJXegxYE5FN/xw==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.8.0" + }, + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz", + "integrity": "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@peculiar/asn1-cms": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-cms/-/asn1-cms-2.7.0.tgz", + "integrity": "sha512-hew63shtzzvBcSHbhm+cyAmKe6AIfinT9hzEqSPjDC6opTTMKmTkQ0gHuN2KsWlvqiKw1S/fS94fhag/FJkioQ==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "@peculiar/asn1-x509-attr": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-csr": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-csr/-/asn1-csr-2.7.0.tgz", + "integrity": "sha512-VVsAyGqErT9D1SY4aEqozThXMVI+ssVRiv2DDeYuvpBKLIgZ3hYs3Ay3u/VSoKq6ESFi9cf6rf3IOOzfwh7oMA==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-ecc": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-ecc/-/asn1-ecc-2.7.0.tgz", + "integrity": "sha512-n7KEs/Q/wrB415cxy4fHOBhegp4NdJ15fkJPwcB/3/8iNBQC2L/N7SChJPKDJPZGYH0jD4Tg4/0vnHmwghnbKw==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-pfx": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-pfx/-/asn1-pfx-2.7.0.tgz", + "integrity": "sha512-V/nrlQVmhg7lYAsM7E13UDL5erAwFv6kCIVFqNaMIHSVi7dngcT839JkRTkQBqznMG98l2XjxYk74ZztAohZzA==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-cms": "^2.7.0", + "@peculiar/asn1-pkcs8": "^2.7.0", + "@peculiar/asn1-rsa": "^2.7.0", + "@peculiar/asn1-schema": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-pkcs8": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-pkcs8/-/asn1-pkcs8-2.7.0.tgz", + "integrity": "sha512-9GTl1nE8Mx1kTZ+7QyYatDyKsm34QcWRBFkY1iPvWC3X4Dona5s/tlLiQsx5WzVdZqiMBZNYT0buyw4/vbhnjw==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-pkcs9": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-pkcs9/-/asn1-pkcs9-2.7.0.tgz", + "integrity": "sha512-Bh7m+OuIaSEllPQcSd9OSp93F4ROWH7sbITWV8MI+8dwsjE5111/87VxiWVvYFKyww3vp39geLv9ENqhwWHcew==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-cms": "^2.7.0", + "@peculiar/asn1-pfx": "^2.7.0", + "@peculiar/asn1-pkcs8": "^2.7.0", + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "@peculiar/asn1-x509-attr": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-rsa": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-rsa/-/asn1-rsa-2.7.0.tgz", + "integrity": "sha512-/qvENQrXyTZURjMqSeofHul0JJt2sNSzSwk36pl2olkHbaioMQgrASDZAlHXl0xUlnVbHj0uGgOrBMTb5x2aJQ==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-schema": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.7.0.tgz", + "integrity": "sha512-W8ZfWzLmQnrcky+eh3tni4IozMdqBDiHWU0N+vve/UGjMaUs8c0L7A2oEdkBXS8rTpWDpK/aoI3DG/L/hxmxPg==", + "license": "MIT", + "dependencies": { + "@peculiar/utils": "^2.0.2", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-x509": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-x509/-/asn1-x509-2.7.0.tgz", + "integrity": "sha512-mUn9RRrkGDnG4ALfunDmzyRW5dg+sWCj/pfnCCqEHYbkGxEpvUt6iVJv8Yw1cyp6SWZ26ZE5oSmI5SqEaen15g==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/utils": "^2.0.2", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/asn1-x509-attr": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-x509-attr/-/asn1-x509-attr-2.7.0.tgz", + "integrity": "sha512-NS8e7SOgXipkzUPLF/sce7ukpMpWjhxYsH0n6Y+bHYo4TTxOb95Zv7hqwSuL212mj5YxovjdOKQOgH1As3E94w==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-schema": "^2.7.0", + "@peculiar/asn1-x509": "^2.7.0", + "asn1js": "^3.0.6", + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/utils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@peculiar/utils/-/utils-2.0.3.tgz", + "integrity": "sha512-+oL3HPFRIZ1St2K50lWCXiioIgSoxzz7R1J3uF6neO2yl1sgmpgY6XXJH4BdpoDkMWznQTeYF6oWNDZLCdQ4eQ==", + "license": "MIT", + "dependencies": { + "tslib": "^2.8.1" + } + }, + "node_modules/@peculiar/x509": { + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/@peculiar/x509/-/x509-1.14.3.tgz", + "integrity": "sha512-C2Xj8FZ0uHWeCXXqX5B4/gVFQmtSkiuOolzAgutjTfseNOHT3pUjljDZsTSxXFGgio54bCzVFqmEOUrIVk8RDA==", + "license": "MIT", + "dependencies": { + "@peculiar/asn1-cms": "^2.6.0", + "@peculiar/asn1-csr": "^2.6.0", + "@peculiar/asn1-ecc": "^2.6.0", + "@peculiar/asn1-pkcs9": "^2.6.0", + "@peculiar/asn1-rsa": "^2.6.0", + "@peculiar/asn1-schema": "^2.6.0", + "@peculiar/asn1-x509": "^2.6.0", + "pvtsutils": "^1.3.6", + "reflect-metadata": "^0.2.2", + "tslib": "^2.8.1", + "tsyringe": "^4.10.0" + }, + "engines": { + "node": ">=20.0.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -1987,6 +2208,166 @@ "string-argv": "~0.3.1" } }, + "node_modules/@seydx/node-av-darwin-arm64": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-darwin-arm64/-/node-av-darwin-arm64-5.2.3.tgz", + "integrity": "sha512-pLX0SS3LLRoDWHCt+aWWc/P5W/BpmB5vD935KcM5nlxDG+SMjc4uyYqG+t8VVKwvmPrE2kLCsAAu/h37x4ZPYQ==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-darwin-x64": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-darwin-x64/-/node-av-darwin-x64-5.2.3.tgz", + "integrity": "sha512-kMweEjMCItEH0eolKntm6IXWFDgMlfrW4xLFTIsrLfe9w9mdAMMQIqWA+7WTCWKMGUl9z5Nc/Y5GNl4HGx8N9w==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-linux-arm64": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-linux-arm64/-/node-av-linux-arm64-5.2.3.tgz", + "integrity": "sha512-WHtPyzkIaiQtDV8Dashp84adEdMGHByMWDdHWnTIVhc29+0vrv+xZbgWKh1Y+z5XrpzSXUM36WzSttkzpDs6bw==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-linux-x64": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-linux-x64/-/node-av-linux-x64-5.2.3.tgz", + "integrity": "sha512-Nwm25hBKUl4TTv6zY2AbZJNSTor3ubilbW02NofQx0ch68fANs5zIPDvWFMZOrQwDnl5NYpO4rHB3/UnoNEBcg==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-win32-arm64-mingw": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-win32-arm64-mingw/-/node-av-win32-arm64-mingw-5.2.3.tgz", + "integrity": "sha512-0J/IArDO/jebA7a8Ep6j1XeZFF8DmDQD8x0+LrYsMQiv89i5NQJto/Bbaazfmldi+HGKBiJe+NwswzVW18pMyA==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-win32-arm64-msvc": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-win32-arm64-msvc/-/node-av-win32-arm64-msvc-5.2.3.tgz", + "integrity": "sha512-NCoOZSD4KppikZUv71xzTQEKpRMUaR2ZSzgpwGGaCLEWZ27lKRpSmE6vMQJXYuBMN5ePf36FsBdP7he+dMQpvQ==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-win32-x64-mingw": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-win32-x64-mingw/-/node-av-win32-x64-mingw-5.2.3.tgz", + "integrity": "sha512-HClIpeM+73yEAIIAgSL/vHV385ka7gYRyJ+Z3s/t4uvLWD2VGhgGhZSS7U6d1RMS75+D4wBiEqLPiXTz7NLA1w==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, + "node_modules/@seydx/node-av-win32-x64-msvc": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@seydx/node-av-win32-x64-msvc/-/node-av-win32-x64-msvc-5.2.3.tgz", + "integrity": "sha512-abGMjVfnzCV6YTGBabXL6KJEHCODUY5Bl8/WLC2taBAwZHsvj2S4B7LfoxvulJmm3HeSWqG0/ygD1nk7VyyQMw==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "dependencies": { + "unzipper": "^0.12.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + } + }, "node_modules/@shikijs/core": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-2.5.0.tgz", @@ -2074,6 +2455,24 @@ "dev": true, "license": "MIT" }, + "node_modules/@shinyoshiaki/binary-data": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/@shinyoshiaki/binary-data/-/binary-data-0.6.1.tgz", + "integrity": "sha512-7HDb/fQAop2bCmvDIzU5+69i+UJaFgIVp99h1VzK1mpg1JwSODOkjbqD7ilTYnqlnadF8C4XjpwpepxDsGY6+w==", + "license": "MIT", + "dependencies": { + "generate-function": "^2.3.1", + "is-plain-object": "^2.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@shinyoshiaki/jspack": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@shinyoshiaki/jspack/-/jspack-0.0.6.tgz", + "integrity": "sha512-SdsNhLjQh4onBlyPrn4ia1Pdx5bXT88G/LIEpOYAjx2u4xeY/m/HB5yHqlkJB1uQR3Zw4R3hBWLj46STRAN0rg==" + }, "node_modules/@stylistic/eslint-plugin": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-4.2.0.tgz", @@ -3801,6 +4200,12 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/aes-js": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz", + "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==", + "license": "MIT" + }, "node_modules/agent-base": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", @@ -3978,6 +4383,20 @@ "dequal": "^2.0.3" } }, + "node_modules/asn1js": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.10.tgz", + "integrity": "sha512-S2s3aOytiKdFRdulw2qPE51MzjzVOisppcVv7jVFR+Kw0kxwvFrDcYA0h7Ndqbmj0HkMIXYWaoj7fli8kgx1eg==", + "license": "BSD-3-Clause", + "dependencies": { + "pvtsutils": "^1.3.6", + "pvutils": "^1.1.5", + "tslib": "^2.8.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/assertion-error": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", @@ -4113,7 +4532,6 @@ "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "dev": true, "funding": [ { "type": "github", @@ -4150,6 +4568,12 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "license": "MIT" + }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -4170,7 +4594,6 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "dev": true, "funding": [ { "type": "github", @@ -4195,7 +4618,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-1.0.0.tgz", "integrity": "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w==", - "dev": true, "license": "MIT", "engines": { "node": ">=8.0.0" @@ -4520,7 +4942,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "dev": true, "license": "MIT" }, "node_modules/cose-base": { @@ -5139,6 +5560,22 @@ "node": ">= 14" } }, + "node_modules/date-fns": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.21.0" + }, + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + }, "node_modules/dayjs": { "version": "1.11.13", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz", @@ -5149,7 +5586,6 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5284,6 +5720,18 @@ "node": ">=0.3.1" } }, + "node_modules/dns-packet": { + "version": "5.6.1", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz", + "integrity": "sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw==", + "license": "MIT", + "dependencies": { + "@leichtgewicht/ip-codec": "^2.0.1" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/dom-accessibility-api": { "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", @@ -5364,6 +5812,45 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/duplexer2": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", + "integrity": "sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==", + "license": "BSD-3-Clause", + "dependencies": { + "readable-stream": "^2.0.2" + } + }, + "node_modules/duplexer2/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/duplexer2/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/duplexer2/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -5939,8 +6426,7 @@ "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fast-fifo": { "version": "1.3.2", @@ -6163,7 +6649,6 @@ "version": "11.3.2", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.2.tgz", "integrity": "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A==", - "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.2.0", @@ -6278,6 +6763,15 @@ "node": "^18.17.0 || >=20.5.0" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -6421,7 +6915,6 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true, "license": "ISC" }, "node_modules/grapheme-splitter": { @@ -6631,7 +7124,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, "funding": [ { "type": "github", @@ -6715,9 +7207,14 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true, "license": "ISC" }, + "node_modules/int64-buffer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-1.1.0.tgz", + "integrity": "sha512-94smTCQOvigN4d/2R/YDjz8YVG0Sufvv2aAh8P5m42gwhCsDAJqnbNOrxJsrADuAFAA69Q/ptGzxvNcNuIJcvw==", + "license": "MIT" + }, "node_modules/internmap": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz", @@ -6727,6 +7224,12 @@ "node": ">=12" } }, + "node_modules/ip": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", + "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==", + "license": "MIT" + }, "node_modules/ip-address": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.0.1.tgz", @@ -6807,6 +7310,24 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "license": "MIT", + "dependencies": { + "isobject": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -6837,7 +7358,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "dev": true, "license": "MIT" }, "node_modules/isexe": { @@ -6846,6 +7366,15 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/jackspeak": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", @@ -6929,7 +7458,6 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz", "integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==", - "dev": true, "license": "MIT", "dependencies": { "universalify": "^2.0.0" @@ -7446,8 +7974,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash-es": { "version": "4.17.21", @@ -8417,6 +8944,12 @@ "pathe": "^2.0.1" } }, + "node_modules/mp4box": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/mp4box/-/mp4box-0.5.4.tgz", + "integrity": "sha512-GcCH0fySxBurJtvr0dfhz0IxHZjc1RP+F+I8xw+LIwkU1a+7HJx8NCDiww1I5u4Hz6g4eR1JlGADEGJ9r4lSfA==", + "license": "BSD-3-Clause" + }, "node_modules/mrmime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", @@ -8430,8 +8963,20 @@ "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/multicast-dns": { + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-7.2.5.tgz", + "integrity": "sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==", + "license": "MIT", + "dependencies": { + "dns-packet": "^5.2.2", + "thunky": "^1.0.2" + }, + "bin": { + "multicast-dns": "cli.js" + } }, "node_modules/nanoid": { "version": "3.3.11", @@ -8468,6 +9013,27 @@ "node": ">= 0.4.0" } }, + "node_modules/node-av": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/node-av/-/node-av-5.2.3.tgz", + "integrity": "sha512-tUFIqn1kV5Ihzgzc2/g0s00Di21+On50g5TTHRpVl57b7kqzFidQr5rire8iktfltWg9Q8cRNyo8wpcxG9pkNA==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "unzipper": "^0.12.3", + "werift": "^0.22.9" + }, + "optionalDependencies": { + "@seydx/node-av-darwin-arm64": "^5.2.3", + "@seydx/node-av-darwin-x64": "^5.2.3", + "@seydx/node-av-linux-arm64": "^5.2.3", + "@seydx/node-av-linux-x64": "^5.2.3", + "@seydx/node-av-win32-arm64-mingw": "^5.2.3", + "@seydx/node-av-win32-arm64-msvc": "^5.2.3", + "@seydx/node-av-win32-x64-mingw": "^5.2.3", + "@seydx/node-av-win32-x64-msvc": "^5.2.3" + } + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -8509,6 +9075,12 @@ } } }, + "node_modules/node-int64": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", + "integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==", + "license": "MIT" + }, "node_modules/non-layered-tidy-tree-layout": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/non-layered-tidy-tree-layout/-/non-layered-tidy-tree-layout-2.0.2.tgz", @@ -8577,6 +9149,15 @@ "node": ">= 0.8.0" } }, + "node_modules/p-cancelable": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", + "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -9068,7 +9649,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "dev": true, "license": "MIT" }, "node_modules/progress": { @@ -9149,6 +9729,24 @@ "node": ">=6" } }, + "node_modules/pvtsutils": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.6.tgz", + "integrity": "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.8.1" + } + }, + "node_modules/pvutils": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.1.5.tgz", + "integrity": "sha512-KTqnxsgGiQ6ZAzZCVlJH5eOjSnvlyEgx1m8bkRJfOhmGRqfo5KLvmAlACQkrjEtOQ4B7wF9TdSLIs9O90MX9xA==", + "license": "MIT", + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/quansync": { "version": "0.2.10", "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.10.tgz", @@ -9244,6 +9842,12 @@ "node": ">=10" } }, + "node_modules/reflect-metadata": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", + "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", + "license": "Apache-2.0" + }, "node_modules/regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/regex/-/regex-6.0.1.tgz", @@ -9504,6 +10108,11 @@ "integrity": "sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==", "dev": true }, + "node_modules/rx.mini": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/rx.mini/-/rx.mini-1.4.0.tgz", + "integrity": "sha512-8w5cSc1mwNja7fl465DXOkVvIOkpvh2GW4jo31nAIvX4WTXCsRnKJGUfiDBzWtYRInEcHAUYIZfzusjIrea8gA==" + }, "node_modules/safaridriver": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/safaridriver/-/safaridriver-1.0.0.tgz", @@ -10168,6 +10777,12 @@ "b4a": "^1.6.4" } }, + "node_modules/thunky": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", + "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==", + "license": "MIT" + }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -10298,8 +10913,7 @@ "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==" }, "node_modules/tsx": { "version": "4.19.4", @@ -10321,6 +10935,30 @@ "fsevents": "~2.3.3" } }, + "node_modules/tsyringe": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/tsyringe/-/tsyringe-4.10.0.tgz", + "integrity": "sha512-axr3IdNuVIxnaK5XGEUFTu3YmAQ6lllgrvqfEoR16g/HGnYY/6We4oWENtAnzK6/LpJ2ur9PAb80RBt7/U4ugw==", + "license": "MIT", + "dependencies": { + "tslib": "^1.9.3" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/tsyringe/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "license": "0BSD" + }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "license": "Unlicense" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -10520,12 +11158,24 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 10.0.0" } }, + "node_modules/unzipper": { + "version": "0.12.3", + "resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.12.3.tgz", + "integrity": "sha512-PZ8hTS+AqcGxsaQntl3IRBw65QrBI6lxzqDEL7IAo/XCEqRTKGfOX56Vea5TH9SZczRVxuzk1re04z/YjuYCJA==", + "license": "MIT", + "dependencies": { + "bluebird": "~3.7.2", + "duplexer2": "~0.1.4", + "fs-extra": "^11.2.0", + "graceful-fs": "^4.2.2", + "node-int64": "^0.4.0" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -10556,7 +11206,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true, "license": "MIT" }, "node_modules/uuid": { @@ -11800,6 +12449,131 @@ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", "dev": true }, + "node_modules/werift": { + "version": "0.22.9", + "resolved": "https://registry.npmjs.org/werift/-/werift-0.22.9.tgz", + "integrity": "sha512-TE9AxskSRWBMYm0MBRllfnKVXQelqC76JCvyolQyVWpmKabfY5BA/cuvkGg+71JWn3QrGih1YWtpIWGPqoxcoA==", + "license": "MIT", + "dependencies": { + "@fidm/x509": "^1.2.1", + "@minhducsun2002/leb128": "^1.0.0", + "@noble/curves": "^1.8.1", + "@peculiar/x509": "^1.12.3", + "@shinyoshiaki/binary-data": "^0.6.1", + "@shinyoshiaki/jspack": "^0.0.6", + "aes-js": "^3.1.2", + "buffer": "^6.0.3", + "debug": "4.4.0", + "fast-deep-equal": "^3.1.3", + "int64-buffer": "1.1.0", + "ip": "^2.0.1", + "mp4box": "^0.5.3", + "multicast-dns": "^7.2.5", + "tweetnacl": "^1.0.3", + "werift-common": "*", + "werift-dtls": "*", + "werift-ice": "*", + "werift-rtp": "*", + "werift-sctp": "*" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/werift-common": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/werift-common/-/werift-common-0.0.3.tgz", + "integrity": "sha512-ma3E4BqKTyZVLhrdfTVs2T1tg9seeUtKMRn5e64LwgrogWa62+3LAUoLBUSl1yPWhgSkXId7GmcHuWDen9IJeQ==", + "license": "MIT", + "dependencies": { + "@shinyoshiaki/jspack": "^0.0.6", + "debug": "^4.4.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/werift-dtls": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/werift-dtls/-/werift-dtls-0.5.7.tgz", + "integrity": "sha512-z2fjbP7fFUFmu/Ky4bCKXzdgPTtmSY1DYi0TUf3GG2zJT4jMQ3TQmGY8y7BSSNGetvL4h3pRZ5un0EcSOWpPog==", + "license": "MIT", + "dependencies": { + "@fidm/x509": "^1.2.1", + "@noble/curves": "^1.3.0", + "@peculiar/x509": "^1.9.2", + "@shinyoshiaki/binary-data": "^0.6.1", + "date-fns": "^2.29.3", + "lodash": "^4.17.21", + "rx.mini": "^1.2.2", + "tweetnacl": "^1.0.3" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/werift-ice": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/werift-ice/-/werift-ice-0.2.2.tgz", + "integrity": "sha512-td52pHp+JmFnUn5jfDr/SSNO0dMCbknhuPdN1tFp9cfRj5jaktN63qnAdUuZC20QCC3ETWdsOthcm+RalHpFCQ==", + "license": "MIT", + "dependencies": { + "@shinyoshiaki/jspack": "^0.0.6", + "buffer-crc32": "^1.0.0", + "debug": "^4.3.4", + "int64-buffer": "^1.0.1", + "ip": "^2.0.1", + "lodash": "^4.17.21", + "multicast-dns": "^7.2.5", + "p-cancelable": "^2.1.1", + "rx.mini": "^1.2.2" + } + }, + "node_modules/werift-rtp": { + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/werift-rtp/-/werift-rtp-0.8.8.tgz", + "integrity": "sha512-GiYMSdvCyScQaw5bnEsraSoHUVZpjfokJAiLV4R1FsiB06t6XiebPYPpkqB9nYNNKiA8Z/cYWsym7wISq1sYSQ==", + "license": "MIT", + "dependencies": { + "@minhducsun2002/leb128": "^1.0.0", + "@shinyoshiaki/jspack": "^0.0.6", + "aes-js": "^3.1.2", + "buffer": "^6.0.3", + "mp4box": "^0.5.3" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/werift-sctp": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/werift-sctp/-/werift-sctp-0.0.11.tgz", + "integrity": "sha512-7109yuI5U7NTEHjqjn0A8VeynytkgVaxM6lRr1Ziv0D8bPcaB8A7U/P88M7WaCpWDoELHoXiRUjQycMWStIgjQ==", + "license": "MIT", + "dependencies": { + "@shinyoshiaki/jspack": "^0.0.6" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/werift/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/whatwg-encoding": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", @@ -12134,6 +12908,21 @@ "peerDependencies": { "mediabunny": "^1.0.0" } + }, + "packages/server": { + "name": "@mediabunny/server", + "version": "1.43.1", + "license": "MPL-2.0", + "dependencies": { + "node-av": "^5.2.3" + }, + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/Vanilagy" + }, + "peerDependencies": { + "mediabunny": "^1.0.0" + } } } } diff --git a/packages/aac-encoder/src/encoder.ts b/packages/aac-encoder/src/encoder.ts index 61421fd..7b80e5f 100644 --- a/packages/aac-encoder/src/encoder.ts +++ b/packages/aac-encoder/src/encoder.ts @@ -276,6 +276,8 @@ class AacEncoder extends CustomAudioEncoder { } } +let registered = false; + /** * Registers the AAC encoder, which Mediabunny will then use automatically when applicable. Make sure to call this * function before starting any encoding task. @@ -295,6 +297,11 @@ class AacEncoder extends CustomAudioEncoder { * @public */ export const registerAacEncoder = () => { + if (registered) { + return; + } + registered = true; + registerEncoder(AacEncoder); }; diff --git a/packages/ac3/src/decoder.ts b/packages/ac3/src/decoder.ts index a676073..49d3d8e 100644 --- a/packages/ac3/src/decoder.ts +++ b/packages/ac3/src/decoder.ts @@ -61,6 +61,8 @@ class Ac3Decoder extends CustomAudioDecoder { } } +let registered = false; + /** * Registers AC-3 and E-AC-3 decoders, which Mediabunny will then use automatically when applicable. Make sure to call * this function before starting any decoding task. @@ -69,5 +71,10 @@ class Ac3Decoder extends CustomAudioDecoder { * @public */ export const registerAc3Decoder = () => { + if (registered) { + return; + } + registered = true; + registerDecoder(Ac3Decoder); }; diff --git a/packages/flac-encoder/src/encoder.ts b/packages/flac-encoder/src/encoder.ts index d2706a6..7e54d65 100644 --- a/packages/flac-encoder/src/encoder.ts +++ b/packages/flac-encoder/src/encoder.ts @@ -197,6 +197,8 @@ class FlacEncoder extends CustomAudioEncoder { } } +let registered = false; + /** * Registers the FLAC encoder, which Mediabunny will then use automatically when applicable. Make sure to call this * function before starting any encoding task. The FLAC encoder will automatically determine the output bit depth @@ -217,6 +219,11 @@ class FlacEncoder extends CustomAudioEncoder { * @public */ export const registerFlacEncoder = () => { + if (registered) { + return; + } + registered = true; + registerEncoder(FlacEncoder); }; diff --git a/packages/mp3-encoder/src/index.ts b/packages/mp3-encoder/src/index.ts index ad32601..6f9abc3 100644 --- a/packages/mp3-encoder/src/index.ts +++ b/packages/mp3-encoder/src/index.ts @@ -212,6 +212,8 @@ class Mp3Encoder extends CustomAudioEncoder { } } +let registered = false; + /** * Registers the LAME MP3 encoder, which Mediabunny will then use automatically when applicable. Make sure to call this * function before starting any encoding task. @@ -231,6 +233,11 @@ class Mp3Encoder extends CustomAudioEncoder { * @public */ export const registerMp3Encoder = () => { + if (registered) { + return; + } + registered = true; + registerEncoder(Mp3Encoder); }; diff --git a/packages/server/LICENSE b/packages/server/LICENSE new file mode 100644 index 0000000..d0a1fa1 --- /dev/null +++ b/packages/server/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/packages/server/README.md b/packages/server/README.md new file mode 100644 index 0000000..4d94406 --- /dev/null +++ b/packages/server/README.md @@ -0,0 +1 @@ +todo \ No newline at end of file diff --git a/packages/server/api-extractor.json b/packages/server/api-extractor.json new file mode 100644 index 0000000..fafe3a5 --- /dev/null +++ b/packages/server/api-extractor.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "dist/modules/src/index.d.ts", + "bundledPackages": [], + "compiler": {}, + "apiReport": { + "enabled": false + }, + "docModel": { + "enabled": false + }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "dist/mediabunny-flac-encoder.d.ts" + }, + "tsdocMetadata": { + "enabled": false + }, + "messages": { + "compilerMessageReporting": { + "default": { + "logLevel": "warning" + } + }, + "extractorMessageReporting": { + "default": { + "logLevel": "warning" + } + }, + "tsdocMessageReporting": { + "default": { + "logLevel": "warning" + } + } + }, + "newlineKind": "lf" +} diff --git a/packages/server/package.json b/packages/server/package.json new file mode 100644 index 0000000..6290fbb --- /dev/null +++ b/packages/server/package.json @@ -0,0 +1,54 @@ +{ + "name": "@mediabunny/server", + "author": "Vanilagy", + "version": "1.43.1", + "description": "FLAC encoder extension for Mediabunny, based on libFLAC.", + "main": "./dist/bundles/mediabunny-server.cjs", + "module": "./dist/bundles/mediabunny-server.mjs", + "types": "./dist/modules/src/index.d.ts", + "exports": { + "types": "./dist/modules/src/index.d.ts", + "import": "./dist/bundles/mediabunny-server.mjs", + "require": "./dist/bundles/mediabunny-server.cjs" + }, + "files": [ + "README.md", + "package.json", + "LICENSE", + "dist", + "src" + ], + "browser": { + "worker_threads": false + }, + "sideEffects": false, + "license": "MPL-2.0", + "repository": { + "type": "git", + "url": "git+https://github.com/Vanilagy/mediabunny.git", + "directory": "packages/server" + }, + "bugs": { + "url": "https://github.com/Vanilagy/mediabunny/issues" + }, + "homepage": "https://mediabunny.dev/guide/extensions/server", + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/Vanilagy" + }, + "dependencies": { + "node-av": "^5.2.3" + }, + "peerDependencies": { + "mediabunny": "^1.0.0" + }, + "keywords": [ + "flac", + "encoding", + "codec", + "mediabunny", + "lossless", + "browser", + "wasm" + ] +} diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts new file mode 100644 index 0000000..bc6dd28 --- /dev/null +++ b/packages/server/src/index.ts @@ -0,0 +1,28 @@ +import { registerDecoder, registerEncoder } from 'mediabunny'; +import { NodeAvVideoDecoder } from './video-decoder'; +import * as NodeAv from 'node-av'; +import { NodeAvVideoEncoder } from './video-encoder'; + +const SERVER_LOADED_SYMBOL = Symbol.for('@mediabunny/server loaded'); +if ((globalThis as Record)[SERVER_LOADED_SYMBOL]) { + console.error( + '[WARNING]\n@mediabunny/server was loaded twice.' + + ' This will likely cause the package not to work correctly.' + + ' Check if multiple dependencies are importing different versions of @mediabunny/server,' + + ' or if something is being bundled incorrectly.', + ); +} +(globalThis as Record)[SERVER_LOADED_SYMBOL] = true; + +let registered = false; +export const registerMediabunnyServer = () => { + if (registered) { + return; + } + registered = true; + + NodeAv.Log.setLevel(NodeAv.AV_LOG_ERROR); + + registerDecoder(NodeAvVideoDecoder); + registerEncoder(NodeAvVideoEncoder); +}; diff --git a/packages/server/src/misc.ts b/packages/server/src/misc.ts new file mode 100644 index 0000000..ab6ab63 --- /dev/null +++ b/packages/server/src/misc.ts @@ -0,0 +1,182 @@ +import { VideoSamplePixelFormat, VideoCodec } from 'mediabunny'; +import * as NodeAv from 'node-av'; + +export const CODEC_TO_CODEC_ID: Record = { + avc: NodeAv.AV_CODEC_ID_H264, + hevc: NodeAv.AV_CODEC_ID_HEVC, + vp8: NodeAv.AV_CODEC_ID_VP8, + vp9: NodeAv.AV_CODEC_ID_VP9, + av1: NodeAv.AV_CODEC_ID_AV1, +}; + +let cachedHardwareContext: NodeAv.HardwareContext | null | undefined = undefined; +export const getHardwareContext = (): NodeAv.HardwareContext | null => { + if (cachedHardwareContext === undefined) { + cachedHardwareContext = NodeAv.HardwareContext.auto(); + } + return cachedHardwareContext; +}; + +const hardwareDecoderCodecCache = new Map(); +export const getHardwareDecoderCodec = (codecId: NodeAv.AVCodecID): NodeAv.Codec | null => { + if (!hardwareDecoderCodecCache.has(codecId)) { + const hw = getHardwareContext(); + hardwareDecoderCodecCache.set(codecId, hw?.getDecoderCodec(codecId) ?? null); + } + return hardwareDecoderCodecCache.get(codecId)!; +}; + +const hardwareEncoderCodecCache = new Map(); +export const getHardwareEncoderCodec = (codecId: NodeAv.AVCodecID): NodeAv.Codec | null => { + if (!hardwareEncoderCodecCache.has(codecId)) { + const hw = getHardwareContext(); + hardwareEncoderCodecCache.set(codecId, hw?.getEncoderCodec(codecId) ?? null); + } + return hardwareEncoderCodecCache.get(codecId)!; +}; + +export const mapColorPrimaries = (primaries: string) => { + switch (primaries) { + case 'bt709': return NodeAv.AVCOL_PRI_BT709; + case 'bt470bg': return NodeAv.AVCOL_PRI_BT470BG; + case 'smpte170m': return NodeAv.AVCOL_PRI_SMPTE170M; + case 'bt2020': return NodeAv.AVCOL_PRI_BT2020; + case 'smpte432': return NodeAv.AVCOL_PRI_SMPTE432; + } + + return null; +}; + +export const unmapColorPrimaries = (primaries: number) => { + switch (primaries) { + case NodeAv.AVCOL_PRI_BT709: return 'bt709'; + case NodeAv.AVCOL_PRI_BT470BG: return 'bt470bg'; + case NodeAv.AVCOL_PRI_SMPTE170M: return 'smpte170m'; + case NodeAv.AVCOL_PRI_BT2020: return 'bt2020'; + case NodeAv.AVCOL_PRI_SMPTE432: return 'smpte432'; + } + + return null; +}; + +export const mapTransferCharacteristics = (transfer: string) => { + switch (transfer) { + case 'bt709': return NodeAv.AVCOL_TRC_BT709; + case 'smpte170m': return NodeAv.AVCOL_TRC_SMPTE170M; + case 'iec61966-2-1': return NodeAv.AVCOL_TRC_IEC61966_2_1; + case 'linear': return NodeAv.AVCOL_TRC_LINEAR; + case 'pq': return NodeAv.AVCOL_TRC_SMPTE2084; + case 'hlg': return NodeAv.AVCOL_TRC_ARIB_STD_B67; + } + + return null; +}; + +export const unmapTransferCharacteristics = (transfer: number) => { + switch (transfer) { + case NodeAv.AVCOL_TRC_BT709: return 'bt709'; + case NodeAv.AVCOL_TRC_SMPTE170M: return 'smpte170m'; + case NodeAv.AVCOL_TRC_IEC61966_2_1: return 'iec61966-2-1'; + case NodeAv.AVCOL_TRC_LINEAR: return 'linear'; + case NodeAv.AVCOL_TRC_SMPTE2084: return 'pq'; + case NodeAv.AVCOL_TRC_ARIB_STD_B67: return 'hlg'; + } + + return null; +}; + +export const mapMatrixCoefficients = (matrix: string) => { + switch (matrix) { + case 'rgb': return NodeAv.AVCOL_SPC_RGB; + case 'bt709': return NodeAv.AVCOL_SPC_BT709; + case 'bt470bg': return NodeAv.AVCOL_SPC_BT470BG; + case 'smpte170m': return NodeAv.AVCOL_SPC_SMPTE170M; + case 'bt2020-ncl': return NodeAv.AVCOL_SPC_BT2020_NCL; + } + + return null; +}; + +export const unmapMatrixCoefficients = (matrix: number) => { + switch (matrix) { + case NodeAv.AVCOL_SPC_RGB: return 'rgb'; + case NodeAv.AVCOL_SPC_BT709: return 'bt709'; + case NodeAv.AVCOL_SPC_BT470BG: return 'bt470bg'; + case NodeAv.AVCOL_SPC_SMPTE170M: return 'smpte170m'; + case NodeAv.AVCOL_SPC_BT2020_NCL: return 'bt2020-ncl'; + } + + return null; +}; + +export const toPixelFormat = (ffmpegPixelFormat: NodeAv.AVPixelFormat): VideoSamplePixelFormat | null => { + switch (ffmpegPixelFormat) { + case NodeAv.AV_PIX_FMT_YUV420P: return 'I420'; + // "deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range" + case NodeAv.AV_PIX_FMT_YUVJ420P: return 'I420'; + case NodeAv.AV_PIX_FMT_YUV420P10LE: return 'I420P10'; + case NodeAv.AV_PIX_FMT_YUV420P12LE: return 'I420P12'; + case NodeAv.AV_PIX_FMT_YUVA420P: return 'I420A'; + case NodeAv.AV_PIX_FMT_YUVA420P10LE: return 'I420AP10'; + + case NodeAv.AV_PIX_FMT_YUV422P: return 'I422'; + // "deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range" + case NodeAv.AV_PIX_FMT_YUVJ422P: return 'I422'; + case NodeAv.AV_PIX_FMT_YUV422P10LE: return 'I422P10'; + case NodeAv.AV_PIX_FMT_YUV422P12LE: return 'I422P12'; + case NodeAv.AV_PIX_FMT_YUVA422P: return 'I422A'; + case NodeAv.AV_PIX_FMT_YUVA422P10LE: return 'I422AP10'; + case NodeAv.AV_PIX_FMT_YUVA422P12LE: return 'I422AP12'; + + case NodeAv.AV_PIX_FMT_YUV444P: return 'I444'; + // "deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range" + case NodeAv.AV_PIX_FMT_YUVJ444P: return 'I444'; + case NodeAv.AV_PIX_FMT_YUV444P10LE: return 'I444P10'; + case NodeAv.AV_PIX_FMT_YUV444P12LE: return 'I444P12'; + case NodeAv.AV_PIX_FMT_YUVA444P: return 'I444A'; + case NodeAv.AV_PIX_FMT_YUVA444P10LE: return 'I444AP10'; + case NodeAv.AV_PIX_FMT_YUVA444P12LE: return 'I444AP12'; + + case NodeAv.AV_PIX_FMT_NV12: return 'NV12'; + + case NodeAv.AV_PIX_FMT_RGBA: return 'RGBA'; + case NodeAv.AV_PIX_FMT_RGB0: return 'RGBX'; + case NodeAv.AV_PIX_FMT_BGRA: return 'BGRA'; + case NodeAv.AV_PIX_FMT_BGR0: return 'BGRX'; + + default: return null; + } +}; + +export const fromPixelFormat = (pixelFormat: VideoSamplePixelFormat) => { + switch (pixelFormat) { + case 'I420': return NodeAv.AV_PIX_FMT_YUV420P; + case 'I420P10': return NodeAv.AV_PIX_FMT_YUV420P10LE; + case 'I420P12': return NodeAv.AV_PIX_FMT_YUV420P12LE; + case 'I420A': return NodeAv.AV_PIX_FMT_YUVA420P; + case 'I420AP10': return NodeAv.AV_PIX_FMT_YUVA420P10LE; + + case 'I422': return NodeAv.AV_PIX_FMT_YUV422P; + case 'I422P10': return NodeAv.AV_PIX_FMT_YUV422P10LE; + case 'I422P12': return NodeAv.AV_PIX_FMT_YUV422P12LE; + case 'I422A': return NodeAv.AV_PIX_FMT_YUVA422P; + case 'I422AP10': return NodeAv.AV_PIX_FMT_YUVA422P10LE; + case 'I422AP12': return NodeAv.AV_PIX_FMT_YUVA422P12LE; + + case 'I444': return NodeAv.AV_PIX_FMT_YUV444P; + case 'I444P10': return NodeAv.AV_PIX_FMT_YUV444P10LE; + case 'I444P12': return NodeAv.AV_PIX_FMT_YUV444P12LE; + case 'I444A': return NodeAv.AV_PIX_FMT_YUVA444P; + case 'I444AP10': return NodeAv.AV_PIX_FMT_YUVA444P10LE; + case 'I444AP12': return NodeAv.AV_PIX_FMT_YUVA444P12LE; + + case 'NV12': return NodeAv.AV_PIX_FMT_NV12; + + case 'RGBA': return NodeAv.AV_PIX_FMT_RGBA; + case 'RGBX': return NodeAv.AV_PIX_FMT_RGB0; + case 'BGRA': return NodeAv.AV_PIX_FMT_BGRA; + case 'BGRX': return NodeAv.AV_PIX_FMT_BGR0; + + default: return NodeAv.AV_PIX_FMT_NONE; + } +}; diff --git a/packages/server/src/video-decoder.ts b/packages/server/src/video-decoder.ts new file mode 100644 index 0000000..6a08f06 --- /dev/null +++ b/packages/server/src/video-decoder.ts @@ -0,0 +1,211 @@ +import { CustomVideoDecoder, VideoCodec, EncodedPacket, VideoSample, MaybePromise, Rational } from 'mediabunny'; +import * as NodeAv from 'node-av'; +import { + CODEC_TO_CODEC_ID, + getHardwareDecoderCodec, + mapColorPrimaries, + mapMatrixCoefficients, + mapTransferCharacteristics, +} from './misc'; +import { binarySearchLessOrEqual, simplifyRational, toUint8Array } from '../../../src/misc'; +import { NodeAvFrameVideoSampleResource } from './video-sample'; + +export class NodeAvVideoDecoder extends CustomVideoDecoder { + frame!: NodeAv.Frame; + packet!: NodeAv.Packet; + codecContext!: NodeAv.CodecContext; + pixelAspectRatio!: Rational; + + // Bookkeeping to restore the original timing information + preciseTimings: { + microsecondTimestamp: number; + timestamp: number; + duration: number; + timestampIsValid: boolean; + durationIsValid: boolean; + }[] = []; + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + static override supports(codec: VideoCodec, config: VideoDecoderConfig): boolean { + return codec === 'avc' || codec === 'hevc' || codec === 'vp8' || codec === 'vp9' || codec === 'av1'; + } + + async init() { + this.frame = new NodeAv.Frame(); + this.frame.alloc(); + this.packet = new NodeAv.Packet(); + this.packet.alloc(); + + const codecId = CODEC_TO_CODEC_ID[this.codec]; + + let codec: NodeAv.Codec | null; + if (this.config.hardwareAcceleration !== 'prefer-hardware' || this.codec === 'av1') { + // https://github.com/opencv/opencv/issues/24430 + codec = NodeAv.Codec.findDecoder(codecId); + } else { + codec = getHardwareDecoderCodec(codecId) ?? NodeAv.Codec.findDecoder(codecId); + } + + if (!codec) { + throw new Error(`Unable to obtain libav codec for '${this.codec}'.`); + } + + const codecContext = new NodeAv.CodecContext(); + codecContext.allocContext3(codec); + + this.pixelAspectRatio = simplifyRational({ + num: (this.config.displayAspectWidth ?? this.config.codedWidth ?? 0) * (this.config.codedHeight ?? 0), + den: (this.config.displayAspectHeight ?? this.config.codedHeight ?? 0) * (this.config.codedWidth ?? 0) || 1, + }); + + codecContext.width = this.config.codedWidth ?? 0; // Fucky that the dimensions can be optional, but oh well + codecContext.height = this.config.codedHeight ?? 0; + codecContext.codecType = NodeAv.AVMEDIA_TYPE_VIDEO; + codecContext.codecId = codecId; + codecContext.extraData = this.config.description + ? Buffer.from(toUint8Array(this.config.description)) + : null; + codecContext.sampleAspectRatio = new NodeAv.Rational(this.pixelAspectRatio.num, this.pixelAspectRatio.den); + + if (this.config.colorSpace?.primaries) { + const mapped = mapColorPrimaries(this.config.colorSpace.primaries); + if (mapped !== null) { + codecContext.colorPrimaries = mapped; + } + } + if (this.config.colorSpace?.transfer) { + const mapped = mapTransferCharacteristics(this.config.colorSpace.transfer); + if (mapped !== null) { + codecContext.colorTrc = mapped; + } + } + if (this.config.colorSpace?.matrix) { + const mapped = mapMatrixCoefficients(this.config.colorSpace.matrix); + if (mapped !== null) { + codecContext.colorSpace = mapped; + } + } + if (this.config.colorSpace?.fullRange != null) { + codecContext.colorRange = this.config.colorSpace.fullRange + ? NodeAv.AVCOL_RANGE_JPEG + : NodeAv.AVCOL_RANGE_MPEG; + } + + const ret = await codecContext.open2(); + NodeAv.FFmpegError.throwIfError(ret, 'Open codec context'); + + this.codecContext = codecContext; + } + + async decode(packet: EncodedPacket) { + this.packet.isKeyframe = packet.type === 'key'; + this.packet.data = Buffer.from(packet.data); + this.packet.timeBase = { num: 1, den: 1e6 }; + this.packet.pts = BigInt(packet.microsecondTimestamp); + this.packet.dts = NodeAv.AV_NOPTS_VALUE; + this.packet.duration = BigInt(packet.microsecondDuration); + + const preciseTimingIndex = binarySearchLessOrEqual( + this.preciseTimings, + packet.microsecondTimestamp, + x => x.microsecondTimestamp, + ); + const existingEntry = preciseTimingIndex !== -1 + ? this.preciseTimings[preciseTimingIndex] + : null; + if (existingEntry && existingEntry.microsecondTimestamp === packet.microsecondTimestamp) { + if (existingEntry.timestamp !== packet.timestamp) { + // Mapping isn't unique, can't use the timestamp + existingEntry.timestampIsValid = false; + } + if (existingEntry.duration !== packet.duration) { + // Mapping isn't unique, can't use the duration + existingEntry.durationIsValid = false; + } + } else { + this.preciseTimings.splice(preciseTimingIndex + 1, 0, { + microsecondTimestamp: packet.microsecondTimestamp, + timestamp: packet.timestamp, + duration: packet.duration, + timestampIsValid: true, + durationIsValid: true, + }); + + // Make sure it doesn't grow indefinitely + if (this.preciseTimings.length > 128) { + this.preciseTimings.shift(); + } + } + + const ret = await this.codecContext.sendPacket(this.packet); + NodeAv.FFmpegError.throwIfError(ret, 'Send packet'); + + while (true) { + const receiveRet = await this.codecContext.receiveFrame(this.frame); + if (receiveRet === NodeAv.AVERROR_EAGAIN || receiveRet === NodeAv.AVERROR_EOF) { + break; + } + + this.receiveFrame(receiveRet); + } + } + + receiveFrame(ret: number) { + NodeAv.FFmpegError.throwIfError(ret, 'Receive frame'); + + this.frame.sampleAspectRatio = new NodeAv.Rational(this.pixelAspectRatio.num, this.pixelAspectRatio.den); + + let timestamp = Number(this.frame.pts) / 1e6; + let duration = Number(this.frame.duration) / 1e6; + + const preciseTimingIndex = binarySearchLessOrEqual( + this.preciseTimings, + Number(this.frame.pts), + x => x.microsecondTimestamp, + ); + const entry = preciseTimingIndex !== -1 + ? this.preciseTimings[preciseTimingIndex] + : null; + + // If there's a relevant timing entry, refine the frame's timing data to get better accuracy than + // microseconds + if (entry && entry.microsecondTimestamp === Number(this.frame.pts)) { + if (entry.timestampIsValid) { + timestamp = entry.timestamp; + } + if (entry.durationIsValid) { + duration = entry.duration; + } + } + + this.onSample(new VideoSample(new NodeAvFrameVideoSampleResource(this.frame), { + timestamp, + duration, + })); + } + + async flush() { + // Send null packet to signal flush + const ret = await this.codecContext.sendPacket(null); + NodeAv.FFmpegError.throwIfError(ret, 'Flush decoder'); + + // Keep receiving frames until no more are available + while (true) { + const receiveRet = await this.codecContext.receiveFrame(this.frame); + if (receiveRet === NodeAv.AVERROR_EAGAIN || receiveRet === NodeAv.AVERROR_EOF) { + // No more frames available + break; + } + + this.receiveFrame(receiveRet); + } + + this.codecContext.flushBuffers(); + } + + close(): MaybePromise { + this.codecContext.freeContext(); + this.frame.free(); + this.packet.free(); + } +} diff --git a/packages/server/src/video-encoder.ts b/packages/server/src/video-encoder.ts new file mode 100644 index 0000000..4dbea2d --- /dev/null +++ b/packages/server/src/video-encoder.ts @@ -0,0 +1,563 @@ +import { CustomVideoEncoder, MaybePromise, QUALITY_MEDIUM, VideoCodec, VideoSample, EncodedPacket } from 'mediabunny'; +import * as NodeAv from 'node-av'; +import { + CODEC_TO_CODEC_ID, + fromPixelFormat, + getHardwareEncoderCodec, + mapColorPrimaries, + mapMatrixCoefficients, + mapTransferCharacteristics, + unmapColorPrimaries, + unmapMatrixCoefficients, + unmapTransferCharacteristics, +} from './misc'; +import { NodeAvFrameVideoSampleResource } from './video-sample'; +import { + AvcNalUnitType, + extractAv1CodecInfoFromPacket, + extractAvcDecoderConfigurationRecord, + extractHevcDecoderConfigurationRecord, + extractNalUnitTypeForAvc, + extractNalUnitTypeForHevc, + extractVp9CodecInfoFromPacket, + HevcNalUnitType, + iterateNalUnitsInAnnexB, + NalUnitLocation, + serializeAvcDecoderConfigurationRecord, + serializeHevcDecoderConfigurationRecord, +} from '../../../src/codec-data'; +import { extractVideoCodecString } from '../../../src/codec'; +import { assert, binarySearchLessOrEqual, simplifyRational, toUint8Array } from '../../../src/misc'; + +export class NodeAvVideoEncoder extends CustomVideoEncoder { + frame!: NodeAv.Frame; + packet!: NodeAv.Packet; + avCodec!: NodeAv.Codec; + codecContext: NodeAv.CodecContext | null = null; + lastBuffer: Buffer | null = null; + colorSpaceSet = false; + packetEmitted = false; + + scaler: NodeAv.SoftwareScaleContext | null = null; + lastScalerKey: string | null = null; + dstFrame: NodeAv.Frame | null = null; + + // Bookkeeping to restore the original timing information + preciseTimings: { + microsecondTimestamp: number; + timestamp: number; + duration: number; + timestampIsValid: boolean; + durationIsValid: boolean; + }[] = []; + + static override supports(codec: VideoCodec, config: VideoEncoderConfig): boolean { + return (codec === 'avc' || codec === 'hevc' || codec === 'vp8' || codec === 'vp9' || codec === 'av1') + && !(config.alpha === 'keep' || config.bitrateMode === 'quantizer'); + } + + async init(): Promise { + this.frame = new NodeAv.Frame(); + this.frame.alloc(); + this.frame.timeBase = new NodeAv.Rational(1, 1e6); + + this.packet = new NodeAv.Packet(); + this.packet.alloc(); + + const codecId = CODEC_TO_CODEC_ID[this.codec]; + + let codec: NodeAv.Codec | null = null; + if (this.config.hardwareAcceleration === 'prefer-software') { + codec = NodeAv.Codec.findEncoder(codecId); + } else { + codec = getHardwareEncoderCodec(codecId) ?? NodeAv.Codec.findEncoder(codecId); + } + + if (!codec) { + throw new Error(`Unable to obtain libav codec for '${this.codec}'.`); + } + + this.avCodec = codec; + + await this.createCodecContext(); + } + + async createCodecContext() { + assert(this.codecContext === null); + + const codecContext = new NodeAv.CodecContext(); + codecContext.allocContext3(this.avCodec); + + let pixelFormat = NodeAv.AV_PIX_FMT_YUV420P; + if (this.avCodec.pixelFormats && !this.avCodec.pixelFormats.includes(NodeAv.AV_PIX_FMT_YUV420P)) { + pixelFormat = this.avCodec.pixelFormats[0]!; + } + + const pixelAspectRatio = simplifyRational({ + num: (this.config.displayWidth ?? this.config.width) * this.config.height, + den: (this.config.displayHeight ?? this.config.height) * this.config.width, + }); + + codecContext.width = this.config.width; + codecContext.height = this.config.height; + codecContext.pixelFormat = pixelFormat; + codecContext.timeBase = new NodeAv.Rational(1, 1e6); + codecContext.gopSize = 60; + codecContext.framerate = new NodeAv.Rational(Math.round(this.config.framerate ?? 0) || 30, 1); + codecContext.bitRate = BigInt( + this.config.bitrate ?? QUALITY_MEDIUM._toVideoBitrate(this.codec, this.config.width, this.config.height), + ); + codecContext.sampleAspectRatio = new NodeAv.Rational(pixelAspectRatio.num, pixelAspectRatio.den); + + if (this.config.bitrateMode === 'constant') { + codecContext.rcMinRate = codecContext.bitRate; + codecContext.rcMaxRate = codecContext.bitRate; + } + + const isRealtime = this.config.latencyMode === 'realtime'; + + if (this.avCodec.name === 'libx264') { + if (isRealtime) { + codecContext.setOption('tune', 'zerolatency'); + codecContext.setOption('preset', 'ultrafast'); + } + } else if (this.avCodec.name === 'libx265') { + codecContext.setOption('x265-params', 'log-level=error'); + + if (isRealtime) { + codecContext.setOption('tune', 'zerolatency'); + codecContext.setOption('preset', 'ultrafast'); + } + } else if (this.avCodec.name === 'libvpx') { + if (isRealtime) { + codecContext.setOption('deadline', 'realtime'); + codecContext.setOption('cpu-used', '8'); + } else { + codecContext.setOption('cpu-used', '8'); + } + } else if (this.avCodec.name === 'libvpx-vp9') { + codecContext.setOption('deadline', 'realtime'); + + if (isRealtime) { + codecContext.setOption('cpu-used', '8'); + } else { + codecContext.setOption('cpu-used', '5'); + } + } else if (this.avCodec.name === 'libsvtav1') { + // SVTAV1 can be silenced by setting an environment variable: + // https://superuser.com/questions/1775236/how-to-remove-svt-av1-information-from-ffmpeg-output + process.env['SVT_LOG'] = '1'; + + if (isRealtime) { + codecContext.setOption('preset', '12'); + } + } + + const ret = await codecContext.open2(); + NodeAv.FFmpegError.throwIfError(ret, 'Open codec context'); + + this.codecContext = codecContext; + } + + async encode(videoSample: VideoSample, options: VideoEncoderEncodeOptions): Promise { + if (this.codecContext === null) { + await this.createCodecContext(); + assert(this.codecContext); + } + + const underlyingData = videoSample.getUnderlyingData(); + + if (underlyingData instanceof NodeAvFrameVideoSampleResource) { + this.frame.ref(underlyingData.frame); + } else { + if (videoSample.format === null) { + throw new Error('Cannot encode foreign VideoSample with unknown (null) format.'); + } + + // Copy frame data from VideoSample to FFmpeg Frame + this.frame.format = fromPixelFormat(videoSample.format); + this.frame.width = videoSample.codedWidth; + this.frame.height = videoSample.codedHeight; + this.frame.pts = BigInt(videoSample.microsecondTimestamp); + this.frame.duration = BigInt(videoSample.microsecondDuration); + this.frame.colorPrimaries = mapColorPrimaries(videoSample.colorSpace.primaries ?? 'unknown') + ?? NodeAv.AVCOL_PRI_UNSPECIFIED; + this.frame.colorSpace = mapMatrixCoefficients(videoSample.colorSpace.matrix ?? 'unknown') + ?? NodeAv.AVCOL_SPC_UNSPECIFIED; + this.frame.colorTrc = mapTransferCharacteristics(videoSample.colorSpace.transfer ?? 'unknown') + ?? NodeAv.AVCOL_TRC_UNSPECIFIED; + this.frame.colorRange = videoSample.colorSpace.fullRange === false + ? NodeAv.AVCOL_RANGE_MPEG + : videoSample.colorSpace.fullRange === true + ? NodeAv.AVCOL_RANGE_JPEG + : NodeAv.AVCOL_RANGE_UNSPECIFIED; + + this.frame.keyFrame = options?.keyFrame ? 1 : 0; + + const size = videoSample.allocationSize(); + if (!this.lastBuffer || this.lastBuffer.byteLength !== size) { + this.lastBuffer = Buffer.from({ length: size }); + } + + await videoSample.copyTo(this.lastBuffer); + this.frame.fromBuffer(this.lastBuffer); + } + + if (!this.colorSpaceSet) { + this.codecContext.colorPrimaries = this.frame.colorPrimaries; + this.codecContext.colorTrc = this.frame.colorTrc; + this.codecContext.colorSpace = this.frame.colorSpace; + this.codecContext.colorRange = this.frame.colorRange; + + this.colorSpaceSet = true; + } + + let frameToEncode = this.frame; + + const requiresScaler + = this.codecContext.pixelFormat !== this.frame.format + || this.codecContext.width !== this.frame.width + || this.codecContext.height !== this.frame.height; + + if (requiresScaler) { + if (!this.scaler) { + this.scaler = new NodeAv.SoftwareScaleContext(); + } + + const key = `${this.frame.width}x${this.frame.height}:${this.frame.format}`; + const needsConfigure = key !== this.lastScalerKey; + + if (needsConfigure) { + this.scaler.getContext( + this.frame.width, this.frame.height, this.frame.format as NodeAv.AVPixelFormat, + this.codecContext.width, this.codecContext.height, this.codecContext.pixelFormat, + NodeAv.SWS_FAST_BILINEAR, + ); + + this.lastScalerKey = key; + + const ret = this.scaler.initContext(); + NodeAv.FFmpegError.throwIfError(ret, 'initContext'); + } + + if (!this.dstFrame) { + this.dstFrame = new NodeAv.Frame(); + this.dstFrame.alloc(); + this.dstFrame.width = this.codecContext.width; + this.dstFrame.height = this.codecContext.height; + this.dstFrame.format = this.codecContext.pixelFormat; + this.dstFrame.allocBuffer(); + } + + await this.scaler.scaleFrame(this.dstFrame, this.frame); + this.dstFrame.copyProps(this.frame); + frameToEncode = this.dstFrame; + } + + const preciseTimingIndex = binarySearchLessOrEqual( + this.preciseTimings, + videoSample.microsecondTimestamp, + x => x.microsecondTimestamp, + ); + const existingEntry = preciseTimingIndex !== -1 + ? this.preciseTimings[preciseTimingIndex] + : null; + if (existingEntry && existingEntry.microsecondTimestamp === videoSample.microsecondTimestamp) { + if (existingEntry.timestamp !== videoSample.timestamp) { + // Mapping isn't unique, can't use the timestamp + existingEntry.timestampIsValid = false; + } + if (existingEntry.duration !== videoSample.duration) { + // Mapping isn't unique, can't use the duration + existingEntry.durationIsValid = false; + } + } else { + this.preciseTimings.splice(preciseTimingIndex + 1, 0, { + microsecondTimestamp: videoSample.microsecondTimestamp, + timestamp: videoSample.timestamp, + duration: videoSample.duration, + timestampIsValid: true, + durationIsValid: true, + }); + + // Make sure it doesn't grow indefinitely + if (this.preciseTimings.length > 128) { + this.preciseTimings.shift(); + } + } + + const ret = await this.codecContext.sendFrame(frameToEncode); + NodeAv.FFmpegError.throwIfError(ret, 'Send frame'); + + // Keep receiving packets until no more are available for this frame + while (true) { + const receiveRet = await this.codecContext.receivePacket(this.packet); + if (receiveRet === NodeAv.AVERROR_EAGAIN || receiveRet === NodeAv.AVERROR_EOF) { + break; + } + + this.receivePacket(ret); + } + } + + receivePacket(ret: number) { + assert(this.codecContext); + NodeAv.FFmpegError.throwIfError(ret, 'Receive packet'); + + if (!this.packet.data) { + return; + } + let packetData = toUint8Array(this.packet.data); + + let timestamp = Number(this.packet.pts) / 1e6; + let duration = Number(this.packet.duration) / 1e6; + + const preciseTimingIndex = binarySearchLessOrEqual( + this.preciseTimings, + Number(this.packet.pts), + x => x.microsecondTimestamp, + ); + const entry = preciseTimingIndex !== -1 + ? this.preciseTimings[preciseTimingIndex] + : null; + + // If there's a relevant timing entry, refine the packet's timing data to get better accuracy than + // microseconds + if (entry && entry.microsecondTimestamp === Number(this.packet.pts)) { + if (entry.timestampIsValid) { + timestamp = entry.timestamp; + } + if (entry.durationIsValid) { + duration = entry.duration; + } + } + + const metadata: EncodedVideoChunkMetadata = {}; + let decoderConfigCodecString: string | null = null; + let decoderConfigDescription: Uint8Array | null = null; + + if (this.codec === 'avc' || this.codec === 'hevc') { + let expectsAnnexB = false; + if (this.codec === 'avc') { + expectsAnnexB = this.config.avc?.format === 'annexb'; + } else { + // eslint-disable-next-line @stylistic/max-len + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access + expectsAnnexB = (this.config as any).hevc?.format === 'annexb'; + } + + if (!this.packetEmitted) { + let serializedRecord: Uint8Array; + + if (this.codec === 'avc') { + const record = extractAvcDecoderConfigurationRecord(this.packet.data); + if (!record) { + throw new Error('Invalid AVC data, could not extract decoder configuration record.'); + } + + serializedRecord = serializeAvcDecoderConfigurationRecord(record); + } else { + const record = extractHevcDecoderConfigurationRecord(this.packet.data); + if (!record) { + throw new Error('Invalid HEVC data, could not extract decoder configuration record.'); + } + + serializedRecord = serializeHevcDecoderConfigurationRecord(record); + } + + decoderConfigCodecString = extractVideoCodecString({ + width: this.config.width, + height: this.config.height, + codec: this.codec, + codecDescription: serializedRecord, + colorSpace: null, + avcType: 1, + avcCodecInfo: null, + hevcCodecInfo: null, + vp9CodecInfo: null, + av1CodecInfo: null, + }); + + if (!expectsAnnexB) { + decoderConfigDescription = serializedRecord; + } + } + + if (!expectsAnnexB) { + const NAL_UNIT_LENGTH_SIZE = 4; + + const nalUnits: NalUnitLocation[] = []; + for (const loc of iterateNalUnitsInAnnexB(packetData)) { + if (this.codec === 'avc') { + const naluType = extractNalUnitTypeForAvc(packetData[loc.offset]!); + + // Certain NALUs get stripped + if ( + naluType !== AvcNalUnitType.SPS + && naluType !== AvcNalUnitType.PPS + && naluType !== AvcNalUnitType.SPS_EXT + ) { + nalUnits.push(loc); + } + } else { + const naluType = extractNalUnitTypeForHevc(packetData[loc.offset]!); + + // Certain NALUs get stripped + if ( + naluType !== HevcNalUnitType.SPS_NUT + && naluType !== HevcNalUnitType.PPS_NUT + && naluType !== HevcNalUnitType.VPS_NUT + ) { + nalUnits.push(loc); + } + } + } + + let totalSize = 0; + for (const nalUnit of nalUnits) { + totalSize += NAL_UNIT_LENGTH_SIZE + nalUnit.length; + } + + const lengthPrefixedData = new Uint8Array(totalSize); + const dataView = new DataView(lengthPrefixedData.buffer); + let offset = 0; + + // Write each NAL unit with its length prefix + for (const nalUnit of nalUnits) { + const length = nalUnit.length; + + dataView.setUint32(offset, length, false); + offset += 4; + + lengthPrefixedData.set( + packetData.subarray(nalUnit.offset, nalUnit.offset + nalUnit.length), + offset, + ); + offset += nalUnit.length; + } + + packetData = lengthPrefixedData; + } + } else if (this.codec === 'vp8') { + if (!this.packetEmitted) { + decoderConfigCodecString = extractVideoCodecString({ + width: this.config.width, + height: this.config.height, + codec: 'vp8', + codecDescription: null, + colorSpace: null, + avcType: null, + avcCodecInfo: null, + hevcCodecInfo: null, + vp9CodecInfo: null, + av1CodecInfo: null, + }); + } + } else if (this.codec === 'vp9') { + if (!this.packetEmitted) { + const vp9CodecInfo = extractVp9CodecInfoFromPacket(packetData); + + decoderConfigCodecString = extractVideoCodecString({ + width: this.config.width, + height: this.config.height, + codec: 'vp9', + codecDescription: null, + colorSpace: null, + avcType: null, + avcCodecInfo: null, + hevcCodecInfo: null, + vp9CodecInfo, + av1CodecInfo: null, + }); + } + } else if (this.codec === 'av1') { + if (!this.packetEmitted) { + const av1CodecInfo = extractAv1CodecInfoFromPacket(packetData); + + decoderConfigCodecString = extractVideoCodecString({ + width: this.config.width, + height: this.config.height, + codec: 'av1', + codecDescription: null, + colorSpace: null, + avcType: null, + avcCodecInfo: null, + hevcCodecInfo: null, + vp9CodecInfo: null, + av1CodecInfo, + }); + } + } else { + throw new Error('Unreachable.'); + } + + const packet = new EncodedPacket( + packetData, + this.packet.isKeyframe ? 'key' : 'delta', + timestamp, + duration, + ); + + if (decoderConfigCodecString !== null) { + // Create the decoder config + metadata.decoderConfig = { + codec: decoderConfigCodecString, + codedWidth: this.codecContext.width, + codedHeight: this.codecContext.height, + displayAspectWidth: this.config.displayWidth ?? this.codecContext.width, + displayAspectHeight: this.config.displayHeight ?? this.codecContext.height, + description: decoderConfigDescription ?? undefined, + colorSpace: { + primaries: + unmapColorPrimaries(this.codecContext.colorPrimaries) as VideoColorPrimaries, + matrix: + unmapMatrixCoefficients(this.codecContext.colorSpace) as VideoMatrixCoefficients, + transfer: + unmapTransferCharacteristics(this.codecContext.colorTrc) as VideoTransferCharacteristics, + fullRange: this.codecContext.colorRange === NodeAv.AVCOL_RANGE_JPEG + ? true + : this.codecContext.colorRange === NodeAv.AVCOL_RANGE_MPEG + ? false + : undefined, + }, + }; + } + + this.onPacket(packet, metadata); + this.packetEmitted = true; + } + + async flush(): Promise { + if (this.codecContext) { + // Send null frame to signal flush + const ret = await this.codecContext.sendFrame(null); + NodeAv.FFmpegError.throwIfError(ret, 'Send frame'); + + // Keep receiving packets until no more are available + while (true) { + const receiveRet = await this.codecContext.receivePacket(this.packet); + if (receiveRet === NodeAv.AVERROR_EAGAIN || receiveRet === NodeAv.AVERROR_EOF) { + break; + } + + this.receivePacket(receiveRet); + } + + this.codecContext.freeContext(); + this.codecContext = null; + // The codec is done now and can't be reused. Any subsequence encode call will first need to recreate a + // codec context. + } + + this.packetEmitted = false; + this.colorSpaceSet = false; + } + + close(): MaybePromise { + this.codecContext?.freeContext(); + this.frame.free(); + this.packet.free(); + this.scaler?.freeContext(); + this.dstFrame?.free(); + } +} diff --git a/packages/server/src/video-sample.ts b/packages/server/src/video-sample.ts new file mode 100644 index 0000000..d142708 --- /dev/null +++ b/packages/server/src/video-sample.ts @@ -0,0 +1,520 @@ +import assert from 'assert'; +import { Rectangle, VideoSamplePixelFormat } from 'mediabunny'; +import { VideoSampleColorSpace } from 'mediabunny'; +import { VideoSampleResource } from 'mediabunny'; +import * as NodeAv from 'node-av'; +import { toUint8Array } from '../../../src/misc'; +import { getPlaneConfigs } from '../../../src/sample'; +import { + toPixelFormat, + unmapColorPrimaries, + unmapTransferCharacteristics, + unmapMatrixCoefficients, + fromPixelFormat, + mapColorPrimaries, + mapTransferCharacteristics, + mapMatrixCoefficients, +} from './misc'; + +export class NodeAvFrameVideoSampleResource extends VideoSampleResource { + frame: NodeAv.Frame; + + constructor(frame: NodeAv.Frame) { + super(); + + const clone = frame.clone(); + if (!clone) { + throw new Error('Allocation failure during frame clone.'); + } + + this.frame = clone; + } + + getFormat(): VideoSamplePixelFormat | null { + return toPixelFormat(this.frame.format as NodeAv.AVPixelFormat); + } + + getCodedWidth(): number { + return this.frame.width; + } + + getCodedHeight(): number { + return this.frame.height; + } + + getSquarePixelWidth(): number { + if (this.frame.sampleAspectRatio.num > this.frame.sampleAspectRatio.den) { + return Math.round(this.frame.width * this.frame.sampleAspectRatio.num / this.frame.sampleAspectRatio.den); + } else { + return this.frame.width; + } + } + + getSquarePixelHeight(): number { + if (this.frame.sampleAspectRatio.num > this.frame.sampleAspectRatio.den) { + return this.frame.height; + } else { + return Math.round(this.frame.height * this.frame.sampleAspectRatio.den / this.frame.sampleAspectRatio.num); + } + } + + getColorSpace(): VideoSampleColorSpace { + return new VideoSampleColorSpace({ + primaries: unmapColorPrimaries(this.frame.colorPrimaries) as VideoColorPrimaries | null, + transfer: unmapTransferCharacteristics(this.frame.colorTrc) as VideoTransferCharacteristics | null, + matrix: unmapMatrixCoefficients(this.frame.colorSpace) as VideoMatrixCoefficients | null, + fullRange: this.frame.colorRange === NodeAv.AVCOL_RANGE_JPEG, + }); + } + + close(): void { + this.frame.free(); + } + + allocationSize(options: VideoFrameCopyToOptions): number { + // 3. Let combinedLayout be the result of running the Parse VideoFrameCopyToOptions algorithm with options. + // 4. If combinedLayout is an exception, throw combinedLayout. + const combinedLayout = ParseVideoFrameCopyToOptions(this, options); + + // 5. Return combinedLayout's allocationSize. + return combinedLayout.allocationSize; + } + + async copyTo( + destination: AllowSharedBufferSource, + options: VideoFrameCopyToOptions, + ): Promise { + const format = this.getFormat(); + assert(format !== null); + + // 3. Let combinedLayout be the result of running the Parse VideoFrameCopyToOptions algorithm with options. + const combinedLayout = ParseVideoFrameCopyToOptions(this, options); + + // 4. If destination.byteLength is less than combinedLayout’s allocationSize, return a promise rejected with + // // eslint-disable-next-line @stylistic/max-len + const destBytes = toUint8Array(destination); + if (destBytes.byteLength < combinedLayout.allocationSize) { + throw new TypeError( + `Destination buffer too small. Required: ${combinedLayout.allocationSize},` + + ` Available: ${destBytes.byteLength}`, + ); + } + + // 5. If options.format is equal to one of RGBA, RGBX, BGRA, BGRX then: + if (options.format && ['RGBA', 'RGBX', 'BGRA', 'BGRX'].includes(options.format) && options.format !== format) { + // Let newOptions be the result of running the Clone Configuration algorithm with options. + // Assign undefined to newOptions.format. + const newOptions = { ...options }; + delete newOptions.format; + + // Let rgbFrame be the result of running the Convert to RGB frame algorithm with this, options.format, + // and options.colorSpace. + const rgbFrame = await ConvertToRGBFrame(this, options.format, options.colorSpace); + + // Return the result of calling copyTo() on rgbFrame with destination and newOptions. + try { + const result = await rgbFrame.copyTo(destination, newOptions); + rgbFrame.close(); + return result; + } catch (e) { + rgbFrame.close(); + throw e; + } + } + + // 6. Let p be a new Promise. (Implicit) + // 7. Let copyStepsQueue be the result of starting a new parallel queue. (Implicit) + // 8. Let planeLayouts be a new list. + const planeLayouts: PlaneLayout[] = []; + + // Enqueue the following steps to copyStepsQueue: (fuck the queuing part) + + // Let resource be the media resource referenced by [[resource reference]]. + // (this.data) + + // Let numPlanes be the number of planes as defined by [[format]]. + const planes = getPlaneConfigs(format); + const numPlanes = planes.length; + + // Let planeIndex be 0. + // While planeIndex is less than combinedLayout’s numPlanes: + for (let planeIndex = 0; planeIndex < numPlanes; planeIndex++) { + const computedLayout = combinedLayout.computedLayouts[planeIndex]!; + + // Let sourceStride be the stride of the plane in resource as identified by planeIndex. + let sourceStride = 0; + let sourceStartOffset = 0; + + sourceStride = this.frame.linesize[planeIndex]!; + const planeBuffer = this.frame.data![planeIndex]!; + if (!planeBuffer) { + throw new Error(`Missing data for plane ${planeIndex}`); + } + const sourceData = new Uint8Array(planeBuffer.buffer, planeBuffer.byteOffset, planeBuffer.byteLength); + sourceStartOffset = 0; + + // Let sourceOffset be the product of multiplying computedLayout’s sourceTop by sourceStride + let sourceOffset = computedLayout.sourceTop * sourceStride; + + // Add computedLayout’s sourceLeftBytes to sourceOffset. + sourceOffset += computedLayout.sourceLeftBytes; + + // Adjust for the base offset of the plane in the source buffer + sourceOffset += sourceStartOffset; + + // Let destinationOffset be computedLayout’s destinationOffset. + let destinationOffset = computedLayout.destinationOffset; + + // Let rowBytes be computedLayout’s sourceWidthBytes. + const rowBytes = computedLayout.sourceWidthBytes; + + // Let layout be a new PlaneLayout, with offset set to destinationOffset and stride set to rowBytes. + // This is a spec error actually (https://github.com/w3c/webcodecs/issues/918) + const layout: PlaneLayout = { + offset: destinationOffset, + stride: computedLayout.destinationStride, + }; + + // Let row be 0. + // While row is less than computedLayout’s sourceHeight: + for (let row = 0; row < computedLayout.sourceHeight; row++) { + // Copy rowBytes bytes from resource starting at sourceOffset to destination starting + // at destinationOffset. + if (sourceOffset + rowBytes > sourceData.byteLength) { + throw new Error(`Source buffer OOB read`); + } + if (destinationOffset + rowBytes > destBytes.byteLength) { + throw new Error(`Destination buffer OOB write`); + } + + const srcSub = sourceData.subarray(sourceOffset, sourceOffset + rowBytes); + destBytes.set(srcSub, destinationOffset); + + // Increment sourceOffset by sourceStride. + sourceOffset += sourceStride; + + // Increment destinationOffset by computedLayout’s destinationStride. + destinationOffset += computedLayout.destinationStride; + } + + // Append layout to planeLayouts. + planeLayouts.push(layout); + } + + // Queue a task to resolve p with planeLayouts. + return planeLayouts; + } +} + +type CombinedBufferLayout = { + allocationSize: number; + computedLayouts: ComputedPlaneLayout[]; +}; + +type ComputedPlaneLayout = { + destinationOffset: number; + destinationStride: number; + sourceTop: number; + sourceHeight: number; + sourceLeftBytes: number; + sourceWidthBytes: number; +}; + +// Taken from the WebCodecs spec +const ParseVideoFrameCopyToOptions = ( + frame: VideoSampleResource, + options: VideoFrameCopyToOptions, +): CombinedBufferLayout => { + // 1. Let defaultRect be the result of performing the getter steps for visibleRect. + const defaultRect: Rectangle = { + left: 0, + top: 0, + width: frame.getCodedWidth(), + height: frame.getCodedHeight(), + }; + + // 2. Let overrideRect be undefined. + // 3. If options.rect exists, assign the value of options.rect to overrideRect. + const overrideRect = options.rect; + + // 4. Let parsedRect be the result of running the Parse Visible Rect algorithm... + const parsedRect = ParseVisibleRect( + defaultRect, + overrideRect, + frame.getCodedWidth(), + frame.getCodedHeight(), + frame.getFormat(), + ); + + // 5. If parsedRect is an exception, return parsedRect. (Handled by throw) + + // 6. Let optLayout be undefined. + // 7. If options.layout exists, assign its value to optLayout. + const optLayout = options.layout; + + // 8. Let format be undefined. + let format: VideoSamplePixelFormat | undefined; + + // 9. If options.format does not exist, assign [[format]] to format. + if (!options.format || options.format === frame.getFormat()) { + format = frame.getFormat()!; + } else if (['RGBA', 'RGBX', 'BGRA', 'BGRX'].includes(options.format)) { + // 10. Otherwise, if options.format is equal to one of RGBA, RGBX, BGRA, BGRX, then assign options.format + // to format... + format = options.format; + } else { + throw new Error('NotSupportedError: Invalid destination format'); + } + + // 11. Let combinedLayout be the result of running the Compute Layout and Allocation Size algorithm... + return ComputeLayoutAndAllocationSize(parsedRect, format, optLayout); +}; + +// Taken from the WebCodecs spec +const ParseVisibleRect = ( + defaultRect: DOMRectInit, + overrideRect: DOMRectInit | undefined, + codedWidth: number, + codedHeight: number, + format: VideoSamplePixelFormat | null, +): DOMRectInit => { + // 1. Let sourceRect be defaultRect + const sourceRect = { ...defaultRect }; + + // 2. If overrideRect is not undefined: + if (overrideRect !== undefined) { + // If either of overrideRect.width or height is 0, return a TypeError. + if (overrideRect.width === 0 || overrideRect.height === 0) { + throw new TypeError('visibleRect dimensions cannot be zero'); + } + // If the sum of overrideRect.x and overrideRect.width is greater than codedWidth, return a TypeError. + if ((overrideRect.x || 0) + (overrideRect.width || 0) > codedWidth) { + throw new TypeError('visibleRect exceeds codedWidth'); + } + // If the sum of overrideRect.y and overrideRect.height is greater than codedHeight, return a TypeError. + if ((overrideRect.y || 0) + (overrideRect.height || 0) > codedHeight) { + throw new TypeError('visibleRect exceeds codedHeight'); + } + // Assign overrideRect to sourceRect. + sourceRect.x = overrideRect.x || 0; + sourceRect.y = overrideRect.y || 0; + sourceRect.width = overrideRect.width || 0; + sourceRect.height = overrideRect.height || 0; + } + + // 3. Let validAlignment be the result of running the Verify Rect Offset Alignment algorithm. + const validAlignment = VerifyRectOffsetAlignment(format, sourceRect); + + // 4. If validAlignment is false, throw a TypeError. + if (!validAlignment) { + throw new TypeError('visibleRect alignment is invalid for the format'); + } + + // 5. Return sourceRect. + return sourceRect; +}; + +// Taken from the WebCodecs spec +const VerifyRectOffsetAlignment = (format: VideoSamplePixelFormat | null, rect: DOMRectInit): boolean => { + // 1. If format is null, return true. + if (format === null) return true; + + const planes = getPlaneConfigs(format); + + // 2. Let planeIndex be 0. + // 3. Let numPlanes be the number of planes as defined by format. + // 4. While planeIndex is less than numPlanes: + for (let planeIndex = 0; planeIndex < planes.length; planeIndex++) { + const plane = planes[planeIndex]!; + const sampleWidth = plane.widthDivisor; + const sampleHeight = plane.heightDivisor; + + // If rect.x is not a multiple of sampleWidth, return false. + if ((rect.x || 0) % sampleWidth !== 0) return false; + // If rect.y is not a multiple of sampleHeight, return false. + if ((rect.y || 0) % sampleHeight !== 0) return false; + } + + return true; +}; + +// Taken from the WebCodecs spec +const ComputeLayoutAndAllocationSize = ( + parsedRect: DOMRectInit, + format: VideoSamplePixelFormat, + layout?: PlaneLayout[], +): CombinedBufferLayout => { + const planes = getPlaneConfigs(format); + + // 1. Let numPlanes be the number of planes as defined by format. + const numPlanes = planes.length; + + // 2. If layout is not undefined and its length does not equal numPlanes, throw a TypeError. + if (layout !== undefined && layout.length !== numPlanes) { + throw new TypeError(`Layout must have ${numPlanes} planes`); + } + + // 3. Let minAllocationSize be 0. + let minAllocationSize = 0; + + // 4. Let computedLayouts be a new list. + const computedLayouts: ComputedPlaneLayout[] = []; + + // 5. Let endOffsets be a new list. + const endOffsets: number[] = []; + + // 6. Let planeIndex be 0. + // 7. While planeIndex < numPlanes: + for (let planeIndex = 0; planeIndex < numPlanes; planeIndex++) { + const plane = planes[planeIndex]!; + const sampleBytes = plane.sampleBytes; + const sampleWidth = plane.widthDivisor; + const sampleHeight = plane.heightDivisor; + + // Let computedLayout be a new computed plane layout. + const computedLayout: ComputedPlaneLayout = { + destinationOffset: 0, + destinationStride: 0, + sourceTop: 0, + sourceHeight: 0, + sourceLeftBytes: 0, + sourceWidthBytes: 0, + }; + + // Set computedLayout’s sourceTop... + computedLayout.sourceTop = Math.ceil(Math.trunc(parsedRect.y || 0) / sampleHeight); + // Set computedLayout’s sourceHeight... + computedLayout.sourceHeight = Math.ceil(Math.trunc(parsedRect.height || 0) / sampleHeight); + // Set computedLayout’s sourceLeftBytes... + computedLayout.sourceLeftBytes = Math.floor(Math.trunc(parsedRect.x || 0) / sampleWidth) * sampleBytes; + // Set computedLayout’s sourceWidthBytes... + computedLayout.sourceWidthBytes = Math.floor(Math.trunc(parsedRect.width || 0) / sampleWidth) * sampleBytes; + + // If layout is not undefined: + if (layout !== undefined) { + const planeLayout = layout[planeIndex]!; + // If planeLayout.stride is less than computedLayout’s sourceWidthBytes, return a TypeError. + if (planeLayout.stride < computedLayout.sourceWidthBytes) { + throw new TypeError(`Stride for plane ${planeIndex} is too small`); + } + // Assign planeLayout.offset to computedLayout’s destinationOffset. + computedLayout.destinationOffset = planeLayout.offset; + // Assign planeLayout.stride to computedLayout’s destinationStride. + computedLayout.destinationStride = planeLayout.stride; + } else { + // Otherwise: + // Assign minAllocationSize to computedLayout’s destinationOffset. + computedLayout.destinationOffset = minAllocationSize; + // Assign computedLayout’s sourceWidthBytes to computedLayout’s destinationStride. + computedLayout.destinationStride = computedLayout.sourceWidthBytes; + } + + // Let planeSize be the product of multiplying computedLayout’s destinationStride and sourceHeight. + const planeSize = computedLayout.destinationStride * computedLayout.sourceHeight; + + // Let planeEnd be the sum of planeSize and computedLayout’s destinationOffset. + const planeEnd = planeSize + computedLayout.destinationOffset; + + // If planeSize or planeEnd is greater than maximum range of unsigned long, return a TypeError. + if (planeEnd > 4294967295) throw new TypeError('Allocation size exceeds limit'); + + // Append planeEnd to endOffsets. + endOffsets.push(planeEnd); + + // Assign the maximum of minAllocationSize and planeEnd to minAllocationSize. + minAllocationSize = Math.max(minAllocationSize, planeEnd); + + // Check for overlap + for (let earlierPlaneIndex = 0; earlierPlaneIndex < planeIndex; earlierPlaneIndex++) { + const earlierLayout = computedLayouts[earlierPlaneIndex]!; + // If plane A ends before plane B starts, they do not overlap. + if ( + endOffsets[planeIndex]! <= earlierLayout.destinationOffset + || endOffsets[earlierPlaneIndex]! <= computedLayout.destinationOffset + ) { + continue; + } + throw new TypeError('Planes overlap'); + } + + computedLayouts.push(computedLayout); + } + + // 12. Return combinedLayout. + return { + allocationSize: minAllocationSize, + computedLayouts: computedLayouts, + }; +}; + +// Taken from the WebCodecs spec +const ConvertToRGBFrame = async ( + frame: NodeAvFrameVideoSampleResource, + format: VideoPixelFormat, + colorSpace?: PredefinedColorSpace, +): Promise => { + // 1. Let convertedFrame be a new VideoFrame... + // (We construct it at the end, but we prepare the resource here) + + const width = frame.getCodedWidth(); + const height = frame.getCodedHeight(); + + const scaler = new NodeAv.SoftwareScaleContext(); + const srcFmt = fromPixelFormat(frame.getFormat()!); + const dstFmt = fromPixelFormat(format); + + // Configure scaling: Source -> Destination (Visible Size) + scaler.getContext( + width, height, srcFmt, + width, height, dstFmt, + NodeAv.SWS_BILINEAR, + ); + + // Allocate destination frame + const dstFrame = new NodeAv.Frame(); + dstFrame.width = width; + dstFrame.height = height; + dstFrame.format = dstFmt; + dstFrame.alloc(); + dstFrame.allocBuffer(); + + // Apply destination color space settings to dstFrame + // If colorSpace is not provided, srgb is used + const targetColorSpace = colorSpace || 'srgb'; + if (targetColorSpace === 'srgb') { + dstFrame.colorPrimaries = NodeAv.AVCOL_PRI_BT709; + dstFrame.colorTrc = NodeAv.AVCOL_TRC_IEC61966_2_1; + dstFrame.colorSpace = NodeAv.AVCOL_SPC_RGB; + dstFrame.colorRange = NodeAv.AVCOL_RANGE_JPEG; + } else if (targetColorSpace === 'display-p3') { + dstFrame.colorPrimaries = NodeAv.AVCOL_PRI_SMPTE432; + dstFrame.colorTrc = NodeAv.AVCOL_TRC_IEC61966_2_1; + dstFrame.colorSpace = NodeAv.AVCOL_SPC_RGB; + dstFrame.colorRange = NodeAv.AVCOL_RANGE_JPEG; + } + + const srcFrame = frame.frame; + + // Apply source color space settings to srcFrame (if known) + // This ensures the scaler knows the input color space for correct conversion + const frameColorSpace = frame.getColorSpace(); + if (colorSpace) { + srcFrame.colorPrimaries = mapColorPrimaries(frameColorSpace.primaries ?? 'unknown') + ?? NodeAv.AVCOL_PRI_UNSPECIFIED; + srcFrame.colorTrc = mapTransferCharacteristics(frameColorSpace.transfer ?? 'unknown') + ?? NodeAv.AVCOL_TRC_UNSPECIFIED; + srcFrame.colorSpace = mapMatrixCoefficients(frameColorSpace.matrix ?? 'unknown') + ?? NodeAv.AVCOL_SPC_UNSPECIFIED; + srcFrame.colorRange = frameColorSpace.fullRange + ? NodeAv.AVCOL_RANGE_JPEG + : NodeAv.AVCOL_RANGE_MPEG; + } + + try { + await scaler.scaleFrame(dstFrame, srcFrame); + } finally { + scaler.freeContext(); + } + + return new NodeAvFrameVideoSampleResource(dstFrame); +}; diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json new file mode 100644 index 0000000..27a7ef1 --- /dev/null +++ b/packages/server/tsconfig.json @@ -0,0 +1,24 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist/modules", + "declaration": true, + "declarationMap": true, + "stripInternal": true, + "noEmit": false, + "moduleResolution": "nodenext", + "module": "nodenext", + "allowJs": true, + "paths": { + "mediabunny": ["../../src/index.ts"], + }, + }, + "include": [ + "./src/**/*", + "./build/**/*", + ], + "references": [ + { "path": "../../src" } + ] +} diff --git a/packages/server/tsdoc.json b/packages/server/tsdoc.json new file mode 100644 index 0000000..776fc76 --- /dev/null +++ b/packages/server/tsdoc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", + "extends": ["../../tsdoc.json"] +} diff --git a/scripts/bundle.ts b/scripts/bundle.ts index 6a22de0..0d965eb 100644 --- a/scripts/bundle.ts +++ b/scripts/bundle.ts @@ -223,12 +223,30 @@ const flacEncoderVariants = await createVariants( }, ); +const serverVariants = await createVariants( + 'packages/server/src/index.ts', + 'MediabunnyServer', + 'packages/server/dist/bundles/mediabunny-server', + 'cjs', + { + platform: 'node', + packages: 'external', + external: ['mediabunny'], + }, + { + platform: 'node', + packages: 'external', + external: ['mediabunny'], + }, +); + const contexts = [ ...mediabunnyVariants, ...mp3EncoderVariants, ...ac3Variants, ...aacEncoderVariants, ...flacEncoderVariants, + ...serverVariants, ]; if (process.argv[2] === '--watch') { diff --git a/scripts/check.sh b/scripts/check.sh index d47231e..bb28006 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -16,6 +16,9 @@ tsc -p packages/aac-encoder rm -rf packages/flac-encoder/dist/modules tsc -p packages/flac-encoder +rm -rf packages/server/dist/modules +tsc -p packages/server + tsc -p tsconfig.vitest.json --noEmit tsc -p scripts --noEmit diff --git a/src/isobmff/isobmff-muxer.ts b/src/isobmff/isobmff-muxer.ts index 5e50127..d456d04 100644 --- a/src/isobmff/isobmff-muxer.ts +++ b/src/isobmff/isobmff-muxer.ts @@ -400,7 +400,7 @@ export class IsobmffMuxer extends Muxer { const timescale = computeRationalApproximation( 1 / (track.metadata.frameRate ?? GLOBAL_TIMESCALE), 1e6, - ).denominator; + ).den; const displayAspectWidth = decoderConfig.displayAspectWidth; const displayAspectHeight = decoderConfig.displayAspectHeight; diff --git a/src/misc.ts b/src/misc.ts index 129c58c..167e69e 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -585,7 +585,7 @@ export const retriedFetch = async ( } }; -export const computeRationalApproximation = (x: number, maxDenominator: number) => { +export const computeRationalApproximation = (x: number, maxDenominator: number): Rational => { // Handle negative numbers const sign = x < 0 ? -1 : 1; x = Math.abs(x); @@ -605,8 +605,8 @@ export const computeRationalApproximation = (x: number, maxDenominator: number) if (nextDenominator > maxDenominator) { return { - numerator: sign * currNumerator, - denominator: currDenominator, + num: sign * currNumerator, + den: currDenominator, }; } @@ -624,8 +624,8 @@ export const computeRationalApproximation = (x: number, maxDenominator: number) } return { - numerator: sign * currNumerator, - denominator: currDenominator, + num: sign * currNumerator, + den: currDenominator, }; }; diff --git a/src/sample.ts b/src/sample.ts index 30b435c..15f16d2 100644 --- a/src/sample.ts +++ b/src/sample.ts @@ -26,6 +26,7 @@ import { simplifyRational, Rectangle, validateRectangle, + MaybePromise, } from './misc'; polyfillSymbolDispose(); @@ -94,7 +95,7 @@ export abstract class VideoSampleResource { * Returns the internal pixel format in which the frame is stored. * [See pixel formats](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/format) */ - abstract getFormat(): VideoPixelFormat | null; + abstract getFormat(): VideoSamplePixelFormat | null; /** Returns the width of the frame in pixels. */ abstract getCodedWidth(): number; @@ -119,7 +120,10 @@ export abstract class VideoSampleResource { abstract allocationSize(options: VideoFrameCopyToOptions): number; /** Copies this video sample's pixel data to an ArrayBuffer or ArrayBufferView. */ - abstract copyTo(destination: AllowSharedBufferSource, options: VideoFrameCopyToOptions): PlaneLayout[]; + abstract copyTo( + destination: AllowSharedBufferSource, + options: VideoFrameCopyToOptions + ): MaybePromise; } /** @@ -225,7 +229,7 @@ export class VideoSample implements Disposable { /** * The internal pixel format in which the frame is stored. Will be `null` if it's using an arbitrary internal - * format not representable by `VideoPixelFormat`. + * format not representable by `VideoSamplePixelFormat`. * [See pixel formats](https://www.w3.org/TR/webcodecs/#pixel-format) */ readonly format!: VideoSamplePixelFormat | null; @@ -393,7 +397,33 @@ export class VideoSample implements Disposable { this.rotation = init.rotation ?? 0; this.timestamp = init.timestamp!; this.duration = init.duration ?? 0; - this.colorSpace = new VideoSampleColorSpace(init.colorSpace); + + let colorSpaceInit = init.colorSpace ?? null; + if (colorSpaceInit === null) { + if ( + this.format === 'RGBA' || this.format === 'RGBX' + || this.format === 'BGRA' || this.format === 'BGRX' + ) { + // sRGB Color Space + colorSpaceInit = { + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'rgb', + fullRange: true, + }; + } else { + // REC709 Color Space + colorSpaceInit = { + primaries: 'bt709', + transfer: 'bt709', + matrix: 'bt709', + fullRange: false, + }; + } + } + + this.colorSpace = new VideoSampleColorSpace(colorSpaceInit); + this.visibleRect = { left: init.visibleRect?.left ?? 0, top: init.visibleRect?.top ?? 0, @@ -557,6 +587,15 @@ export class VideoSample implements Disposable { finalizationRegistry?.register(this, { type: 'video', data: this._data }, this); } + getUnderlyingData() { + if (this._closed) { + throw new Error('VideoSample is closed.'); + } + + assert(this._data !== null); + return this._data; + } + /** Clones this video sample. */ clone() { if (this._closed) { @@ -759,7 +798,7 @@ export class VideoSample implements Disposable { if (this._data instanceof VideoSampleResource) { const format = this._data.getFormat() ?? 'RGBA'; - const allocationSize = this._data.allocationSize({ format }); + const allocationSize = this._data.allocationSize({ format: format as VideoPixelFormat }); let data: ArrayBuffer; if (this._data._lastAllocationBuffer?.byteLength === allocationSize) { @@ -767,10 +806,19 @@ export class VideoSample implements Disposable { } else { data = this._data._lastAllocationBuffer = new ArrayBuffer(allocationSize); } - const layout = this._data.copyTo(data, { format }); + const layoutResult = this._data.copyTo(data, { format: format as VideoPixelFormat }); + + if (layoutResult instanceof Promise) { + throw new Error( + 'Cannot create a VideoFrame from a VideoSampleResource if copyTo returns a Promise. To work' + + ' around this, copy the data into a buffer and then create a VideoFrame from it.', + ); + } + + const layout = layoutResult; return new VideoFrame(data, { - format, + format: format as VideoPixelFormat, codedWidth: this._data.getCodedWidth(), codedHeight: this._data.getCodedHeight(), colorSpace: this._data.getColorSpace(), @@ -1349,7 +1397,7 @@ type PlaneConfig = { }; /** Helper to retrieve plane configurations based on WebCodecs § 9.8 Pixel Format definitions. */ -const getPlaneConfigs = (format: VideoSamplePixelFormat): PlaneConfig[] => { +export const getPlaneConfigs = (format: VideoSamplePixelFormat): PlaneConfig[] => { // Helper for standard YUV planes const yuv = ( yBytes: number, diff --git a/test/node/server-extension.test.ts b/test/node/server-extension.test.ts new file mode 100644 index 0000000..3fd10ce --- /dev/null +++ b/test/node/server-extension.test.ts @@ -0,0 +1,794 @@ +import { beforeAll, describe, expect, test } from 'vitest'; +import { registerMediabunnyServer } from '@mediabunny/server'; +import { Input } from '../../src/input.js'; +import { BufferSource, FilePathSource } from '../../src/source.js'; +import { ALL_FORMATS } from '../../src/input-format.js'; +import { assert, toUint8Array } from '../../src/misc.js'; +import { EncodedPacketSink, VideoSampleSink } from '../../src/media-sink.js'; +import { NodeAvVideoDecoder } from '../../packages/server/src/video-decoder.js'; +import { NodeAvVideoEncoder } from '../../packages/server/src/video-encoder.js'; +import { VideoSample } from '../../src/sample.js'; +import { buildVideoCodecString, VideoCodec } from '../../src/codec.js'; +import { EncodedPacket } from '../../src/packet.js'; +import { + AvcNalUnitType, + extractNalUnitTypeForAvc, + extractNalUnitTypeForHevc, + HevcNalUnitType, + iterateNalUnitsInAnnexB, + iterateNalUnitsInLengthPrefixed, +} from '../../src/codec-data.js'; +import { Output } from '../../src/output.js'; +import { Mp4OutputFormat } from '../../src/output-format.js'; +import { BufferTarget } from '../../src/target.js'; +import { Conversion } from '../../src/conversion.js'; +import { NodeAvFrameVideoSampleResource } from '../../packages/server/src/video-sample.js'; + +beforeAll(() => { + registerMediabunnyServer(); +}); + +describe('Video', async () => { + test('Decoder lifecycle', async () => { + using input = new Input({ + source: new FilePathSource('./test/public/video.mp4'), + formats: ALL_FORMATS, + }); + + const videoTrack = await input.getPrimaryVideoTrack(); + assert(videoTrack); + + const decoder = new NodeAvVideoDecoder(); + // @ts-expect-error Readonly + decoder.codec = await videoTrack.getCodec(); + // @ts-expect-error Readonly + decoder.config = await videoTrack.getDecoderConfig(); + + let sampleCount = 0; + const packetTimestamps: number[] = []; + + // @ts-expect-error Readonly + decoder.onSample = (sample: VideoSample) => { + expect(sample.timestamp).toBe(packetTimestamps[sampleCount]); + expect(sample.duration).toBe(1 / 25); + + sampleCount++; + sample.close(); + }; + + await decoder.init(); + + const sink = new EncodedPacketSink(videoTrack); + let packetCount = 0; + for await (const packet of sink.packets()) { + packetTimestamps.push(packet.timestamp); + packetTimestamps.sort((a, b) => a - b); // Because of B-frames + await decoder.decode(packet); + + if (++packetCount === 10) { + break; + } + } + + await decoder.flush(); + + expect(sampleCount).toBe(10); + + // And, go again + sampleCount = 0; + packetTimestamps.length = 0; + + packetCount = 0; + for await (const packet of sink.packets((await sink.getKeyPacket(2))!)) { + packetTimestamps.push(packet.timestamp); + packetTimestamps.sort((a, b) => a - b); // Because of B-frames + await decoder.decode(packet); + + if (++packetCount === 10) { + break; + } + } + + await decoder.flush(); + + expect(sampleCount).toBe(10); + + await decoder.close(); + }); + + test('Encoder lifecycle', async () => { + const encoder = new NodeAvVideoEncoder(); + // @ts-expect-error Readonly + encoder.codec = 'avc'; + // @ts-expect-error Readonly + encoder.config = { + codec: buildVideoCodecString('avc', 1280, 720, 1e6), + width: 1280, + height: 720, + bitrate: 1e6, + } satisfies VideoEncoderConfig; + + let packetCount = 0; + const sampleTimestamps: number[] = []; + + // @ts-expect-error Readonly + encoder.onPacket = (packet: EncodedPacket, meta: EncodedVideoChunkMetadata) => { + expect(packet.timestamp).toBe(sampleTimestamps[packetCount]); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(packetCount ? 'delta' : 'key'); + + if (packetCount === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('avc1.')).toBe(true); + expect(meta.decoderConfig!.codedWidth).toBe(1280); + expect(meta.decoderConfig!.codedHeight).toBe(720); + expect(meta.decoderConfig!.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'rgb', + fullRange: true, + }); + expect(meta.decoderConfig!.description).toBeDefined(); + } + + packetCount++; + }; + + await encoder.init(); + + const data = new Uint8Array(1280 * 720 * 4).fill(0xff); // White + for (let i = 0; i < 10; i++) { + using sample = new VideoSample(data, { + format: 'RGBX', + codedWidth: 1280, + codedHeight: 720, + timestamp: i / 30, + duration: 1 / 30, + }); + + sampleTimestamps.push(sample.timestamp); + + await encoder.encode(sample, {}); + } + + await encoder.flush(); + + expect(packetCount).toBe(10); + + packetCount = 0; + sampleTimestamps.length = 0; + + for (let i = 0; i < 10; i++) { + using sample = new VideoSample(data, { + format: 'RGBX', + codedWidth: 1280, + codedHeight: 720, + timestamp: i / 30, + duration: 1 / 30, + }); + + sampleTimestamps.push(sample.timestamp); + + await encoder.encode(sample, {}); + } + + await encoder.flush(); + + expect(packetCount).toBe(10); + + await encoder.close(); + }); + + test('AVC encode and decode, length-prefixed', async () => { + await encodeDecodeTest('avc', {}, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + expect([...packet.data.slice(0, 4)]).not.toEqual([0, 0, 0, 1]); + + for (const loc of iterateNalUnitsInLengthPrefixed(packet.data, 4)) { + const naluType = extractNalUnitTypeForAvc(packet.data[loc.offset]!); + // These have been stripped + expect( + naluType !== AvcNalUnitType.SPS + && naluType !== AvcNalUnitType.PPS + && naluType !== AvcNalUnitType.SPS_EXT, + ).toBe(true); + } + + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('avc1.')).toBe(true); + expect(meta.decoderConfig!.description).toBeDefined(); + expect(toUint8Array(meta.decoderConfig!.description!)[0]).toBe(1); // configurationVersion + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + expect(sample.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'rgb', + fullRange: true, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBeGreaterThan(250); // Quasi-white + }); + }); + + test('AVC encode and decode, Annex B', async () => { + await encodeDecodeTest('avc', { avc: { format: 'annexb' } }, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + expect([...packet.data.slice(0, 4)]).toEqual([0, 0, 0, 1]); + + if (i === 0) { + // In Annex B there's no description, so SPS/PPS are inlined into the keyframe + const naluTypes: number[] = []; + for (const loc of iterateNalUnitsInAnnexB(packet.data)) { + naluTypes.push(extractNalUnitTypeForAvc(packet.data[loc.offset]!)); + } + expect(naluTypes).toContain(AvcNalUnitType.SPS); + expect(naluTypes).toContain(AvcNalUnitType.PPS); + + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('avc1.')).toBe(true); + expect(meta.decoderConfig!.description).toBeUndefined(); + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + expect(sample.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'rgb', + fullRange: true, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBeGreaterThan(250); // Quasi-white + }); + }); + + test('HEVC encode and decode, length-prefixed', async () => { + await encodeDecodeTest('hevc', {}, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + expect([...packet.data.slice(0, 4)]).not.toEqual([0, 0, 0, 1]); + + for (const loc of iterateNalUnitsInLengthPrefixed(packet.data, 4)) { + const naluType = extractNalUnitTypeForHevc(packet.data[loc.offset]!); + // These have been stripped + expect( + naluType !== HevcNalUnitType.SPS_NUT + && naluType !== HevcNalUnitType.PPS_NUT + && naluType !== HevcNalUnitType.VPS_NUT, + ).toBe(true); + } + + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('hev1.')).toBe(true); + expect(meta.decoderConfig!.description).toBeDefined(); + expect(toUint8Array(meta.decoderConfig!.description!)[0]).toBe(1); // configurationVersion + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + + // Undefined, for some reason: + expect(sample.colorSpace).toEqual({ + primaries: null, + transfer: null, + matrix: null, + fullRange: false, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBe(255); // White + }); + }); + + test('HEVC encode and decode, Annex B', async () => { + // @ts-expect-error Fucky types + await encodeDecodeTest('hevc', { hevc: { format: 'annexb' } }, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + expect([...packet.data.slice(0, 4)]).toEqual([0, 0, 0, 1]); + + if (i === 0) { + // In Annex B there's no description, so VPS/SPS/PPS are inlined into the keyframe + const naluTypes: number[] = []; + for (const loc of iterateNalUnitsInAnnexB(packet.data)) { + naluTypes.push(extractNalUnitTypeForHevc(packet.data[loc.offset]!)); + } + expect(naluTypes).toContain(HevcNalUnitType.VPS_NUT); + expect(naluTypes).toContain(HevcNalUnitType.SPS_NUT); + expect(naluTypes).toContain(HevcNalUnitType.PPS_NUT); + + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('hev1.')).toBe(true); + expect(meta.decoderConfig!.description).toBeUndefined(); + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + + // Undefined, for some reason: + expect(sample.colorSpace).toEqual({ + primaries: null, + transfer: null, + matrix: null, + fullRange: false, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBe(255); // White + }); + }); + + test('VP8 encode and decode', async () => { + await encodeDecodeTest('vp8', {}, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec).toBe('vp8'); + expect(meta.decoderConfig!.description).toBeUndefined(); + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + expect(sample.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'bt470bg', + fullRange: false, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBeGreaterThan(250); // Quasi-white + }); + }); + + test('VP9 encode and decode', async () => { + await encodeDecodeTest('vp9', {}, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('vp09.')).toBe(true); + expect(meta.decoderConfig!.description).toBeUndefined(); + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + expect(sample.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: null, + fullRange: false, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBeGreaterThan(250); // Quasi-white + }); + }); + + test('AV1 encode and decode', async () => { + await encodeDecodeTest('av1', {}, async (packet, meta, i) => { + expect(packet.timestamp).toBe(i / 30); + expect(packet.duration).toBe(1 / 30); + expect(packet.type).toBe(i ? 'delta' : 'key'); + + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codec.startsWith('av01.')).toBe(true); + expect(meta.decoderConfig!.description).toBeUndefined(); + } + }, async (sample, i) => { + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.timestamp).toBe(i / 30); + expect(sample.duration).toBe(1 / 30); + expect(sample.colorSpace).toEqual({ + primaries: 'bt709', + transfer: 'iec61966-2-1', + matrix: 'rgb', + fullRange: false, + }); + + const buf = new Uint8Array(sample.allocationSize({ format: 'RGBX' })); + await sample.copyTo(buf, { format: 'RGBX' }); + + expect(buf[0]).toBeGreaterThan(250); // Quasi-white + }); + }); + + test('Non-square pixels encode and decode #1', async () => { + await encodeDecodeTest('avc', { displayWidth: 2 * 1280, displayHeight: 720 }, async (packet, meta, i) => { + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codedWidth).toBe(1280); + expect(meta.decoderConfig!.codedHeight).toBe(720); + expect(meta.decoderConfig!.displayAspectWidth).toBe(2 * 1280); + expect(meta.decoderConfig!.displayAspectHeight).toBe(720); + } + }, async (sample) => { + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.squarePixelWidth).toBe(2 * 1280); + expect(sample.squarePixelHeight).toBe(720); + }); + }); + + test('Non-square pixels encode and decode #2', async () => { + await encodeDecodeTest('avc', { displayWidth: 1280, displayHeight: 2 * 720 }, async (packet, meta, i) => { + if (i === 0) { + expect(meta.decoderConfig).toBeDefined(); + expect(meta.decoderConfig!.codedWidth).toBe(1280); + expect(meta.decoderConfig!.codedHeight).toBe(720); + expect(meta.decoderConfig!.displayAspectWidth).toBe(1280); + expect(meta.decoderConfig!.displayAspectHeight).toBe(2 * 720); + } + }, async (sample) => { + expect(sample.codedWidth).toBe(1280); + expect(sample.codedHeight).toBe(720); + expect(sample.squarePixelWidth).toBe(1280); + expect(sample.squarePixelHeight).toBe(2 * 720); + }); + }); + + const encodeDecodeTest = async ( + codec: VideoCodec, + extraConfig: Partial, + onPacket: (packet: EncodedPacket, meta: EncodedVideoChunkMetadata, i: number) => Promise, + onSample: (sample: VideoSample, i: number) => Promise, + ) => { + const encoder = new NodeAvVideoEncoder(); + // @ts-expect-error Readonly + encoder.codec = codec; + // @ts-expect-error Readonly + encoder.config = { + codec: buildVideoCodecString(codec, 1280, 720, 1e6), + width: 1280, + height: 720, + bitrate: 1e6, + ...extraConfig, + } satisfies VideoEncoderConfig; + + const sampleTimestamps: number[] = []; + const packets: EncodedPacket[] = []; + const metas: EncodedVideoChunkMetadata[] = []; + + // @ts-expect-error Readonly + encoder.onPacket = (packet: EncodedPacket, meta: EncodedVideoChunkMetadata) => { + packets.push(packet); + metas.push(meta); + }; + + await encoder.init(); + + const data = new Uint8Array(1280 * 720 * 4).fill(0xff); // White + for (let i = 0; i < 10; i++) { + using sample = new VideoSample(data, { + format: 'RGBX', + codedWidth: 1280, + codedHeight: 720, + timestamp: i / 30, + duration: 1 / 30, + }); + + sampleTimestamps.push(sample.timestamp); + + await encoder.encode(sample, {}); + } + + await encoder.flush(); + + expect(packets).toHaveLength(10); + + for (let i = 0; i < packets.length; i++) { + await onPacket(packets[i]!, metas[i]!, i); + } + + const decoder = new NodeAvVideoDecoder(); + // @ts-expect-error Readonly + decoder.codec = codec; + // @ts-expect-error Readonly + decoder.config = metas[0]!.decoderConfig!; + + const decodedSamples: VideoSample[] = []; + + // @ts-expect-error Readonly + decoder.onSample = (sample: VideoSample) => { + decodedSamples.push(sample); + }; + + await decoder.init(); + + for (const packet of packets) { + await decoder.decode(packet); + } + + await decoder.flush(); + + expect(decodedSamples).toHaveLength(10); + + for (using sample of decodedSamples) { + await onSample(sample, decodedSamples.indexOf(sample)); + } + }; + + test('AVC conversion roundtrip', { timeout: 10_000 }, async () => { + await conversionRoundtrip('avc'); + }); + + test('HEVC conversion roundtrip', { timeout: 10_000 }, async () => { + await conversionRoundtrip('hevc'); + }); + + test('VP8 conversion roundtrip', { timeout: 10_000 }, async () => { + await conversionRoundtrip('vp8'); + }); + + test('VP9 conversion roundtrip', { timeout: 10_000 }, async () => { + await conversionRoundtrip('vp9'); + }); + + test('AV1 conversion roundtrip', { timeout: 10_000 }, async () => { + await conversionRoundtrip('av1'); + }); + + const conversionRoundtrip = async (codec: VideoCodec) => { + using input = new Input({ + source: new FilePathSource('./test/public/video.mp4'), + formats: ALL_FORMATS, + }); + + const output = new Output({ + format: new Mp4OutputFormat(), + target: new BufferTarget(), + }); + + const inputTrack = await input.getPrimaryVideoTrack(); + assert(inputTrack); + + const packetTimestamps: number[] = []; + const packetSink = new EncodedPacketSink(inputTrack); + + for await (const packet of packetSink.packets()) { + packetTimestamps.push(packet.timestamp); + } + + packetTimestamps.sort((a, b) => a - b); + + const conversion = await Conversion.init({ + input, + output, + video: { + codec, + forceTranscode: true, + }, audio: { + discard: true, + }, + }); + await conversion.execute(); + + using newInput = new Input({ + source: new BufferSource(output.target.buffer!), + formats: ALL_FORMATS, + }); + + const newInputTrack = await newInput.getPrimaryVideoTrack(); + assert(newInputTrack); + + expect(await newInputTrack.getCodec()).toBe(codec); + + const sink = new VideoSampleSink(newInputTrack); + + let sampleCount = 0; + for await (using sample of sink.samples()) { + expect(sample.codedWidth).toBe(await inputTrack.getCodedWidth()); + expect(sample.codedHeight).toBe(await inputTrack.getCodedHeight()); + expect(sample.timestamp).toBe(packetTimestamps[sampleCount]); + + sampleCount++; + } + + expect(sampleCount).toBe(packetTimestamps.length); + }; + + test('Custom VideoSample resource', async () => { + using input = new Input({ + source: new FilePathSource('./test/public/video.mp4'), + formats: ALL_FORMATS, + }); + + const videoTrack = await input.getPrimaryVideoTrack(); + assert(videoTrack); + + const sink = new VideoSampleSink(videoTrack); + using sample = await sink.getSample(0); + assert(sample); + + expect(sample.getUnderlyingData()).toBeInstanceOf(NodeAvFrameVideoSampleResource); + expect(sample.format).toBe('I420'); + expect(sample.codedWidth).toBe(1920); + expect(sample.codedHeight).toBe(1080); + expect(sample.squarePixelWidth).toBe(1920); + expect(sample.squarePixelHeight).toBe(1080); + expect(sample.displayWidth).toBe(1920); + expect(sample.displayHeight).toBe(1080); + expect(sample.visibleRect).toEqual({ + left: 0, + top: 0, + width: 1920, + height: 1080, + }); + expect(sample.rotation).toBe(0); + expect(sample.timestamp).toBe(0); + expect(sample.duration).toBe(1 / 25); + expect(sample.colorSpace).toEqual({ + primaries: null, + transfer: null, + matrix: 'bt470bg', + fullRange: true, + }); + + // Default expected YUV size + expect(sample.allocationSize()).toBe(1920 * 1080 * 1.5); + // This is the same + expect(sample.allocationSize({ format: 'I420' })).toBe(1920 * 1080 * 1.5); + // Expected RGBA size + expect(sample.allocationSize({ format: 'RGBA' })).toBe(1920 * 1080 * 4); + // Can't convert to a non-RGBA format + expect(() => sample.allocationSize({ format: 'NV12' })).toThrow('Invalid destination format'); + // Default YUV layout + expect(sample.allocationSize({ layout: [ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1920 / 2 }, + { offset: 1920 * 1080 + (1920 / 2) * (1080 / 2), stride: 1920 / 2 }, + ] })).toBe(1920 * 1080 * 1.5); + // Custom YUV layout + expect(sample.allocationSize({ layout: [ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1000 }, + { offset: 1920 * 1080 + (1000) * (1080 / 2), stride: 1920 / 2 }, + ] })).toBe(1920 * 1080 + (1000) * (1080 / 2) + (1920 / 2) * (1080 / 2)); + // Default RGBA layout + expect(sample.allocationSize({ format: 'RGBA', layout: [ + { offset: 0, stride: 1920 * 4 }, + ] })).toBe(1920 * 1080 * 4); + // Custom RGBA layout + expect(sample.allocationSize({ format: 'RGBA', layout: [ + { offset: 0, stride: 1920 * 5 }, + ] })).toBe(1920 * 1080 * 5); + // Subrect with YUV + expect(sample.allocationSize({ rect: { + x: 0, + y: 0, + width: 400, + height: 200, + } })).toBe(400 * 200 * 1.5); + // Subrect with RGBA + expect(sample.allocationSize({ format: 'RGBA', rect: { + x: 0, + y: 0, + width: 400, + height: 200, + } })).toBe(400 * 200 * 4); + + const buffer = new ArrayBuffer(1920 * 1080 * 5); + + // Default YUV layout + expect(await sample.copyTo(buffer)).toEqual([ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1920 / 2 }, + { offset: 1920 * 1080 + (1920 / 2) * (1080 / 2), stride: 1920 / 2 }, + ]); + // This is the same + expect(await sample.copyTo(buffer, { format: 'I420' })).toEqual([ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1920 / 2 }, + { offset: 1920 * 1080 + (1920 / 2) * (1080 / 2), stride: 1920 / 2 }, + ]); + // Default RGBA layout + expect(await sample.copyTo(buffer, { format: 'RGBA' })).toEqual([ + { offset: 0, stride: 1920 * 4 }, + ]); + // Can't convert to a non-RGBA format + await expect(sample.copyTo(buffer, { format: 'NV12' })).rejects.toThrow('Invalid destination format'); + // Explicit default YUV layout + expect(await sample.copyTo(buffer, { layout: [ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1920 / 2 }, + { offset: 1920 * 1080 + (1920 / 2) * (1080 / 2), stride: 1920 / 2 }, + ] })).toEqual([ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1920 / 2 }, + { offset: 1920 * 1080 + (1920 / 2) * (1080 / 2), stride: 1920 / 2 }, + ]); + // Custom YUV layout + expect(await sample.copyTo(buffer, { layout: [ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1000 }, + { offset: 1920 * 1080 + (1000) * (1080 / 2), stride: 1920 / 2 }, + ] })).toEqual([ + { offset: 0, stride: 1920 }, + { offset: 1920 * 1080, stride: 1000 }, + { offset: 1920 * 1080 + (1000) * (1080 / 2), stride: 1920 / 2 }, + ]); + // Explicit default RGBA layout + expect(await sample.copyTo(buffer, { format: 'RGBA', layout: [ + { offset: 0, stride: 1920 * 4 }, + ] })).toEqual([ + { offset: 0, stride: 1920 * 4 }, + ]); + // Custom RGBA layout + expect(await sample.copyTo(buffer, { format: 'RGBA', layout: [ + { offset: 0, stride: 1920 * 5 }, + ] })).toEqual([ + { offset: 0, stride: 1920 * 5 }, + ]); + // Subrect with YUV + expect(await sample.copyTo(buffer, { rect: { + x: 0, + y: 0, + width: 400, + height: 200, + } })).toEqual([ + { offset: 0, stride: 400 }, + { offset: 400 * 200, stride: 400 / 2 }, + { offset: 400 * 200 + (400 / 2) * (200 / 2), stride: 400 / 2 }, + ]); + // Subrect with RGBA + expect(await sample.copyTo(buffer, { format: 'RGBA', rect: { + x: 0, + y: 0, + width: 400, + height: 200, + } })).toEqual([ + { offset: 0, stride: 400 * 4 }, + ]); + }); +}); diff --git a/tsconfig.vitest.json b/tsconfig.vitest.json index 129fafc..d665820 100644 --- a/tsconfig.vitest.json +++ b/tsconfig.vitest.json @@ -11,6 +11,7 @@ "@mediabunny/aac-encoder": ["./packages/aac-encoder/src/index.ts"], "@mediabunny/flac-encoder": ["./packages/flac-encoder/src/index.ts"], "@mediabunny/mp3-encoder": ["./packages/mp3-encoder/src/index.ts"], + "@mediabunny/server": ["./packages/server/src/index.ts"], }, }, "include": ["vitest.config.ts", "./test/**/*"], @@ -21,5 +22,6 @@ { "path": "./packages/aac-encoder" }, { "path": "./packages/flac-encoder" }, { "path": "./packages/mp3-encoder" }, + { "path": "./packages/server" }, ] } diff --git a/vitest.config.ts b/vitest.config.ts index 8578819..8f19b53 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -14,6 +14,8 @@ export default defineConfig({ path.resolve(__dirname, './packages/flac-encoder/dist/bundles/mediabunny-flac-encoder.mjs'), '@mediabunny/mp3-encoder': path.resolve(__dirname, './packages/mp3-encoder/dist/bundles/mediabunny-mp3-encoder.mjs'), + '@mediabunny/server': + path.resolve(__dirname, './packages/server/src/index.ts'), }, }, test: {