1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00

fix crashes

This commit is contained in:
Mikael Finstad 2024-05-15 15:07:54 +02:00
parent 8a01a928a1
commit 8e361077a8
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
2 changed files with 13 additions and 7 deletions

View File

@ -28,6 +28,15 @@ export class RefuseOverwriteError extends Error {
}
}
export function fixRemoteBuffer(buffer: Buffer) {
// if we don't do this when creating a Blob, we get:
// "Failed to construct 'Blob': The provided ArrayBufferView value must not be resizable."
// maybe when moving away from @electron/remote, it's not needed anymore?
const buffer2 = Buffer.allocUnsafe(buffer.length);
buffer.copy(buffer2);
return buffer2;
}
export function logStdoutStderr({ stdout, stderr }: { stdout: Buffer, stderr: Buffer }) {
if (stdout.length > 0) {
console.log('%cSTDOUT:', 'color: green; font-weight: bold');
@ -492,7 +501,7 @@ async function renderThumbnail(filePath: string, timestamp: number) {
const { stdout } = await runFfmpeg(args);
const blob = new Blob([stdout], { type: 'image/jpeg' });
const blob = new Blob([fixRemoteBuffer(stdout)], { type: 'image/jpeg' });
return URL.createObjectURL(blob);
}
@ -507,7 +516,7 @@ export async function extractSubtitleTrack(filePath: string, streamId: number) {
const { stdout } = await runFfmpeg(args);
const blob = new Blob([stdout], { type: 'text/vtt' });
const blob = new Blob([fixRemoteBuffer(stdout)], { type: 'text/vtt' });
return URL.createObjectURL(blob);
}

View File

@ -3,7 +3,7 @@ import sortBy from 'lodash/sortBy';
import { useThrottle } from '@uidotdev/usehooks';
import { waveformColorDark, waveformColorLight } from '../colors';
import { renderWaveformPng } from '../ffmpeg';
import { fixRemoteBuffer, renderWaveformPng } from '../ffmpeg';
import { RenderableWaveform } from '../types';
import { FFprobeStream } from '../../../../ffprobe';
@ -73,12 +73,9 @@ export default ({ darkMode, filePath, relevantTime, duration, waveformEnabled, a
return w;
}
// if we don't do this, we get Failed to construct 'Blob': The provided ArrayBufferView value must not be resizable.
const buffer2 = Buffer.allocUnsafe(buffer.length);
buffer.copy(buffer2);
return {
...w,
url: URL.createObjectURL(new Blob([buffer2], { type: 'image/png' })),
url: URL.createObjectURL(new Blob([fixRemoteBuffer(buffer)], { type: 'image/png' })),
};
}));
} catch (err) {