mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-16 11:55:21 +00:00
web/libav: always clean up files on function exit
This commit is contained in:
parent
0ce743d13f
commit
0a37c84e93
|
@ -29,6 +29,8 @@ export default class LibAVWrapper {
|
||||||
const libav = await this.libav;
|
const libav = await this.libav;
|
||||||
|
|
||||||
await libav.mkreadaheadfile('input', blob);
|
await libav.mkreadaheadfile('input', blob);
|
||||||
|
|
||||||
|
try {
|
||||||
await libav.ffprobe([
|
await libav.ffprobe([
|
||||||
'-v', 'quiet',
|
'-v', 'quiet',
|
||||||
'-print_format', 'json',
|
'-print_format', 'json',
|
||||||
|
@ -38,13 +40,14 @@ export default class LibAVWrapper {
|
||||||
'-o', 'output.json'
|
'-o', 'output.json'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await libav.unlinkreadaheadfile('input');
|
|
||||||
|
|
||||||
const copy = await libav.readFile('output.json');
|
const copy = await libav.readFile('output.json');
|
||||||
const text = new TextDecoder().decode(copy);
|
const text = new TextDecoder().decode(copy);
|
||||||
await libav.unlink('output.json');
|
await libav.unlink('output.json');
|
||||||
|
|
||||||
return JSON.parse(text) as FfprobeData;
|
return JSON.parse(text) as FfprobeData;
|
||||||
|
} finally {
|
||||||
|
await libav.unlinkreadaheadfile('input');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getExtensionFromType(blob: Blob) {
|
static getExtensionFromType(blob: Blob) {
|
||||||
|
@ -82,6 +85,7 @@ export default class LibAVWrapper {
|
||||||
|
|
||||||
const outputName = `output.${output.extension}`;
|
const outputName = `output.${output.extension}`;
|
||||||
|
|
||||||
|
try {
|
||||||
await libav.mkreadaheadfile("input", blob);
|
await libav.mkreadaheadfile("input", blob);
|
||||||
|
|
||||||
// https://github.com/Yahweasel/libav.js/blob/7d359f69/docs/IO.md#block-writer-devices
|
// https://github.com/Yahweasel/libav.js/blob/7d359f69/docs/IO.md#block-writer-devices
|
||||||
|
@ -121,10 +125,6 @@ export default class LibAVWrapper {
|
||||||
outputName
|
outputName
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await libav.unlink(outputName);
|
|
||||||
await libav.unlink('progress.txt');
|
|
||||||
await libav.unlinkreadaheadfile("input");
|
|
||||||
|
|
||||||
// if we didn't need as much space as we allocated for some reason,
|
// if we didn't need as much space as we allocated for some reason,
|
||||||
// shrink the buffer so that we don't inflate the file with zeros
|
// shrink the buffer so that we don't inflate the file with zeros
|
||||||
if (writtenData.length > actualSize) {
|
if (writtenData.length > actualSize) {
|
||||||
|
@ -138,6 +138,14 @@ export default class LibAVWrapper {
|
||||||
|
|
||||||
if (renderBlob.size === 0) return;
|
if (renderBlob.size === 0) return;
|
||||||
return renderBlob;
|
return renderBlob;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await libav.unlink(outputName);
|
||||||
|
await libav.unlink('progress.txt');
|
||||||
|
await libav.unlinkreadaheadfile("input");
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#emitProgress(data: Uint8Array | Int8Array) {
|
#emitProgress(data: Uint8Array | Int8Array) {
|
||||||
|
|
Loading…
Reference in a new issue