Standalone / web streaming video choppy, black frame, skip seconds

I’m trying to play a movie (.mp4) inside my game as intro.
However I’m having a couple of issues I’m running into which I tried to google. But the examples I found do not solve what I’m facing.

First I’m creating the game for both standalone and webplayer.
In the standalone I can load my movie into a movietexture, but what I encounter is that it starts with a black frame which I do not have in my actual movie. And besides that, it doesn’t play straight from the beginning.
For example, my movie starts with the black frame and jumps 3/4 seconds into the movie and starts from there.
I’ve tried a couple of solution with coroutines and without, but I can’t seam to solve this.

Besides that. I also try to publish this game project for the webplayer and I can’t seam to stream the video from a folder named “movie” where the movie named “movie_beheer.mp4” is located. The html file is outside the movie folder. So it should find it somehow, but doesn’t stream at all.

Also I’m trying to find a way how to check if the movie is finished playing. However if I use !movieTexture.isPlaying and load a scene, it just doesn’t stream the video in webplayer but just loads the scene and acts like it’s done playing the movie.

Here is what I got so far with C#. I just can’t find a way to have the video play correctly in both situations.

using UnityEngine;
using System.Collections;

// [ multi platform support ]
public enum MoviePlayTextureState
{
    WEBPLAYER,
    STANDALONE,
}

// [ Required Components ]
[RequireComponent(typeof(AudioSource))]

public class MoviePlayTexture : MonoBehaviour 
{
    // [ Variables ]
    public MovieTexture movieTexture;
    public string pathMovieForWeb; // path name is string: "movie/movie_beheer.mp4"
    MoviePlayTextureState state;

    // [ Functions ]
    /*----------------------------------------------------------------------
        Start ( Unity standard )
    ----------------------------------------------------------------------*/
    void Start()
    {
        detectPlatform();
        switch (state)
        {
            case MoviePlayTextureState.WEBPLAYER:
                loadMovieWeb(pathMovieForWeb);
                break;
            case MoviePlayTextureState.STANDALONE:
                loadMovieStandalone(movieTexture);
                break;
            default:
                break;
        }
        
    }

    /*----------------------------------------------------------------------
        Update ( Unity standard )
    ----------------------------------------------------------------------*/
    void Update()
    {
        playMovie();   
    }

    /*----------------------------------------------------------------------
        detectPlatform
    ----------------------------------------------------------------------*/
    void detectPlatform()
    {
        bool platform = Application.isWebPlayer;

        // - check platform
        switch(platform)
        {
            case true:
                state = MoviePlayTextureState.WEBPLAYER;
                break;
            case false:
                state = MoviePlayTextureState.STANDALONE;
                break;
            default:
                break;
        }
    }

    /*----------------------------------------------------------------------
        loadMovieWeb
    ----------------------------------------------------------------------*/
    void loadMovieWeb(string vFilePath)
    {
        WWW www                 = new WWW(vFilePath);
        movieTexture            = (MovieTexture)www.movie;
        initMovie();
    }

    /*----------------------------------------------------------------------
        loadMovieStandalone
    ----------------------------------------------------------------------*/
    void loadMovieStandalone(MovieTexture vMovieTexture)
    {
        initMovie();
    }

    /*----------------------------------------------------------------------
        initMovie
    ----------------------------------------------------------------------*/
    void initMovie()
    {
        GUITexture tex          = this.guiTexture;
        float aspectRatio       = Screen.width * ((movieTexture.height + 0.0f) / (movieTexture.width + 0.0f));
        tex.pixelInset          = new Rect(0 - Mathf.Ceil(Screen.width * 0.5f), 0 - Mathf.Ceil(aspectRatio * 0.5f), Screen.width, aspectRatio);
        tex.texture             = movieTexture;
        audio.clip              = movieTexture.audioClip;
        audio.minDistance       = 1000;
    }

    /*----------------------------------------------------------------------
        playMovie
    ----------------------------------------------------------------------*/
    void playMovie()
    {
        if (movieTexture.isReadyToPlay  !movieTexture.isPlaying)
        {
            movieTexture.Play();
            audio.Play();
        }
    }
}

I wonder no one has this same problem experienced? I tried to get some usefull information from the documentation, however this doesn’t describe what problem I could encounter or how to fix it, nor these problem should occur.
I see numerous people having this same question when I google. But none seam to actually work when there is an answer posted.
What am I doing wrong to let this video play correctly in standalone and web?

Thanks for the information, I wonder how usefull this forum actually is.
I’m working on projects for customers and solve about 98% of my problem myself. However if I have a serious issue with Unity and my project I actually try to search the whole web or ask people I know who use Unity.

However the last weeks it seams that my questions seam to be rocket science or something. From terrain patch issues, to strange billboard trees and now this strange black frame in my movie and skipping seconds of playing it. Not to mention the huge amount of interface, viewport, culling, painting collider errors I get when using the terrain system which I even didn’t bother to mention here. I can write an complete assay about that, or I’m I really the only one using Unity which encounter these issues? That terrain system isn’t finished at all, it has huge amount of issues if you work seriously with it.

I really would like to see this software as one of the best solutions for Indie game development and improve it. But it seams like I’m trying to move a cow which seams to consume 100kilo gras every second, making it harder and harder to work with.

I thank those who helped me out on these forums, I really do. But for now my fate of gone. Back to countless hours of googling and breaking my head to find a workaround… again!!

Hi,

I spend a lot of time too when I have a problem researching. I also spend time helping out when I can.

It may be that no one reading in the last few days has experienced your issues, or have even seen this post. I understand it can be frustrating at times, but you’ll resolve it I’m sure.

Regarding the black frame: I have seen it myself, but that was so long ago I don’t honestly recall what the fix was. Nor do I have access to the project at the moment unfortunately…

A quick search found this thread though:

I would also focus on getting it running on say the standalone first. When that’s done, you’ll be able to troubleshoot the other issue easier hopefully!

Good luck!

Thanks for your answer, however I came across this page as well and tried it yesterday. Since my video would also only show 23kb filesize in the inspector. I totally re-encoded my movie with the program “EasyBrake” as unity did reimport the video with a proper filesize notation in the inspector.
However the black frame still did exist and still first 3 seconds of my movie are still being skipped.

I tried the function MovieTexture.isPlaying and MovieTexture.isReadyToPlay. Which my my opinion would only return true if my video is indeed ready to play and playing. I assign my movietexture to a GUITexture offscreen and afther both functions return true, it’s positioned on screen.

So I go from my game scene to an empty scene and the scene containing this movie is being loaded. The movie scene is being loaded using Application.LoadLevel(“scene_movie”), the if statement containing movieTexture.isReadyToPlay movieTexture.isPlaying are both returning true. But then I’m waiting 5 seconds ( so clearly this movie isn’t ready to play ) and looking at a black screen. Then suddenly I see my movie being displayed with the first 3 seconds being skipped. And plays smooth in my Editor.
When testing this standalone, it just does the same, except this time my movie is stuttering and looks like I’m on low fps. But my machine is really a monster, the scene before loading this movie scene is about 100 times bigger and heavier, so that can’t be an issue. I already have a empty scene between my game and movie to clear the memory useage for the browser version. ( that’s another story of a work around I had to make )

When I play this same movie from my assets folder in mediaplayer VLC, it shows me just a nice white starting screen ( like I edited my video ) and loads just fine without skipping anything.

I’m on the edge of going nuts and pulling my hear out. I’m sure I would find an solution to my problems with Unity. But this time I’m completely clueless.

I’m even on the edge of writing a script that does pixel color detection to check if my GUITexture with the movie is displayed black, then if the pixelTest returns a black color. Pause the movie, stop the movie and rewind it.
But if I have to use this kind of script abomination, then I’m really disappointed about how Unity loads movies. I have no clue why others playing movies inside games don’t have this issue. Or should I not want to have my first frame white instead of black?

Other thing that comes to mind. It seams the video is starting at a point where the audio on my video is starting. It could be that Unity is making it’s own decisions to not display my video until the point where audio comes into play.
Could that be true? Because I did read something about movie being synchronized with audio. But then, who doesn’t have a silenced start of his video? Should I just add a noise from the beginning to fix this black frame and 3 seconds skip issue?

Been 3 days now to find a solution just to play a simple movie in my scene. Or am I a perfectionist who just has to deal with the black frame and 3 seconds skip?

Ok people, no worries no crying no nothing. I finally fixed the problem.

It’s a Unity bug I think
Let me tell why!

I have the exact same script loading 2 different videos encoded with the same settings.
Video 1, start with white screen, fade in 3 seconds and starts with a nice movie + audio
Video 2, start with a white screen and directly has noise added to the audio track playing right on the 1st frame. After fade is done, the nice movie starts with audio.

Video 1 has the issue starting with a black frame and jumps into the video after 3 seconds ( where the audio starts, i mean where you hear something ) and plays fine

Video 2 has no issue, because to test this bug, I just added horrible noise right from the start to the audio track inside the video. And well the video starts just fine without any black frame of skipping 3 seconds

Who ever encounters the black frame and skipping seconds in the movie. This is your workaround! Your video needs audio from starting to end frame. Audio not having any sound at the start is also creating a black frame and seconds skipping. So adding a really light noise would fix this issue. Sounds as horrible workaround ( hahaha sounds, you get it wink wink) and is a horrible workaround and this needs a fix in my opinion!

If you think this isn’t working, I can screen record all this and show this issue right away!

The only reason I can think of this is my fault. I need some funcky audio setting to set right in my video compression. But the presets I use are just industry standard presets from Afther Effect. So I guess that would be standard somehow. Maybe the code synchronizing video with audio is somehow funky.

Would like to see a reaction on this from a Unity Developer confirming this.
I’m trying out several videos right now to test some other situations.

The above is confirmed, it is indeed the audio track with the video.

Test cases I’ve done:

Video1: white fade into movie, when fade done, audio starts to take volume
Video2: white fade into movie with audio volume as loud noise from the beginning all the way to the end
Video3: white fade into movie, when fade done, audio starts to take volume, also compressed with different application and settings

Result:

Video1 as MovieTexture: black frame appears, 3 second of black frame, then movie starts where audio takes volume. The 3 seconds of black frame is the 3 seconds that white should fade to movie and has an audio track but 3 seconds no volume or activity inside the audio track.

Video2 as MovieTexture: plays correctly, starts with white frame fading into the movie while during the fade some audio noise. This video does play correctly without skipping anything of the video and without a black frame

Video3 as MovieTexture: does the same as Video1, black frame for 3 seconds ( where audio track is present but has no activity or volume ) and start to show movie where audio takes volume.

Conclusion 1:
Your video needs all over the sequence an audio clip which has activity at the start of the first frame, or Unity will start to show the video where audio takes volume.

How to fix?:
Slight noise or single frame activity on the audioclip at the 1st frame. This prevents the black frame and now showing movie until audio has some activity and volume.

What causes this?
Not assigning any audio to an audiosource, still does playback the video. Because somehow de audio is linked to the movietexture.
I’m not a Unity Developer, but I think this has to do with the importing of videos in Unity3D 4.x. Somehow the video is synchronized with the audio volume activity. So no activity and volume, no movietexture displayed.

I’m curious what happens if you have an movie that has nog audio activity inside it. Here I mean, that the audio in the movie has a straight line of 0DB from start to end. Does this playback as movieTexture? I don’t know because I do not have the time to test this. But if my conclusion above is right, it should show the whole duration of the movie a black frame. If not, then something else is funky here.

I tested another application with another compression and it does not make a difference.

Conclusion 2:

If I however export an mp4 from premiere or after effects, this video does not play at all except the audio. Somehow it only shows me a gray frame or black frame. Also my movie isn’t 100mb as it should be, but displayed in the inspector as 230kb. Unity just didn’t import the video correctly or, didn’t import it at all.

Re-encoding this with “EasyBrake” EasyBrake download | SourceForge.net fixes this problem. As soon I re-encoded it and put it in my assets folder, it does import the video. It takes about 15/20minutes but then I have a video that plays fine if it has audio activity straight from frame 1. If not, still a black frame.

To Unity Developers

I think the movie import function needs a good redo. What’s wrong here?
It took me 3 days to figure this out. From googling around, reading documentation about 50 times, reading scripting reference about 50 times, calling friends, calling freelancers. No solution found!!
What I wrote above should be the solution, I hope someone having this same problem find this usefull. Because it would have saved me 3 days of headbanging against my desk and having a hair redo because I pulled it all out.

Topic Solved in my case <<
Need investigation by Unity <<

Hi,

Great to hear you’re able to finally track it down!

Can you file a bug report with Unity, and attach a test case?

I’ll try to do that, however using this topic to track down the bug would be faster for me. The project I have to report with is huge, big in filesize and takes about ages for them to find what I’m talking about. So I have to make a special testcase for which I do not have time at this moment.

Hi, JDMulti.

I am facing exactly the same problem, but your workaround didn’t work for me. My videos have sound from frame number 1, The behavior is, however, the same you described. I have also read here that it might be solved by loading the videos that will be played in the videotextures from disk using www. It didn’t work neither.

This thread states that the problem has been around for over three years now, so it is a bit worrying. It appears to happen only in Mac.

Any other ideas for a workaround to this issue?

Regards,

Hi again.

After some more research, I have discovered that the problem is solved if I use mp4 videos and allow Unity to import them to convert them to ogg. I was using Miro Video Converter to convert to ogg to control the image quality, since Unity was messing with it.

Miro must introduce some kind of stuff that Unity doesn’t like very much.

Hope this help somebody.

Regards,