Skip to content

Commit

Permalink
Fix video decoder stalls issue in webgpu_video_frame.html (#30380)
Browse files Browse the repository at this point in the history
* fix

* Update webgpu_video_frame.html

More clean up.

* Update webgpu_video_frame.html

* Update webgpu_video_frame.html

---------

Co-authored-by: Michael Herzog <[email protected]>
  • Loading branch information
ycw and Mugen87 authored Jan 22, 2025
1 parent 176ea06 commit 574c8f8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions examples/webgpu_video_frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
const decoder = new VideoDecoder( {
output( frame ) {

// To avoid video decoder stalls, we should close the VideoFrame which is no longer needed. https://w3c.github.io/webcodecs/#dom-videodecoder-decode
if ( videoTexture.image instanceof VideoFrame ) videoTexture.image.close();

videoTexture.setFrame( frame );

},
Expand All @@ -71,9 +74,24 @@
decoder.decode( chunk );

},
setStatus( s ) {
setStatus( kind, status ) {

console.info( 'MP4Demuxer:', kind );

if ( kind === 'fetch' && status === 'Done' ) {

decoder.flush().then( () => {

decoder.close();

// In case our VideoFrameTexture is no longer needed, we should close its backed VideoFrame, see issue #30379:
if ( videoTexture.image instanceof VideoFrame ) videoTexture.image.close();

videoTexture.image = null;

} );

console.info( 'MP4Demuxer:', s );
}

}
} );
Expand Down

0 comments on commit 574c8f8

Please sign in to comment.