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

Streaming a webcam as a movie texture? Almost there but....

Discussion in 'Editor & General Support' started by degeneration, Feb 3, 2009.

  1. degeneration

    degeneration

    Joined:
    Apr 3, 2008
    Posts:
    115
    After a bit of higgledypiggledy I have almost managed to stream in a webcam live into Unity. When I say 'almost', I can get the video to play when I have stopped the source of the stream. Unity kind of catches up after a while. The first time I realised I had gotten it to work the stream was 30 minutes behind.

    Code (csharp):
    1. function Start(){
    2.    www = new WWW("http://mydomain:8000/stream.ogg");
    3.    renderer.material.mainTexture = [url]www.movie;[/url]
    4.    while(!renderer.material.mainTexture.isReadyToPlay){
    5.       yield;
    6.    }
    7.    renderer.material.mainTexture.Play();
    8. }
    Is there anyway to fool Unity into playing what is there regardless of whether isReadyToPlay thinks it's ready to play or am I barking up the wrong tree?
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I think you're barking up the wrong tree. The isReadyToPlay property is only true when the Unity player thinks it has enough of the video buffered to start playback. Thus, if it's false the player doesn't believe (anthropomorphizing!) it has enough in the buffer and won't start playing the video, I'm not aware of any way to change that.
     
  3. degeneration

    degeneration

    Joined:
    Apr 3, 2008
    Posts:
    115
    Hmmmm.... Just trying .Play() doesn't start the texture playing. I'm so close to getting live streaming into Unity.
     
  4. absolutebreeze

    absolutebreeze

    Joined:
    Feb 7, 2009
    Posts:
    490
    I was just wondering how far you got with this - as its something I intend on doing once 2.5 is released on windows.

    BTW - are you using Pro or Indie?
     
  5. degeneration

    degeneration

    Joined:
    Apr 3, 2008
    Posts:
    115
    I got really close. It seems to buffer everything that has been streamed but will not play it until he stream ha finished broadcasting. The first time I realised I got it to work is when I stopped the stream carried on with something else and started to see myself (The camera was pointed at me) on a box inside unity. It took me a while to realise it was me 30 minutes ago.

    I put this on hold until 2.5 comes out as it maybe something that fixes itself in that release. I'll pick this up again then and let you know what I find.

    Edit, using Pro. Just realised your over the county boarder! :)
     
  6. absolutebreeze

    absolutebreeze

    Joined:
    Feb 7, 2009
    Posts:
    490
    Hey thanks for getting back to me :)

    That's a shame... but hopefully your right and 2.5 will have better webcam support.

    I'm in Wickford - so not too far from Herts at all :)
     
  7. degeneration

    degeneration

    Joined:
    Apr 3, 2008
    Posts:
    115
    It's not so much webcam support but how the ogg/theroa stream is stored and played pack. I would (at a guess) say that the isReadyToPlay function doesn't know it if is ready to play as it doesn't know how much it needs to have buffered to be able to play without interuptions.

    This is all a guess.

    If a video is 3 minutes long and is 20mb, then if it gets 1mb in 6 seconds then it knows it can play, but if the length is infinite or undetermined then it can work out the length, which would make me assume that it can't (at the moment) work out how much video its got, ie if its got 1mb is it 1 seconds worth, 10 seconds worth, 60 seconds worth and relys on knowing the size and length to make the determination.

    Again all just guessing.
     
  8. mindlace

    mindlace

    Joined:
    Mar 31, 2007
    Posts:
    24
    I was able to get better results by not waiting for isReadyToPlay... no point buffering anything when you're trying to get the live data anyway.
     
  9. degeneration

    degeneration

    Joined:
    Apr 3, 2008
    Posts:
    115
    I almost got something to work, but not quite. I came back to this on Friday (And submitted a wishlist) and did't get any joy.

    Mindlace, do you mind telling me the setup that you had to stream out video?
     
  10. mindlace

    mindlace

    Joined:
    Mar 31, 2007
    Posts:
    24
    Was just using VLC to stream it to a file. Opening a "real" stream never worked, so I'm going to dig about in the mono classes to see if I can do so there.
     
  11. Christian

    Christian

    Joined:
    Dec 2, 2008
    Posts:
    24
  12. J3-Gaming

    J3-Gaming

    Joined:
    Dec 23, 2010
    Posts:
    55
    Hello from the future, did you ever get this working? Would you like to collaborate?
     
  13. Hesta

    Hesta

    Joined:
    Dec 3, 2012
    Posts:
    4
    Have the same exact problem.. Any ideas on how to do it?
     
  14. FabriFabri

    FabriFabri

    Joined:
    Feb 14, 2013
    Posts:
    2
    UP for me... same here...