Skip to content
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

Video with preprocessor VirtualBackground #2002

Open
9 tasks done
kiliancabrera opened this issue May 4, 2023 · 2 comments
Open
9 tasks done

Video with preprocessor VirtualBackground #2002

kiliancabrera opened this issue May 4, 2023 · 2 comments

Comments

@kiliancabrera
Copy link

kiliancabrera commented May 4, 2023

  • I have verified that the issue occurs with the latest twilio-video.js release and is not marked as a known issue in the CHANGELOG.md.
  • I reviewed the Common Issues and open GitHub issues and verified that this report represents a potentially new issue.
  • I verified that the Quickstart application works in my environment.
  • I am not sharing any Personally Identifiable Information (PII)
    or sensitive account information (API keys, credentials, etc.) when reporting this issue.

Code to reproduce the issue:

import { useEffect, useCallback } from 'react'
import {
  VirtualBackgroundProcessor,
  ImageFit,
  isSupported,
  Pipeline,
} from '@twilio/video-processors'

import background from './videocall-call-view_3.png'

const rawImagePaths = [background]

let imageElements = new Map()

const getImage = (index) => {
  return new Promise((resolve, reject) => {
    if (imageElements.has(index)) {
      return resolve(imageElements.get(index))
    }
    const img = new Image()
    img.onload = () => {
      imageElements.set(index, img)
      resolve(img)
    }
    img.onerror = reject
    img.src = rawImagePaths[index]
  })
}

const virtualBackgroundAssets = '/assets/virtualbackground'
let virtualBackgroundProcessor

export default function useBackgroundSettings(videoTrack, room, isAdmin) {
  const removeProcessor = useCallback(() => {
    if (videoTrack && videoTrack.processor) {
      videoTrack.removeProcessor(videoTrack.processor)
    }
  }, [videoTrack])

  const addProcessor = useCallback(
    (processor) => {
      if (!videoTrack || videoTrack.processor === processor) {
        return
      }
      removeProcessor()
      videoTrack.addProcessor(processor, {
        inputFrameBufferType: 'video',
        outputFrameBufferContextType: 'webgl2',
      })
    },
    [videoTrack, removeProcessor]
  )

  useEffect(() => {
    if (!isSupported || !isAdmin) {
      return
    }

    const handleProcessorChange = async () => {
      if (!virtualBackgroundProcessor) {
        virtualBackgroundProcessor = new VirtualBackgroundProcessor({
          assetsPath: virtualBackgroundAssets,
          backgroundImage: await getImage(0),
          fitType: ImageFit.Cover,
          pipeline: Pipeline.WebGL2,
        })
        await virtualBackgroundProcessor.loadModel()
      }
      if (!room?.localParticipant) {
        return
      }

      addProcessor(virtualBackgroundProcessor)
    }
    handleProcessorChange()
  }, [videoTrack, room, addProcessor, removeProcessor])
}

As of today I have detected that the video with the background processor suffers a considerable drop in performance and it is impossible to make a video call, this with the same version and everything exactly the same did not happen a few days ago, can someone confirm that it is also happening?

Software versions:

  • Browser(s): 113.0.5672.63
  • Operating System: MacOs and Windows 11
  • twilio-video.js: 2.27.0
  • twilio-video-preprocessor: 2.0.0
  • Third-party libraries (e.g., Angular, React, etc.):
@manjeshbhargav
Copy link
Collaborator

Hi @kiliancabrera ,

Sorry for the delayed response. Can you share your application so I can try and reproduce it locally?

@Lisztos
Copy link

Lisztos commented Jun 13, 2023

This one seems highly related to this one: #2007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants