File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
packages/video-filters-web/src Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class FallbackProcessor implements MediaStreamTrackProcessor<VideoFrame> {
4949 let timestamp = 0 ;
5050 const frameRate = track . getSettings ( ) . frameRate || 30 ;
5151 let frameDuration = 1000 / frameRate ;
52+ let lastVideoTime = - 1 ;
5253
5354 this . workerTimer = new WorkerTimer ( { useWorker : true } ) ;
5455 this . readable = new ReadableStream ( {
@@ -76,6 +77,18 @@ class FallbackProcessor implements MediaStreamTrackProcessor<VideoFrame> {
7677 }
7778 timestamp = performance . now ( ) ;
7879
80+ const currentTime = this . video . currentTime ;
81+ const hasNewFrame = currentTime !== lastVideoTime ;
82+
83+ if ( ! hasNewFrame ) {
84+ await new Promise ( ( r : ( value ?: unknown ) => void ) =>
85+ this . workerTimer . setTimeout ( r , frameDuration ) ,
86+ ) ;
87+ return ;
88+ }
89+
90+ lastVideoTime = currentTime ;
91+
7992 if (
8093 canvas . width !== this . video . videoWidth ||
8194 canvas . height !== this . video . videoHeight
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ import { BaseVideoProcessor } from './BaseVideoProcessor';
1717export class VirtualBackground extends BaseVideoProcessor {
1818 private segmenter : ImageSegmenter | null = null ;
1919 private isSegmenterReady = false ;
20- private isFirstFrame = true ;
2120 private webGlRenderer ! : WebGLRenderer ;
2221
2322 private opts ! : SegmenterOptions ;
@@ -65,12 +64,6 @@ export class VirtualBackground extends BaseVideoProcessor {
6564 }
6665
6766 protected async transform ( frame : VideoFrame ) : Promise < VideoFrame > {
68- if ( this . isFirstFrame ) {
69- this . isFirstFrame = false ;
70-
71- return new VideoFrame ( frame , { timestamp : frame . timestamp } ) ;
72- }
73-
7467 if ( this . isSegmenterReady && this . segmenter ) {
7568 await new Promise < void > ( ( resolve ) => {
7669 this . segmenter ! . segmentForVideo ( frame , frame . timestamp , ( result ) => {
You can’t perform that action at this time.
0 commit comments