final touch up
This commit is contained in:
parent
a6b38ac020
commit
8788a7cd48
|
@ -12,18 +12,16 @@ class FFmpegService {
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
this.ffmpeg = createFFmpeg({
|
this.ffmpeg = createFFmpeg({
|
||||||
log: true,
|
|
||||||
...(!process.env.NEXT_PUBLIC_SENTRY_ENV && {
|
...(!process.env.NEXT_PUBLIC_SENTRY_ENV && {
|
||||||
corePath: '/js/ffmpeg/ffmpeg-core.js',
|
corePath: '/js/ffmpeg/ffmpeg-core.js',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
console.log('Loading ffmpeg-core.js');
|
|
||||||
this.isLoading = this.ffmpeg.load();
|
this.isLoading = this.ffmpeg.load();
|
||||||
await this.isLoading;
|
await this.isLoading;
|
||||||
this.isLoading = null;
|
this.isLoading = null;
|
||||||
console.log('ffmpeg loaded');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Error('ffmpeg load failed');
|
logError(e, 'ffmpeg load failed');
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +37,6 @@ class FFmpegService {
|
||||||
);
|
);
|
||||||
|
|
||||||
const thumbnail = await response.promise;
|
const thumbnail = await response.promise;
|
||||||
console.log(URL.createObjectURL(thumbnail));
|
|
||||||
if (!thumbnail) {
|
if (!thumbnail) {
|
||||||
throw Error(CustomError.THUMBNAIL_GENERATION_FAILED);
|
throw Error(CustomError.THUMBNAIL_GENERATION_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +67,6 @@ async function generateThumbnailHelper(ffmpeg: FFmpeg, file: File) {
|
||||||
ffmpeg.FS('unlink', file.name);
|
ffmpeg.FS('unlink', file.name);
|
||||||
return thumb;
|
return thumb;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
|
||||||
logError(e, 'ffmpeg thumbnail generation failed');
|
logError(e, 'ffmpeg thumbnail generation failed');
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,12 @@ export async function generateThumbnail(
|
||||||
if (fileType === FILE_TYPE.IMAGE) {
|
if (fileType === FILE_TYPE.IMAGE) {
|
||||||
canvas = await generateImageThumbnail(file, isHEIC);
|
canvas = await generateImageThumbnail(file, isHEIC);
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
const thumb = await FFmpegService.generateThumbnail(file);
|
const thumb = await FFmpegService.generateThumbnail(file);
|
||||||
return { thumbnail: thumb, hasStaticThumbnail: false };
|
return { thumbnail: thumb, hasStaticThumbnail: false };
|
||||||
|
} catch (e) {
|
||||||
|
canvas = await generateVideoThumbnail(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const thumbnailBlob = await thumbnailCanvasToBlob(canvas);
|
const thumbnailBlob = await thumbnailCanvasToBlob(canvas);
|
||||||
thumbnail = await worker.getUint8ArrayView(thumbnailBlob);
|
thumbnail = await worker.getUint8ArrayView(thumbnailBlob);
|
||||||
|
@ -34,8 +38,7 @@ export async function generateThumbnail(
|
||||||
throw Error('EMPTY THUMBNAIL');
|
throw Error('EMPTY THUMBNAIL');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
logError(e, 'uploading static thumbnail');
|
||||||
logError(e);
|
|
||||||
thumbnail = Uint8Array.from(atob(BLACK_THUMBNAIL_BASE64), (c) =>
|
thumbnail = Uint8Array.from(atob(BLACK_THUMBNAIL_BASE64), (c) =>
|
||||||
c.charCodeAt(0)
|
c.charCodeAt(0)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue