Search Unity

Record video ...

Discussion in 'General Graphics' started by MXAdd, Sep 20, 2015.

  1. MXAdd

    MXAdd

    Joined:
    Apr 23, 2015
    Posts:
    74
    Hi

    I thought I'd ask ...
    It is possible to record short video sequence inside unity ?
    I have an app (WebPlayer currently, will be WebGL soon) that allows an user to create some animation sequence, based on mocap data and so on. Now the user could save this sequence in his/her account, and share it over facebook apis (this is just a short json file where clip numbers and parameters are stored, the user that wish to watch them needs the application too, to be able to load it and play).
    Now customers asks me it it is possible to record 'real' video clip and put it on for example youtube...

    Is there any way to do this ? (in context of this is WebPlayer/WebGL app)
    Animations are short and small (no more than 45 seconds, resolution 640x320 would be fine) but I see no way other than lib ffmpeg to encode them, (I'v experimented with this, but WebPlayer does not allow native plugins, and there is no pure c# implementation of mpg4 encoder AFAIK).
    Any other ideas ?

    PS1. - Putting ffmpeg encoder service on the server & send separate frames is no-go for me BTW :))
    PS2. - Animated GIF is no-go to :)
     
  2. Stankiem

    Stankiem

    Joined:
    Dec 4, 2013
    Posts:
    115
  3. MXAdd

    MXAdd

    Joined:
    Apr 23, 2015
    Posts:
    74
    The first one uses native plugin that is forbiden in WebPlayer/WebGL
    The second one is of iOS/Android only
    And the third one just captures FRAMES, not mpeg2/mpeg4 move
    so ... no, none of them would work ...
     
  4. Diet-Chugg

    Diet-Chugg

    Joined:
    Jul 4, 2012
    Posts:
    51
    Looking for the same thing. I have not found anything yet.
     
  5. MXAdd

    MXAdd

    Joined:
    Apr 23, 2015
    Posts:
    74
    Well it was quite a LOT of work to add this feature but I'v ended with FFmpeg converted to js (using emscripten) (basic idea from this site: https://github.com/bgrins/videoconverter.js) - but this was not enough, as unity do not support multithreading at the moment. I'v spawned worker thread in javascript (that reacts on simple comands like BeginRecording, SubmitVideoFrame, EndRecording, UploadToServer). Then when there is a time to record I'm just capturing RAW frames out of application (again, I don't use unity for this - it's to sloow for some reason, rather I use javascript hackery at the end of frame (found where unity ends the WebGL frame, and inject function call each time the build is finished (I have script to do this ;)) - based on how WebGL Inspector does this).
    The another trickery is to transfer RAW data to the worker FAST, I use transferable ArrayBuffer object(s) for this, but the drawback is that it works only in Chrome, Firefox and Edge, for reasons unknown to me there are some quirks with transferable objects on Safari.
    At the end performance is not that bad, the only thing I'v didn't manage to solve was how to record video with sound, but this is probably out of scope right now ...
     
    theANMATOR2b likes this.