Search Unity

MoviePlayer for Unity (plays MJPEG)

Discussion in 'Works In Progress' 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.5%
  2. h264 video + aac audio (less advanced, licensing and patent encumbered, but very common)

    65.8%
  3. Both

    21.1%
  4. Some other, please comment

    2.6%
  1. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    This plugin plays back AVI files containing MJPEG and MPNG video (not MPEG!) with PCM audio streams in both Unity 4 and 5, Free and Pro. All development and target platforms are supported, but it's meant primarily for standalone and web builds.

    You can use it for cinematic cutscenes, in-game TV screens and such, where the video clips are just too big for preloading tile-sheets and MovieTexture is not an option. Latest version also includes experimental web streaming feature, that can be used for viewing traffic cameras, security cameras, IP cameras and your own streams. See format limitations below.

    The feature demo comes with one embedded video clip ("Sintel" trailer, Bender open movie project), but you can use it to play back AVIs made by you too of course.

    Standalone feature demo (Win32)
    Standalone feature demo (OSX universal)
    Web player feature demo
    Reference PDF
    Asset Store link

    Feature overview
    • Instant seek, fast load, can do runtime loading, handles huge files, works in Editor, full source
    • Playmaker support
    • AVI playback using a MoviePlayer component or access AVI audio and video from a script
    • Simple “Movie Encoder” tool for converting movie clips into supported format (depends on ffmpeg)
    • Simple “Duplicate Frame Remover” tool for further reducing AVI file size without sacrificing quality
    • Experimental MovieStreamer component, that can play HTTP MJPEG streams. Requires Unity PRO
    • Implemented in managed C#, full source included

    Tech details and limitations
    • Up to 720p 30fps is the optimum quality on modern computers
    • No file size restrictions, multi-gigabyte AVIs load and play just fine
    • 1 audio and 1 video stream per AVI
    • Low memory footprint as movies are not preloaded, but streamed
    • Fully self contained, doesn't depend on MovieTexture or other libraries
    • Supports only MJPEG video, MPNG video with alpha and raw RGB(A) frames (32, 24 and 16bit)
    • Supports only PCM audio (N channels, any frequency, alaw, ulaw, 16bit signed LE, 8bit unsigned)
    • Plays HTTP MJPEG streams that have Content-Type: multipart/x-mixed-replace. This protocol is for low framerate video streams without an audio. “Internet cameras” often support it. Also applications like VideoLAN can output this type of stream.
    • It is NOT a general purpose media player!

    Here's how it looks in the Editor


    I'm excited to see if this can be useful on somebody :D
     
    Last edited: Jun 18, 2015
    eka ariyanto and jpthek9 like this.
  2. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Well that video doesn't work
     
  3. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Youtube link fixed
     
  4. SuperZac

    SuperZac

    Joined:
    Mar 1, 2013
    Posts:
    20
    This is awesome, I'm so excited to be able to make cutscenes in Blender instead of Unity itself.

    Not too familiar with MJPEG formats though, is there a quality difference?
     
  5. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Mjpeg is quite a simple codec compared to Theora, h264, mpeg4 and others. The main difference is that mjpeg doesn't do temporal compression while other video codecs usually do. It has good and bad sides to it. Mjpeg is a real winner if you're seeking a lot, because all frames are basically keyframes. You can also easily play the video backwards with mjpeg which is quite hard and slow for codecs with delta frames. Therefore mjpeg is often used in video editing as an intermediate format.

    For cutscenes and such mjpeg is perfectly suitable, but it comes with a cost, the files will be bigger than when using Theora for example. The worst case is a still image or slowly shanging image due to lack of temporal compression. Mjpeg shines most when the image changes rather unpredictably (snowstorm with a lot of falling snowflakes, some TV noise) or when the image changes fast. In real world you just have to test it. The same quality as with Theora is always achievable, but it may and likely will come with a cost of bigger files, but there are no real alternatives when you're stuck in free Unity version.

    That was a long answer, but I wrote it under an assumption that there'll be a lot of questions coming up about mjpeg. But I hope I also answered your question :)
     
    Last edited: Feb 19, 2014
  6. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Ok, it's accepted and available :)

    Asset Store link

    It states there that it requires "Unity 4.3.4 and up", which was added by admin, but just tested it with 4.0.1 and it required only 2 or 3 trivial modifications. In the first bugfix this will be updated.
     
    Last edited: Feb 28, 2014
  7. strobegen

    strobegen

    Joined:
    May 24, 2012
    Posts:
    8
    Is iOs, Android targets also supported?
     
  8. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Yes, all targets are supported... but the main selling point is that this plugin is really the only plugin that can play movies in standalone and web builds with Unity Free.

    Unless you have a specific reason to use this plugin (instant seek, runtime loading, direct access to streams in AVI container for example), then for general video playback on portable devices there are other plugins out there that do a better job (smaller file sizes, hardware decoding) and they work with Free license too. With my plugin a 2 year old Nexus 7 can almost play up to 480p video (sample movie that comes with the asset), but it skips about 5% of fames.
     
  9. shakhruz

    shakhruz

    Joined:
    Feb 17, 2011
    Posts:
    43
    Hi SHUU!
    Thank you for the plugin! Works like charm. The only thing I'm missing there is streaming a video file from URL. Is that possible, could you show an example of how to do that?

    Thank you in advance!
     
  10. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Thanks :)

    Free Unity has serious limitations for accessing network... so streaming is unfortunately not possible (there are some tricks and hacks if you really need to have streaming from the web, but that's not trivial to set up. I'll look into it next week and see what can be done, but don't get your hopes high). For now you can just download and play the file in free Unity. Here's a simple example in C#:
    Code (csharp):
    1. IEnumerator Start ()
    2. {
    3.     // download
    4.     var www = new WWW("http://domain/file.avi");
    5.     while(!www.isDone) yield return 1;
    6.  
    7.     // load and play
    8.     var moviePlayer = gameObject.AddComponent<MoviePlayer>();
    9.     moviePlayer.Load(www.bytes);
    10.     moviePlayer.drawToScreen = true;
    11.     moviePlayer.play = true;
    12. }
    Also, in a few days v0.2 will be up in Asset Store. No 2Gb limitation any more plus some bugfixes and improvements.
     
  11. NeythanQueija

    NeythanQueija

    Joined:
    Apr 18, 2013
    Posts:
    18
    The videos will be played on mobile devices(iOS and Android)? Because mobile doesn't work with Movie Texture.

    Thanks!
     
  12. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    I need to support video with Alpha... I use another engine, and there I have a "side by side" video where the RightSide is only Black/White and I use it as Alpha Channel Info.

    Does your video engine support something like this?
     
  13. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    First, some news about streaming possibilities... The mjpeg streaming solution that stays within free unity limitations is not coming. The reason is that it'll be hacky, unrealiable and would require server side setup. I'm afraid I won't be able to provide support for it, because of the whims of WWW class.

    "Only if you know what you're doing" answers it best :)
    While possible, normally you want a solution that decodes it in native code or hardware on portable devices, this plugin does it all in managed code. There are plugins in Asset Store specifically for that.

    I have two video decoders that support alpha - uncompressed RGBA (huge files!) and MPNG (more CPU intensive to decode than MJPEG, but supports alpha). Both of these should be in AVI container. If there's alpha in video then the target Texture2D framebuffer will be in a script readable RGBA32 format so that you can use it directly with builtin transparent shaders or use the alpha as you need it. MPNG is available since v0.3, which is submitted to Asset Store, but now yet reviewed by admins.

    Proably the easiest way to create MPNG AVI is to use ffmpeg on a sequence of 32bit png images, but surely there are other ways.
    Code (csharp):
    1.  
    2. ffmpeg -i frame%d.png -vcodec png movie.avi
    3.  
     
  14. ben.aten

    ben.aten

    Joined:
    Jan 10, 2013
    Posts:
    8
    Hi, Could you please let me know, how we can skip (move forward and backward) frames in a movie texture?

    Thanks, Ben
     
  15. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    That's really simple, just adjust the videoFrame or videoTime field at any time while playing (or not playing) and it's guaranteed that the next frame Unity renders to the screen will be from the new playhead position. If there is audio, it will be re-synchronized too.
    Code (csharp):
    1.  
    2. GetComponent<MoviePlayer>().videoFrame -= 10;
    3.  
    For absolute control about what and when to decode, you can access decoder instances directly too. There are examples in the source.
     
  16. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Can you add a mac version for testing.
     
  17. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Updated the feature demo in standalone builds to include mjpeg streaming over http. It can be used to test whether your streams can be played back and what's the performance.

    Besides win32 build the feature demo is now available as universal OSX build for Mac too.
     
  18. robertmathew123

    robertmathew123

    Joined:
    May 5, 2014
    Posts:
    1
    We are uploading the videos(30 videos) and we are trying to download using below code changing the Url and the video is uploaded in .avi format .We want to download 30 videos that are uploaded at the start of the game and want to play according to the game scenario.

    IEnumerator Start ()

    {

    // download

    var www = new WWW("http://domain/file.avi");

    while(!www.isDone) yield return 1;



    // load and play

    var moviePlayer = gameObject.AddComponent<MoviePlayer>();

    moviePlayer.Load(www.bytes);

    moviePlayer.drawToScreen = true;

    moviePlayer.play = true;

    }

    we are getting the following error

    System.ArgumentException: Unsupported PCM format=0x11
    at MP.Decoder.AudioDecoderPCM..ctor (MP.AudioStreamInfo streamInfo) [0x00042] in /Users/ateninc/Documents/Noufal/WNS/WNS_Prototype/Assets/MoviePlayer/Scripts/Decoder/AudioDecoderPCM.cs:54
    at MP.AudioDecoder.CreateFor (MP.AudioStreamInfo streamInfo) [0x00024] in /Users/ateninc/Documents/Noufal/WNS/WNS_Prototype/Assets/MoviePlayer/Scripts/AudioDecoder.cs:29
    at MP.MoviePlayerUtil.Load (MP.MovieSource source, UnityEngine.Texture2D targetFramebuffer, UnityEngine.AudioClip targetAudioBuffer, MP.LoadOptions loadOptions) [0x00100] in /Users/ateninc/Documents/Noufal/WNS/WNS_Prototype/Assets/MoviePlayer/Scripts/MoviePlayerUtil.cs:100
    at MoviePlayerBase.Load (MP.MovieSource source, MP.LoadOptions loadOptions) [0x00000] in /Users/ateninc/Documents/Noufal/WNS/WNS_Prototype/Assets/MoviePlayer/MoviePlayerBase.cs:128
    at MoviePlayer.Load (System.IO.Stream srcStream, MP.LoadOptions loadOptions) [0x00047] in /Users/ateninc/Documents/Noufal/WNS/WNS_Prototype/Assets/MoviePlayer/MoviePlayer.cs:108
    UnityEngine.Debug:LogError(Object)
    MoviePlayer:Load(Stream, LoadOptions) (at Assets/MoviePlayer/MoviePlayer.cs:115)
    MoviePlayer:Load(Byte[], LoadOptions) (at Assets/MoviePlayer/MoviePlayer.cs:73)
    <Start>c__Iterator2:MoveNext() (at Assets/MoviePlayer/Scripts/data.cs:22)

    what does the above error tells to to download videos in the start of the game.
     
  19. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    It says that the plugin thinks the PCM audio decoder should be able to decode the audio stream, but it can't. The reason is that the audio is actually not in a PCM format, but is encoded in a more advanced WAVE_FORMAT_DVI_ADPCM (defined in mmreg.h as WAVE_FORMAT_DVI_ADPCM 0x0011).

    If the audio is not needed, then the clip can still be loaded and played back like this:
    Code (csharp):
    1.  
    2. ...
    3. var moviePlayer = gameObject.AddComponent<MoviePlayer>();
    4. moviePlayer.loadOptions.skipAudio = true;
    5. moviePlayer.Load(www.bytes);
    6. moviePlayer.drawToScreen = true;
    7. moviePlayer.play = true;
    8.  
    But if the audio is needed then currently the only option is to encode the clips using one of the supported audio formats (8bit unsigned, alaw, ulaw or 16bit signed pcm). How to do it with ffmpeg encoder for example can be seen from Window/MoviePlayerTools/MovieEncoder(usesFFMPEG) menu option in Unity.

    PS. Use
    Code (csharp):
    1.  tags for readability ;)
     
    Last edited: May 5, 2014
  20. CrunchingTom

    CrunchingTom

    Joined:
    Mar 29, 2011
    Posts:
    42
    Hey ShuuGames,

    Your plugin looks really great! Can I ask you two questions?

    1. What are the supported PC operating systems? Windows, Mac OSX, Linux, Windows 8?
    2. Does it require any external software to be installed on user-end computer?

    Cheers,
    Tom
     
  21. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    should the mjpeg stream work in the webplayer?
     
  22. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    No special software or codecs are needed on the end user computer. This is because all the code is self contained, written in C# and depends only on managed Unity API.

    AVI playback should work on all PC standalone and web builds. I've tested it on Win7, WinXP and OSX, but there is no reason why it's shouldn't work on Linux too.

    The mjpeg streaming is still a bit experimental and needs more testing, but in general it is working, even in web player now.


    It should. Just finished patching the code that caused NotSupportedException. Submitted the fix to Asset Store.
     
  23. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Hi,

    Does it works with a DIVX file?

    Edit :
    Forget it. Just follow the rules : 'RTFM' :D
     
    Last edited: May 21, 2014
  24. Maza1999

    Maza1999

    Joined:
    Aug 14, 2013
    Posts:
    3
    Thank you for writing this plug-in. The Unity Quicktime import process does not always work, and this plug-in solved several long running issues for me.

    I wrote a short python script and a long python script to encode files for AVI Player encode_ffmpeg.py (tested only on windows, long version does not currently work on OS/X or Linux). This is probably overkill, but I lost more than a few minutes because of the required rename append the .bytes extension.

    Code (csharp):
    1. import datetime
    2. import os
    3. import sys
    4.  
    5. input_file_name_arg_index = None
    6. if sys.argv[0].lower().endswith("python"):
    7.     input_file_name_arg_index = 2
    8. else:
    9.     input_file_name_arg_index = 1
    10.  
    11. baseCommandAsString = "ffmpeg -i <INPUT_FILE_NAME> -qscale 4 -vcodec mjpeg -acodec pcm_s16le "
    12. currentTimeAsString = unicode(datetime.datetime.now()).replace(" ", "_").replace(":", "_")
    13. output_file_name = currentTimeAsString + ".avi"
    14. encode_command = baseCommandAsString.replace("<INPUT_FILE_NAME>", sys.argv[input_file_name_arg_index]) + output_file_name
    15. os.system(encode_command)
    16. os.rename(output_file_name, sys.argv[input_file_name_arg_index] + ".bytes")

    Long version designed to run when I have been up for 40 straight hours
    - Searches for ffmpeg if not in PATH or current dir
    - Writes and checks PID to make sure multiple scripts do not run at the same time
    - Verifies input file exists and is readable

    Code (csharp):
    1. import sys
    2. import os
    3. import datetime
    4. import fnmatch
    5. import logging
    6. import atexit
    7. import tempfile
    8.  
    9. def exe_location(program):
    10.     def is_exe(fpath):
    11.         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    12.  
    13.  
    14.     fpath, fname = os.path.split(program)
    15.     if fpath:
    16.         if is_exe(program):
    17.             return program
    18.     else:
    19.         for path in os.environ["PATH"].split(os.pathsep):
    20.             path = path.strip('"')
    21.             exe_file = os.path.join(path, program)
    22.             if is_exe(exe_file):
    23.                 logging.debug('ffmpeg found in path at: %s', exe_file)
    24.                 return exe_file
    25.     logging.debug('ffmpeg NOT found in PATH')
    26.     return None
    27.  
    28.  
    29. def find_ffpmeg():
    30.     return find_file("ffmpeg.exe")
    31.  
    32.  
    33. def find_file(target_file):
    34.     ffmpeg_locations_text = 'ffmpeg_locations.txt'
    35.  
    36.     # Use the first entry of ffmpeg_locations.txt for ffmpeg.exe
    37.     if(os.path.isfile(ffmpeg_locations_text)):
    38.         f = open(ffmpeg_locations_text, 'r')
    39.         ffmpeg_location = f.readline()
    40.         f.close()
    41.         logging.debug('using ffmpeg found on first line of ' + ffmpeg_locations_text)
    42.         return ffmpeg_location.strip()
    43.     else:
    44.         ffmpeg_location = exe_location(target_file)
    45.         # if ffmpeg is in current directory or PATH, do not search
    46.         exe_name = "ffmpeg.exe"
    47.  
    48.         if os.path.isfile(exe_name):
    49.             logging.debug("%s in current directory", exe_name)
    50.             return exe_name
    51.         if ffmpeg_location:
    52.             return exe_name
    53.         # request permission to search
    54.         will_search = raw_input("ffmpeg not found. You can set the explicit path to ffmpeg.exe by pasting the full path to ffmpeg in 'ffmpeg_locations.txt'\n\nSearch your hard drive(s) for ffmpeg.exe? (Y/n)")
    55.         logging.debug("User answered: %s", will_search)
    56.         if will_search.lower() == "y":
    57.             # searches all windows hard drives for ffmpeg.exe
    58.             matches = []
    59.             az = lambda: (chr(i)+":\\" for i in range(ord("A"), ord("Z") + 1))
    60.             for drv in az():
    61.                 for root, dirs, filenames in os.walk(drv):
    62.                     for filename in fnmatch.filter(filenames, target_file):
    63.                         matches.append(os.path.join(root, filename))
    64.             f = open(ffmpeg_locations_text, 'w')
    65.             for file_location in matches:
    66.                 f.write("%s\n" % file_location)
    67.             f.close()
    68.             if len(matches) > 0:
    69.                 return matches[0]
    70.             else:
    71.                 print("ffmpeg not found. Please install VDownloader.")
    72.  
    73. def pid_is_running(pid):
    74.     try:
    75.         os.kill(pid, 0)
    76.     except OSError:
    77.         return
    78.     else:
    79.         return pid
    80.  
    81. def write_pidfile_or_die(path_to_pidfile):
    82.     if os.path.exists(path_to_pidfile):
    83.         pid = int(open(path_to_pidfile).read())
    84.         if pid_is_running(pid):
    85.             print("Found a pidfile!  Process {0} is still running.".format(pid))
    86.             raise SystemExit
    87.         else:
    88.             os.remove(path_to_pidfile)
    89.     open(path_to_pidfile, 'w').write(str(os.getpid()))
    90.     return path_to_pidfile
    91.  
    92. def clean_up_pid(pid_location):
    93.     pid = str(pid_location)
    94.     os.remove(pid)
    95.  
    96. def check_pid():
    97.     temp_dir = tempfile.gettempdir()
    98.     pid_location = temp_dir + '/ffmpeg_finder.pid'
    99.  
    100.     # Only allow one instance of script to run
    101.     write_pidfile_or_die(pid_location)
    102.  
    103.     # Only register the pid clean up AFTER you have verified this is a valid process
    104.     atexit.register(clean_up_pid, pid_location)
    105.  
    106. def display_startup_message():
    107.     print """This program will run ffmpeg on a video file to generate a .bytes file compatible with AVI Player from SHUU games.
    108.  
    109.    1) .exe in first line of ffmpeg_locations.txt (note this can be any fully exec, such as ffmpeg1.exe, or c:\foobar.exe
    110.    2) ffmpeg.exe in path
    111.    3) Requests permission to search for ffmpeg.exe across all dirves and writes to ffmpeg_locations.txt
    112.  
    113.    If you do not have ffmpeg installed, I recommend downloading VDownloader
    114.    """
    115.  
    116. def process_args():
    117.     input_file_name_arg_index = None
    118.     if sys.argv[0].lower().endswith("python"):
    119.         logging.debug('Python Explicitly called')
    120.         input_file_name_arg_index = 2
    121.     else:
    122.         logging.debug('Python Implicitly called')
    123.         input_file_name_arg_index = 1
    124.     python_script_name = sys.argv[input_file_name_arg_index - 1]
    125.     input_file_name = sys.argv[input_file_name_arg_index]
    126.     logging.debug('Script name: %s', python_script_name)
    127.     logging.debug('Input file name: %s', input_file_name)
    128.     if not os.path.isfile(input_file_name):
    129.         logging.debug('Input file does not exist!')
    130.         print('Input file does not exist!')
    131.         sys.exit(-1)
    132.     if not os.access(input_file_name, os.R_OK):
    133.         logging.debug('Input file cannot be read!')
    134.         print('Input file cannot be read!')
    135.         sys.exit(-1)
    136.     if os.path.isfile(input_file_name + ".bytes"):
    137.         logging.debug('Output file already exists!')
    138.         print('Output file ('+input_file_name + ".bytes"+') already exists! Exiting')
    139.         sys.exit(-1)
    140.  
    141.     return input_file_name
    142.  
    143.  
    144. def run_ffmpeg(input_file_name):
    145.     baseCommandAsString = "ffmpeg -i <INPUT_FILE_NAME> -qscale 4 -vcodec mjpeg -acodec pcm_s16le "
    146.     currentTimeAsString = unicode(datetime.datetime.now()).replace(" ", "_").replace(":", "_")
    147.     output_file_name = currentTimeAsString + ".avi"
    148.     commandAsString = baseCommandAsString.replace("ffmpeg", find_ffpmeg())
    149.     encode_command = commandAsString.replace("<INPUT_FILE_NAME>", input_file_name) + output_file_name
    150.     logging.debug('Command: ' + encode_command)
    151.     logging.debug('Beginning Encoding: ' + encode_command)
    152.     os.system(encode_command)
    153.     logging.debug('Renaming output')
    154.     os.rename(output_file_name, input_file_name + ".bytes")
    155.     logging.debug('Renaming complete')
    156.  
    157.  
    158. if __name__ == '__main__':
    159.     logging.basicConfig(level=logging.DEBUG,
    160.                         format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
    161.                         datefmt='%m-%d %H:%M',
    162.                         filename='ffmpeg_encoder.log',
    163.                         filemode='w')
    164.     logging.debug('New run started')
    165.  
    166.     check_pid()
    167.     display_startup_message()
    168.     input_file_name = process_args()
    169.     run_ffmpeg(input_file_name)
    170.     logging.debug('Script execution complete')
     
  25. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    I've been thinking about adding VP9 support since more and more Unity Pro users are using this plugin and asking for something better than mjpeg. VP9 codec is more advanced than Theora or even h264. Together with that it'd be nice to have Vorbis audio and maybe MKV container support too. These are just thoughts right now...

    Thank you for sharing these scripts, maybe it'll be useful for someone.

    About the bytes extension... "Window/Movie Player Tools/Movie Encoder" will get a checkbox for that in next version. Didn't thought about that before. Not everyone loves command line :)
     
  26. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Does it works well on mobile?

    I will need to play 2 to 3 simultaneous small videos (560/224) on screen, would this be possible with it?
     
  27. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    It's stable, reliable and not device dependent on mobile, but performance, battery life and file size might be issues. It's just the limitation of the mjpeg codec used. Since primary target of this plugin is desktop and web player, you might want to look for other video playback plugins too. Don't want to cause disappointment.

    On desktop or web player it's totally fine. On mobile, any over average device should be able to handle 2 or 3 small simultaneously playing video streams.
     
  28. CrunchingTom

    CrunchingTom

    Joined:
    Mar 29, 2011
    Posts:
    42
    Hey guys!

    Just wanted to say that the plugin is awesome and it will make MouseCraft movies look a lot better on PC ;).

    Cheers,
    Tom
     
    ShuuGames likes this.
  29. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Thanks Tom. Great to hear that :)

    *goes to check that game out*
     
  30. MCharikov

    MCharikov

    Joined:
    Jun 23, 2014
    Posts:
    1
    Hi!

    A very nice plugin! We try to use it for real time mjpeg stream playing. Works perfect on Win, but for Mac there is some issue. When some other window is placed on top of unity app - video stops playing. That's ok, but after unity app get focus back, video continues its playback with time lag about 3-5 seconds. We use your demo app for testing.

    Is there any way to beat this problem, cause 5 seconds lag is critical for us?

    Thank you!

    Mike
     
  31. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    In the current demo app "Run in background" is not enabled, but probably in your streaming app you want to enable it. Otherwise the connection may drop, although I haven't seen that often. Also you should check the stream bitrate, it may be too high for your connection.

    The lag is probably due to various network buffers, mostly in operating system. This plugin itself has one frame receive buffer. Right after the last byte of a frame is received, it gets displayed on screen (that's also why low framerates work much better with this plugin). The best that this plugin can do for reducing lag is to tune OS socket options, but that's quite tricky, because defaults should be quite good already. It's quite advanced stuff, but if the bitrate is low enough for your connection and there are still lag problems, then you can try tuning network socket options in HttpMjpegStreamer.cs script.
     
  32. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Hi! I just bought your component!

    I need to put the video on a dialog, so I added as child of a GameObject on my Dialog. But it's position seems to not change relative to the parent, is this expected? How can I acheive this?
     
  33. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Hi. For screen space positioning tick DrawToSceen, set ScreenMode to CustomRect and then you can enter pixel coordinates. For supporting multiple resolutions, you probably need to update that rect from your own script as needed.

    For world space positioning, just create some game object with a renderer (a cube maybe), attach MoviePlayer component and the video is drawn using that renderer. Most renderers draw where the transform is positioned (that's the case with meshes usually), but maybe that's not the case with your UI system, idk.
     
  34. jarden

    jarden

    Joined:
    Mar 29, 2011
    Posts:
    74
    What are the benefits over using sprite animation with jpegs or pngs?
     
  35. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Here is API and components for easy playback control. You get synchronized audio. There's one file to manage instead of thousands. You don't have to worry about memory usage. Anything over a few seconds with reasonable resolution gets troublesome and slow to manage when using simple sprite animations. Build platform quirks are ironed out and it's guaranteed to work fully in Free Unity (except webcam stream receiver which requires Pro) and web player.
     
  36. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Question to whoever may be reading this...

    Would you care about GPU accelerated 4K and 8K video playback support in Unity? Same mjpeg codec.

    It'd be targeted for high end machines for special purposes like interactive on-state shows, art installations and such. Due to huge files and requirement for powerful machines, I wouldn't recommend it for regular games.

    Or what about VP9 support, but it'd be CPU only?
     
    Last edited: Aug 1, 2014
  37. hkessock

    hkessock

    Joined:
    Apr 26, 2011
    Posts:
    21
    I would like to use this for iOS and Android as well as PC/OSX, I am hoping that it can be used like movietexture
     
  38. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Since the plugin launch people have been asking for that... I feel like swimming against the flow by not making mobile top priority. Maybe I should.

    Mobile is currently supported and will be supported in the future. I've researched that decoding performance can be increased about 3x times or more on all platforms using the same mjpeg codec without breaking compatibility. 720p on mobile and 4K on desktop will become possible, but a huge BUT remains, file sizes won't become smaller.
     
  39. hkessock

    hkessock

    Joined:
    Apr 26, 2011
    Posts:
    21
    Well, I think you should trumpet that fact clearly in your advertising because if this works for me on PC, OSX, iOS, and Android - you are saving me from some serious logistical issues because I actually do support all of those platforms and using video across them has been a real problem due to Unity not having its own video support on mobile.

    So, you can use the this to update a texture reference in real-time from a dynamically loaded video (loaded from the local filesystem, not part of the assets/streaming assets)? If so, you're a life saver.

    Now, if only MJPEG wasn't so large lol. That's okay, I'll take it.
     
  40. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Yup, that's what this plugin can do too on every build platform (even in web player and consoles) :)

    And thank you for feedback.
     
  41. Sollare

    Sollare

    Joined:
    Feb 14, 2012
    Posts:
    6
    I just bought you asset, i found it very useful! Even works fine with NGUI UITexture :D Im very happy about it.
    But i have one little question - how can i load files from local disk? Only just using streamer? Or i can download it using WWW or some file manager, and the provide data to your player?
     
  42. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Thanks! That can be done from a script. Load method can take absolute or relative file path, byte array, binary TextAsset or .NET Stream. In web player build you can take byte array from WWW class and pass it to Load method.

    Code (csharp):
    1. var mp = GetComponent<MoviePlayer>();
    2. mp.Load("C:/movie.avi");
    3. mp.drawToScreen = true;
    4. mp.play = true;
    5.  
     
  43. Phiru

    Phiru

    Joined:
    Oct 29, 2012
    Posts:
    32
    I read a post saying it works on Android platform as well.
    Questions.(All questions are on Android)
    1. Does it only support only full screen?
    2. Can I begin a movie at a certain position and stop? I mean, possible to control time or frame?
    Once you reply to me, I am going to buy it. Thanks.
     
  44. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Works very well, but keep mjpeg limitations in mind, discussed in this thread.

    It renders into Texture2D, so besides fullscreen option you can use any material and shader combination to play it back where you need to.

    Yes, you can set the playhead position anytime with instant response. Stop and start with 1 frame precision. Audio is automatically synced too. If your particular need can't be done with parameter fiddling in Inspector, then a simple script can surely do it.
     
    Phiru likes this.
  45. Phiru

    Phiru

    Joined:
    Oct 29, 2012
    Posts:
    32

    Awesome! It has everything that I need.
     
  46. Sollare

    Sollare

    Joined:
    Feb 14, 2012
    Posts:
    6
    I need your advise :)
    I have a task - show the gallery of the availiable videos. For example - 10 for a screen, table style. And when im opening this gallery, i need to show the first frame of the video in each cell. I guess, using .Load() method - is not a good option ^_^
    Can you suggest how to reach this goal, using your asset, without a big losses? Thank you!

    --UPDATED--
    And btw - Load() is async operation? When the movie is ready to play - OnPlay event is called, right? If yes, the main problem - is to put 10 request to an queue, and starting them right after OnPlay is called. Is this a good solution?
     
    Last edited: Aug 27, 2014
  47. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Is'nt it compatible with Windows Store builds?

    Assets\MoviePlayer\Scripts\Net\HttpMjpegStreamer.cs(10,18): error CS0234: The type or namespace 'Sockets' could not be found in namespace 'System.Net'. Are you missing a using directive or an assembly reference?

    Assets\MoviePlayer\Scripts\MpException.cs(25,23): error CS0246: The type or namespace 'SerializationInfo' could not be found. Are you missing a using directive or an assembly reference?

    Assets\MoviePlayer\Scripts\Net\HttpMjpegStreamer.cs(154,11): error CS0246: The type or namespace 'Thread' could not be found. Are you missing a using directive or an assembly reference?

    Assets\MoviePlayer\Scripts\RiffParser.cs(26,31): error CS0246: The type or namespace 'SerializationInfo' could not be found. Are you missing a using directive or an assembly reference?

    Assets\MoviePlayer\Scripts\RiffWriter.cs(27,31): error CS0246: The type or namespace 'SerializationInfo' could not be found. Are you missing a using directive or an assembly reference?
     
  48. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    Loading a video is not async, but is very fast. Some performance numbers for Load()-ing up a video file and decoding first frame. Rather regular PC, no SSD. Add MP_DEBUG flag in Unity build settings to log these numbers for your videos.
    * 30MB 360p AVI file ~9ms
    * 2GB 720p AVI file ~25ms

    I'd spread loading a lot of videos over many frames like this. Load method also decodes first frame.
    Code (csharp):
    1. IEnumerator Start()
    2. {
    3.    for(int i = 0; i < moviePlayers.Length; i++)  {
    4.      moviePlayers[i].Load(fileNames[i]);
    5.      yield return 1; // wait 1 frame
    6.    }
    7. }
     
  49. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    That's weird, please PM me which unity version, op system and build target settings you are using.
     
  50. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Unity 4.5.3f3
    Windows 8.1
    Build for Windows Store
    Type XAML C# Solution
    SDK 8.0