Skip to content

Commit

Permalink
try video decoding if webcodec fails
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonbot committed Apr 15, 2024
1 parent 4539fb8 commit 5ea5d73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/Processing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -308,4 +308,4 @@ function WarningMsg(props: { message: string, when: any, fix?: () => void }) {
{props.fix && <a class="ml-2 text-blue" href="#" onClick={e => { e.preventDefault(); props.fix!() }}>(Fix It)</a>}
</div>
</Show>
}
}
11 changes: 11 additions & 0 deletions src/processors/frameGrabber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

0 comments on commit 5ea5d73

Please sign in to comment.