Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Video WebcamTexture and VideoCapture Simultaneously?

Discussion in 'Audio & Video' started by dclamage, Apr 28, 2021.

  1. dclamage

    dclamage

    Joined:
    Sep 29, 2020
    Posts:
    6
    I'm using 2020.3.5f1 (LTS)

    On Windows 10 (running through Editor right now, but ultimately I need to support Windows and UWP builds), I have WebcamTexture and VideoCapture working properly when used separately. However, what I'd like to do is use both at once, or at least have the same effect as using both at once.

    I'd like to record the webcam, but show a preview of what's being recorded on a RawImage so the user can see what's being recorded. When using both at once, I get an error because I guess the use of the webcam is exclusive, so they can't use them both at once.

    Is there some way around this? Ideally, I'd either get them working together at the same time, or use the VideoCapture API, but intercept what it's capturing and get that as a texture.
     
  2. dclamage

    dclamage

    Joined:
    Sep 29, 2020
    Posts:
    6
    The MediaCapture API has a "StartPreviewAsync" function. Can this be used in some way? Would it work for what I need to do?
     
  3. dimasfuady

    dimasfuady

    Joined:
    Dec 16, 2016
    Posts:
    1
    hello, did you found a way to do this? i've searched quite a lot of forums and didn't find enough answer for this
     
  4. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Yeah, the same resource can't be accessed by 2 processes. If you use WebcamTexture you need to code the encoding which is not necessarily fun. If you use VideoCapture, I see that you can get the IVideoDeviceController pointer, and reading this you can get a preview frame. I never tried myself but you could give it a try. But just to be clear VideoCapture only works on Windows 10 and UWP, and not Windows 7.
     
    Last edited: May 23, 2022
  5. shejianshangdezhongguo

    shejianshangdezhongguo

    Joined:
    Feb 18, 2019
    Posts:
    9
    "reading this"Cannot connect to the correct location.How to preview a video?How to obtain video for transmission?
     
  6. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502