web/libav: add ffprobe wrapper
This commit is contained in:
parent
4636f7b0d4
commit
f93d84c457
3 changed files with 51 additions and 0 deletions
|
@ -131,6 +131,9 @@ importers:
|
|||
'@types/eslint__js':
|
||||
specifier: ^8.42.3
|
||||
version: 8.42.3
|
||||
'@types/fluent-ffmpeg':
|
||||
specifier: ^2.1.25
|
||||
version: 2.1.25
|
||||
'@types/node':
|
||||
specifier: ^20.14.10
|
||||
version: 20.14.14
|
||||
|
@ -695,6 +698,9 @@ packages:
|
|||
'@types/estree@1.0.5':
|
||||
resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==}
|
||||
|
||||
'@types/fluent-ffmpeg@2.1.25':
|
||||
resolution: {integrity: sha512-a9/Jtv/RVaCG4lUwWIcuClWE5eXJFoFS/oHOecOv/RS8n+lQdJzcJVmDlxA8Xbk4B82YpO88Dijcoljb6sYTcA==}
|
||||
|
||||
'@types/json-schema@7.0.15':
|
||||
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
||||
|
||||
|
@ -2634,6 +2640,10 @@ snapshots:
|
|||
|
||||
'@types/estree@1.0.5': {}
|
||||
|
||||
'@types/fluent-ffmpeg@2.1.25':
|
||||
dependencies:
|
||||
'@types/node': 20.14.14
|
||||
|
||||
'@types/json-schema@7.0.15': {}
|
||||
|
||||
'@types/node@10.17.60': {}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"@sveltejs/kit": "^2.0.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||
"@types/eslint__js": "^8.42.3",
|
||||
"@types/fluent-ffmpeg": "^2.1.25",
|
||||
"@types/node": "^20.14.10",
|
||||
"compare-versions": "^6.1.0",
|
||||
"eslint": "^8.57.0",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import mime from "mime";
|
||||
import LibAV, { type LibAV as LibAVInstance } from "@imput/libav.js-remux-cli";
|
||||
import type { FFmpegProgressCallback, FFmpegProgressEvent, FFmpegProgressStatus, FileInfo, RenderParams } from "./types/libav";
|
||||
import type { FfprobeData } from "fluent-ffmpeg";
|
||||
|
||||
export default class LibAVWrapper {
|
||||
libav: Promise<LibAVInstance> | null;
|
||||
|
@ -22,6 +23,45 @@ export default class LibAVWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
async probe(blob: Blob) {
|
||||
if (!this.libav) throw new Error("LibAV wasn't initialized");
|
||||
const libav = await this.libav;
|
||||
|
||||
const OUT_FILE = 'output.json';
|
||||
await libav.mkreadaheadfile('input', blob);
|
||||
await libav.mkwriterdev(OUT_FILE);
|
||||
|
||||
let writtenData = new Uint8Array(0);
|
||||
|
||||
libav.onwrite = (name, pos, data) => {
|
||||
if (name !== OUT_FILE) return;
|
||||
|
||||
const newLen = Math.max(pos + data.length, writtenData.length);
|
||||
if (newLen > writtenData.length) {
|
||||
const newData = new Uint8Array(newLen);
|
||||
newData.set(writtenData);
|
||||
writtenData = newData;
|
||||
}
|
||||
writtenData.set(data, pos);
|
||||
};
|
||||
|
||||
await libav.ffprobe([
|
||||
'-v', 'quiet',
|
||||
'-print_format', 'json',
|
||||
'-show_format',
|
||||
'-show_streams',
|
||||
'input',
|
||||
'-o', OUT_FILE
|
||||
]);
|
||||
|
||||
await libav.unlink(OUT_FILE);
|
||||
await libav.unlinkreadaheadfile('input');
|
||||
|
||||
const copy = new Uint8Array(writtenData);
|
||||
const text = new TextDecoder().decode(copy);
|
||||
return JSON.parse(text) as FfprobeData;
|
||||
}
|
||||
|
||||
async render({ blob, output, args }: RenderParams) {
|
||||
if (!this.libav) throw new Error("LibAV wasn't initialized");
|
||||
const libav = await this.libav;
|
||||
|
|
Loading…
Reference in a new issue