Repository navigation
fix: retry filmstrip frame capture when the video frame is not yet decodable #16348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { delay } from 'es-toolkit' | ||
| import { onScopeDispose, ref, watch } from 'vue' | ||
| import type { Ref } from 'vue' | ||
|
|
||
|
|
@@ -9,6 +10,8 @@ export const FILMSTRIP_THUMBNAIL_MAX_WIDTH = 384 | |
|
|
||
| const METADATA_EVENT_TIMEOUT_MS = 15000 | ||
| const SEEK_EVENT_TIMEOUT_MS = 5000 | ||
| const FRAME_DECODE_TIMEOUT_MS = 5000 | ||
| const FRAME_DECODE_RETRY_INTERVAL_MS = 250 | ||
|
|
||
| export type FilmstripError = 'canvas-unavailable' | 'load-failed' | ||
|
|
||
|
|
@@ -152,6 +155,25 @@ function representativeFrameTime(duration: number): number { | |
| : 0 | ||
| } | ||
|
|
||
| async function waitForDecodableFrame( | ||
| video: HTMLVideoElement, | ||
| canvas: HTMLCanvasElement, | ||
| context: CanvasRenderingContext2D, | ||
| signal: AbortSignal | ||
| ): Promise<string> { | ||
| const deadlineMs = Date.now() + FRAME_DECODE_TIMEOUT_MS | ||
| while (Date.now() < deadlineMs) { | ||
| try { | ||
| await delay(FRAME_DECODE_RETRY_INTERVAL_MS, { signal }) | ||
| } catch { | ||
| throw new LoadAbortedError('Aborted waiting for a decodable frame') | ||
| } | ||
| const frame = await captureFrame(video, canvas, context) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): because The cost is small per your measurements, so this is not blocking. But if |
||
| if (frame) return frame | ||
| } | ||
| return '' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit-pick (non-blocking): the PR description says the failure left "the trim timeline permanently blank with no error or skeleton". Worth being precise that this fixes the transient case only — on exhaustion the outcome is still a blank thumbnail with expect(thumbnail.value).toBe('')
expect(error.value).toBeNull()That is a reasonable scope and I am not asking to widen it. The one thing that genuinely did improve for the permanent case is the skeleton: |
||
| } | ||
|
|
||
| async function captureRepresentativeFrame( | ||
| video: HTMLVideoElement, | ||
| canvas: HTMLCanvasElement, | ||
|
|
@@ -168,7 +190,8 @@ async function captureRepresentativeFrame( | |
| if (!(waitError instanceof EventTimeoutError)) throw waitError | ||
| } | ||
| } | ||
| return captureFrame(video, canvas, context) | ||
| const frame = await captureFrame(video, canvas, context) | ||
| return frame || waitForDecodableFrame(video, canvas, context, signal) | ||
| } | ||
|
|
||
| export function useVideoFilmstrip( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.