From 5ea5d730a6fcf915b39d03be1cf4ea1594ccab6f Mon Sep 17 00:00:00 2001 From: lyonbot Date: Mon, 15 Apr 2024 11:39:20 +0800 Subject: [PATCH] try video decoding if webcodec fails --- src/components/Processing.tsx | 6 +++--- src/processors/frameGrabber.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Processing.tsx b/src/components/Processing.tsx index 858d200..c121414 100644 --- a/src/components/Processing.tsx +++ b/src/components/Processing.tsx @@ -2,7 +2,7 @@ import { Show, createMemo, createSignal } from "solid-js"; import { encode as GIFEncode } from 'modern-gif' import GIFWorkerJS from 'modern-gif/worker?url' import { outputSize, outputTimeRange, store, updateStore } from "../store"; -import { grabFramesWithMP4Box } from "../processors/frameGrabber"; +import { grabFrames as grabFrames1 } from "../processors/frameGrabber"; import { delay } from "yon-utils"; import { unwrap } from "solid-js/store"; import { getWatermarkRenderer } from "../processors/watermarkRenderer"; @@ -193,7 +193,7 @@ export function ProcessingBar() { setProgress('Grabbing Frames') setPercentage(0) - const frames = await grabFramesWithMP4Box({ + const frames = await grabFrames1({ file, resizeWidth: outputSize().width, resizeHeight: outputSize().height, @@ -308,4 +308,4 @@ function WarningMsg(props: { message: string, when: any, fix?: () => void }) { {props.fix && { e.preventDefault(); props.fix!() }}>(Fix It)} -} \ No newline at end of file +} diff --git a/src/processors/frameGrabber.ts b/src/processors/frameGrabber.ts index b7448f3..8c9c1a2 100644 --- a/src/processors/frameGrabber.ts +++ b/src/processors/frameGrabber.ts @@ -172,3 +172,14 @@ export async function grabFramesWithVideoTag({ file, resizeWidth, resizeHeight, URL.revokeObjectURL(fileURL) } } + +export function grabFrames(options: GrabFrameOptions) { + return grabFramesWithMP4Box(options).catch(error => { + console.error('MP4Box grabFrames error', error) + if (confirm('MP4Box+WebCodec cannot decode this file. Try with video tag?')) { + return grabFramesWithVideoTag(options) + } + + throw error + }) +}