RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
224 stars 27 forks source link

TextureProducer.GetTexture() has all pixels RGBA(0,0,0,0) on Windows editor when FirstFrameReady event is triggered #1803

Closed yasirkula closed 3 months ago

yasirkula commented 3 months ago

Describe the issue I'm trying to get the video's first frame but the resulting texture has all pixel values set to (0,0,0,0) even though FirstFrameReady event is triggered.

PS. After restarting Unity, this issue doesn't occur all the time but it still occurs from time to time, so the issue still exists. PPS. Our project had Configurable Enter Play Mode optimization enabled. If I turn it off, the issue occurs much more frequently.

Your Setup (please complete the following information):

To Reproduce Attach the following component to a new MediaPlayer object in a new scene and enter play mode (try a few times if the issue doesn't occur immediately):

private MediaPlayer videoPlayer;
public RenderTexture rt;

private void Start()
{
    videoPlayer = GetComponent<MediaPlayer>();
    videoPlayer.Events.AddListener(OnVideoPlayerEventTriggered);
    videoPlayer.OpenMedia(MediaPathType.AbsolutePathOrURL, @"C:\Users\User\Desktop\Test.mp4", false);
}

private void OnVideoPlayerEventTriggered(MediaPlayer videoPlayer, MediaPlayerEvent.EventType eventType, ErrorCode errorCode)
{
    switch (eventType)
    {
        case MediaPlayerEvent.EventType.ReadyToPlay: videoPlayer.Control.SeekToFrame(0); break;
        case MediaPlayerEvent.EventType.FirstFrameReady: OnVideoFirstFrameRendered(); break;
    }
}

private void OnVideoFirstFrameRendered()
{
    rt = new RenderTexture(512, 512, 0);
    Graphics.Blit(videoPlayer.TextureProducer.GetTexture(), rt);
}

private void OnGUI()
{
    if (rt)
        GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height), rt, ScaleMode.StretchToFill);
}
Chris-RH commented 3 months ago

Have you tried this

yasirkula commented 3 months ago

It works. My code also works right now. 5 minutes ago, it didn't work at least immediately after a code compilation but now it isn't affected by code compilation. I don't know why it all behaves correctly now. I had implemented a solution that waits 1 frame after the FirstFrameReady event and I'll be sticking with it, just in case.