Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MoviePlayer for Unity (plays MJPEG)

Discussion in 'Works In Progress - Archive' started by ShuuGames, Feb 19, 2014.

?

What codec support would you like to see next?

  1. VP9 video + Opus audio (more advanced, royalty free, but less common)

    10.3%
  2. h264 video + aac audio (less advanced, licensing and patent encumbered, but very common)

    64.1%
  3. Both

    23.1%
  4. Some other, please comment

    2.6%
  1. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    You are right, it won't compile for Windows Store. This is my bad, should have tested it. I expected .NET core to be roughly the same on Windows Store target, but it's really rather different (no Thread, no File, no Dictionary classes, etc), but the most crucial stuff this plugin depends on is still there so I think in a few days I am able to make Windows Store port.
     
  2. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Very good! Thanks for the support! =)
     
  3. momay

    momay

    Joined:
    Jul 7, 2013
    Posts:
    9
    I am having trouble playing back a video with alpha.
    How can I check to make sure the video I made has correct alpha?
    Is there some way to show the channel is in the file correctly?
    maybe a flag in ffplay to see the channel? pressing the v key?
    once I can make sure I have a video with a correct alpha channel
    How do I make sure I have the right unity shader working? what shader do I use?

    thank you
    momay
     
  4. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Only mpng and raw codecs can store alpha channel. From ffmpeg package you can use ffprobe to see if there is alpha channel. VirtualDub and other video processing softwares should tell you the pixel format also.

    The simplest way to test and set up video with transparency in alpha channel is like this. Encode a pic that sure has some transparency in it.
    Code (csharp):
    1. ffmpeg.exe -i alphapic.png -vcodec png out.avi
    Then create a new material that uses, say, Unlit/Transparent shader and assign it to MoviePlayer component Material property.

    Other ways require more setup and custom shader, but may be better performance wise. For example, you can play back two video streams with two different MoviePlayer components and then have a material that combines them so that color is taken from one and transparency from another framebuffer. In many cases the transparency clip can have lower resolution to save disk space.
     
  5. metalquan

    metalquan

    Joined:
    May 4, 2013
    Posts:
    3
    Hello:
    I have purchased
    How to call android system outside of avi files?
    Anxious, thank you
     
  6. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Thanks for the purchase. But what do you mean exactly...? Maybe what you're looking after is MoviePlayer component Load method that takes file path as a parameter. You have to call that from your own script.
     
  7. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Have you some advice of how to encode the videos?

    Should I only use AVI Motion Jpeg? I am having difficulty in getting a good quality using this Codec, I got lot of blocks and image artifacts! What suggestions do you have to improve the quality?
     
  8. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    There's a section about encoding in reference pdf, but the key thing is to use lower -qscale value for better quality in ffmpeg for mjpeg codec. Qscale 1 will give you near lossless video, qscale between 3 or 5 should be rather reasonable high quality choice. Ffmpeg defaults to something like 15 (max qscale is 31). Container format, which has to be AVI for this plugin, has no effect on video stream quality in it.

    If your video has sharp edges and big constant color areas or linear gradients (like some cartoons), then you can try lossless mpng codec too (ffmpeg option -vcodec png). It might even compress better, is lossless, but decoding is slower than mjpeg.

    Just to be complete, for some special cases where huge file size and storage access speeds are no issue, lossless unencoded video streams in AVI can also be used.
     
  9. MasterEpik

    MasterEpik

    Joined:
    Sep 24, 2014
    Posts:
    4
    Hello ShuuGames,

    so here is my situation:

    I want to stream videos from my ftp-server with the www class, but everytime I click on the Object Unity always opens the internet explorer first and I can watch it in there. I dont want it like that. I just want to open the Video with the play pause controllers and a button or something to exit the video and go back to the game. So my question is can I do that with your plugin ?

    Thank you for your advice
    greets Ali
     
  10. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Well you can if you're out of options and desperate... but this scenario sounds like there are better options out there. I don't exactly get what script or thing you're using that opens IE when you click somewhere. Maybe you can tell a bit about it. If the case is that the game is operating inside a web browser then its likely that for "fullscreen" video playback you can use html5 instead. It requires a bit of scripting outside unity, but it's much easier to handle issues that may arise from unity web player security sandbox, and also you can use the latest video codecs that modern browsers support (smaller files, better quality). Desktop and mobile are different stories...
     
  11. MasterEpik

    MasterEpik

    Joined:
    Sep 24, 2014
    Posts:
    4
    Yes I am desperate I have no idea how to do that :(
    And no the game isnt operating inside a web browser.
    Well, I have got a few sprites in my 2D game and if I click on a thumbnail, a video should stream from my server.
    I call the video withe Application.URL function, furthermore an internet explorer opens and you see the link where the video is stored, but this is not what I want. I just want to click on the thumbnail and the video should open instantly with pause, play, exit to game controls maybe you can help me a bit.
     
  12. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Application.OpenURL is supposed to open up a web page in a web browser which it does. In your case, if you're only supporting web player, then you basically have two choices: handle it inside the web player plugin or handle it outside. It's your design choice. This plugin only does stuff inside the web player plugin, so if you need to download the clip with WWW class, pass the data to a MoviePlayer component in this plugin, and then script your own controls to handle play, pause, seek, etc. To handle the playback outside the web player plugin you need to edit the html that unity generates when making a web player build. You need to add some html5 video elements and javascript in there and control it all over Application.ExternalCall or Application.ExternalEval from inside Unity. There are probably some other plugins that are made to handle this specific web player video case.
     
  13. MasterEpik

    MasterEpik

    Joined:
    Sep 24, 2014
    Posts:
    4
    Oh okay, I understand but I forgot to mention that this game should work on mobile devices although
    thank you very much !!
     
  14. olix4242

    olix4242

    Joined:
    Jul 21, 2013
    Posts:
    1,962
    Hi, this is best video player for unity.
    I have one question: I have to play a same video on many materials (use a same video texture). For now, you can set it to play only on one material (plus one object). What is the easiest way to assign video texture to more than one material?
     
  15. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Thanks :)
    It's really simple, but requires a small script. You just need to assign the framebuffer texture to your own materials after the video has loaded. Here's a fancy script that does that each time the video starts playing.
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class AssignFramebufferToMaterials : MonoBehaviour {
    4.  
    5.    public Material[] materials;
    6.  
    7.    void Awake () {
    8.      var mp = GetComponent<MoviePlayer> ();
    9.      mp.OnPlay += delegate {
    10.        foreach (var m in materials) {
    11.          m.mainTexture = mp.framebuffer;
    12.        }
    13.      };
    14.    }
    15. }
     
  16. olix4242

    olix4242

    Joined:
    Jul 21, 2013
    Posts:
    1,962
    Thanks for a fast response! I wish I could give you a 6 stars vote on asset store :)
     
  17. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    5 is good enough, every vote helps a lot :)
     
  18. olix4242

    olix4242

    Joined:
    Jul 21, 2013
    Posts:
    1,962
    I have a problem but I don't know if it is directly connected with movie player or some assets that I imported, as it worked flawlessly till two days ago. I get this error (but everything works fine), then after some time (10-20minutes) I get a complete unity crash (too many heap sections):

    OutOfMemoryException: Out of memory
    MP.MoviePlayerEditor.GetSourceInfo () (at Assets/MoviePlayer/Scripts/Editor/MoviePlayerEditor.cs:30)
    MP.MoviePlayerEditor.OnInspectorGUI () (at Assets/MoviePlayer/Scripts/Editor/MoviePlayerEditor.cs:85)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1124)
    UnityEditor.DockArea:OnGUI()
     
  19. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Unity 4.x Editor is a 32bit application. If you have a lot of large assets regardless of their type, then Unity Editor just can't handle it. A solution to this is to have videos not in MyProject/Assets/ folder, but for example in MyProject/Cutscenes/. To load and play back the movie you currently need to do something like this from your own small script:
    Code (csharp):
    1.  
    2. public class PlayFromPath : UnityEngine.MonoBehaviour {
    3.    public string path = "Cutscenes/rwby.avi";
    4.    void Start () {
    5.      var mp = GetComponent<MoviePlayer> ();
    6.      mp.Load (path);
    7.      mp.play = true;
    8.    }
    9. }
    10.  
     
  20. edudsfdsgsd

    edudsfdsgsd

    Joined:
    Oct 24, 2013
    Posts:
    3
    We are very interested in GPU accelerated video (4K+). Does your plugin support that?
    One of the main drawbacks of MovieTexture (in Unity Pro) is that it only uses the CPU (and probably even just one thread), and thus with two Movies simulataneously playing the framerate drops to 10!
    Would your plugin do better (at this moment) than using MovieTexture?

    Thanks
     
  21. olix4242

    olix4242

    Joined:
    Jul 21, 2013
    Posts:
    1,962
    " A solution to this is to have videos not in MyProject/Assets/ folder, but for example in MyProject/Cutscenes/."
    Thanks a lot! This solved my problem!
     
  22. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    No, it won't do GPU decoding and max real world usable resolution is about 720p. It would be a nice challenge to implement, but it'll have limited target platform support and might be hard to support. So for now GPU support is not planned in near future, still I'd love to work on it.

    Up to 4K@60fps multi threaded video decoding would do on modern pc. Starting from 4K@60fps GPU is needed. About 8K@60fps is the upper limit possible on any PC.
     
  23. edudsfdsgsd

    edudsfdsgsd

    Joined:
    Oct 24, 2013
    Posts:
    3
    Too bad for the lack of GPU support (hope you'll find the time/energy to work on it some day! :) ). In any case, you say that up to 4K@60 fps should be fine on a multi-threaded CPU. Since in my 8-core i7-3770 @ 3.5 Ghz a single movie texture does not play smoothly (and with more it goes at <10fps!), I believe the Unity's built-in MovieTexture runs just in one thread. Is this correct?

    Or, in other words, is your plugin more efficient than the built-in MovieTexture?

    And another question, how difficult is to integrate a movie with a projector using your plugin? (with the built-in MovieTexture you just assign a MovieTexture to the projector).
     
  24. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    It's not more efficient, but it's not a pain to use :)

    It's easy, what you get as an output from this plugin is a regular Texture2D. All you need to do is create a material and assign it both to MoviePlayer and Projector.
     
  25. olix4242

    olix4242

    Joined:
    Jul 21, 2013
    Posts:
    1,962
    Here you can see this plugin in action. Everything was rendered in Unity in realtime.
     
  26. Stuttgart_Unity

    Stuttgart_Unity

    Joined:
    Oct 13, 2014
    Posts:
    1
    I would like to buy your plug in for my project in Unity Pro.
    The fallowing is what I am looking for :

    I have a GameObject (e.g. a plane) that has a MovieTexutre. I need a seek bar / scrubber for this video so that I can grab it and drag it back and forth to control the playback of the video.(like a normal video player such as youtube).

    is your plug in the right choice for this purpose ? is there a free version that I can test before buying ?
     
  27. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Yes, you can easily seek the video which you can't do with MovieTexture. There are downloadable desktop and web player feature demos on the first page of this thread (webplayer demo shortcut). What you see there is what you get (and more) when you purchase this package. There is no free unitupackage for testing, sorry.

    If it's right or not depends on your needs. With Unity pro you have more video playback options than this plugin, but now over half a year after releasing this, I know there are quite a few pro users who prefer this to all other options, even tho this plugin has its limitations.
     
  28. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    i got this error when i convert my video :

    please help me!
     
  29. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    What I see is that the encoding produced a file too large for Unity to handle as binary text asset, so it ran out of memory while trying to import it. Try to reduce video bitrate or resolution to get the file size down to a reasonable size, maybe a few hundred Mb max. If that's not possible, then the clip has to be placed outside Assets folder so that Unity won't try to import it by itself and let this plugin do that job through one line script GetComponent<MoviePlayer>().Load("path/file.avi")
     
  30. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    because this is a secret video , my client need login in unity by they account to see this video , that why i can't put it outside Assets folder ...
    so i have other way :
    if i bundle my video to file .unity3d and put it outside, you can use assetbundle to got file video in file .unity3d ?
    (I mean put it outside is ok , but we need coding it for they can't play this video !)
     
    Last edited: Dec 22, 2014
  31. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    With Unity 5 this issue will go away naturally, because it has 64bit editor. In Unity 4 loading asset bundles locally with videos inside should work, but I haven't tested it.
     
  32. dzl483

    dzl483

    Joined:
    Jan 3, 2015
    Posts:
    4
    I read the document but could not find if I can control playback frame rate real time using scripting. Hope there is an answer here. Thanks!
     
  33. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Didn't think people would want to do that, but why not :). Increasing framerate will make the clip shorter so it won't be in sync with audio any more (if there was any audio). In the next version I'll make it changeable by setting moviePlayer.framerate, but for now you'll have to do this (only works after the video has been loaded).

    Code (csharp):
    1. public static void ChangeFramerate(MoviePlayer moviePlayer, float newFramerate)
    2. {
    3.    moviePlayer.videoTime *= moviePlayer.framerate / newFramerate;
    4.    moviePlayer.movie.demux.videoStreamInfo.framerate = newFramerate;
    5. }
     
  34. dzl483

    dzl483

    Joined:
    Jan 3, 2015
    Posts:
    4
    Perfect! Thank you for your great help and looking forward to your next version! :-D
     
  35. dzl483

    dzl483

    Joined:
    Jan 3, 2015
    Posts:
    4
    Hi, I purchased this package and tried to control the playback framerate using scripting realtime. But I found it is impossible to pause the video when I set the framerate to zero. So I hope you could make the framerate control available for forward play, pause and reverse play.
    One more question regarding the audio part, I would like to know if it can load the video only and do not play any audio? I know it can be achieved by muting the video. But I would like to use some more video clips in the game, so wish the system to use minimum resources. Thanks!
     
  36. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Support for negative framerate... interesting. Have to test and make it work.

    Meanwhile a way to achieve what you want is by keeping the video paused (moviePlayer.play=false) and then driving moviePlayer.videoTime or videoFrame from your script directly.

    If you don't want to play audio together with a video, then the best way is not to encode an audio stream into the avi file in the first place. If the audio has to be in the avi file, but you just don't want to hear it, then there is a load option for that. Please see FeatureDemo scene, it shows how to do it from a script.
     
  37. Angelo-Granata

    Angelo-Granata

    Joined:
    Oct 22, 2013
    Posts:
    3
    Greetings ShuuGames,

    Could you please send me your email? this one is not working " toomas@shuugames.com"

    Thank you for your attention.
     
  38. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    That email is redirected to my gmail, so it should work well. I use it daily without any problems.
     
    Last edited: Jan 22, 2015
  39. Maza1999

    Maza1999

    Joined:
    Aug 14, 2013
    Posts:
    3
    Great product, been using 6+ months without a hitch.

    I have a client with a somewhat strange request; He provided a hex shaped .FBX file, created in Maya by making a short cylinder and setting the subdivisions axis to 6 (see attached zip file). I need to play a video only on one of the 2 large faces of the hex. I need the video to auto-scale with the size of the hex at run-time. A nice-to-have, is the ability to play to 2 separate videos, one on each side of the hex, but I can just make 2 separate hexes. I have no idea how to restrict video to one face of a 3D object, or auto-scale the video. And "perfect" would be the ability to play 8 separate videos, one on each of the 8 faces of the hex.
     

    Attached Files:

    • Hex.zip
      File size:
      4.9 KB
      Views:
      423
  40. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    That's great to hear.

    I can't open it where I am now, but principally you need to create UV map for your model. When you use multiple materials in 3d authoring tool then Unity will import these materials separately, each having it's own texture. To set up, say, 6 videos, you need to create 6 materials, attach 6 MoviePlayer components and make them write into those materials, and finally assign those 6 materials to the 3d model. UV maps will controls where those textures will be displayed on the model.
     
  41. Ingenieur

    Ingenieur

    Joined:
    Jan 16, 2015
    Posts:
    2
    Hi,

    we're using more than one instance of the MovieStreamer for different MJPEG-Streams but all instances show the same output. All instances show the stream that has been connected at last. Is it not possible to use multiple instances?
     
  42. OmerMuratli

    OmerMuratli

    Joined:
    Mar 11, 2014
    Posts:
    2
    I am using your player as a start video and when I load the level is starts playing after a key press e.g. Start button I destroys the object and starts the game. It work great in editor when ı reload the screen. However when I expport my game for windows when level reloads video stucks at the first frame and nothing happens game is not playing any videos. No debug errors exc.
     
    Last edited: Feb 10, 2015
  43. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Did you get it solved? I know at least one project which involved streaming 6+ mjpeg streams simultaneously. There's no technical limitation why multiple streams wouldn't work. Maybe you can create a sample scene and export in unityPackage so I could investigate what's going on.
     
  44. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Sounds strange. Race condition? Maybe try to verify if moviePlayer.play is true in the windows build. If you set that to true then the video should definitely play.
     
  45. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    648
    I'm looking for something that will play movies in both the webgl and ios player. Does this handle both use cases? I'm kind of assuming I won't find something that plays movies for webgl yet, but I'm hoping ... we can't switch our project from flash to unity without that :/.

    Thanks!
     
  46. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    This plugin essentially works in WebGL build, but there are a few issues. There is no audio for currently unknown reason. Video streaming doesn't work either, because it fails to start background thread which buffers incoming data. If you try make webgl build using the latest plugin version in Asset Store (v0.9) you'll likely get two compile errors which are trivial to fix (delete LocalWebcamStreamer.cs and comment out a small block of code in Streamer.cs). Next time I push it to Asset Store these compile errors are fixed and hopefully I figure out what's the problem with audio. Making the mjpeg streaming work in webgl gives me a headache just from thinking about it, maybe this plugin will never support it, depends.

    WebGL in Unity is still in "preview" stage, it has issues and how well stuff runs in different browsers, idk. But since this plugin relies only on Unity core features, then I can say with some confidence that when other stuff in Unity is stable in webgl then this plugin should be too. But from performance aspect, idk.

    Take a look, here's a feature demo webgl build :)
    http://shuugames.com/preview/mpwebgl/
     
    olix4242 likes this.
  47. shinichi88

    shinichi88

    Joined:
    May 4, 2011
    Posts:
    80
    Great work..!!
    I've purchase this and working pretty good at the moment on Android & iOS (32&64bit)...

    Just asking, is there anyway to reduce the file size of mjpeg?
    I've converted a MP4 (< 3MB) to MJpeg (8 MB).

    Video Quality 1 --> MJPEG (15 MB)
    Video Quality 10 --> MJPEG (5 MB)
    :)
     
  48. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    The most effective way is to reduce file size is to reduce resolution. I know it'll make it not look so good, but for example going from 720p to 480p will yield in 2.3 times smaller file which is almost guaranteed. It usually good to first find the minimum acceptable resolution with best qscale (compression quality) level and then reduce the qscale as much as possible. A good thing is that because mjpeg only has full frames, then reducing quality won't make the motions blurry and it's possible to sacrifice a bit more from still frame quality than with mpeg4 for example.

    Then if you have almost exactly the same video frames, then there is a tool that ships with this plugin which removes duplicate frames without any negative effect on playback.
     
  49. elliselkins

    elliselkins

    Joined:
    Mar 14, 2014
    Posts:
    6
    I'm looking for a way to do seamless transitions between videos. I've tried a few other options, but have run into problems. A common problem that I've seen is the loading time when loading the second video. To try to fix this I've tried creating a second instance of the video plug-in and replacing the first instance with the second when the first video completes. All the options I've tried so far wouldn't work with this idea either. One wouldn't draw the first frame of the second video correctly, showing a skip. Another plug-in would slow down when the second instance became active, and caused the second video to be choppy. Would a seamless transition be possible with this plugin? Thanks.
     
  50. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Loading and replacing a video clip with another usually takes less than 10 milliseconds with this plugin, unless it's hundreds of MBs or GBs. Usually it's fast enough for seamless switch and 0 video frames are dropped.

    I'd recommend using one MoviePlayer component and Load(...) method instead of switching different MoviePlayer components on-off (which will likely work well too, but has larger impact on memory).