Unity Video Player

smallarrows.GIF

Basic Scene Setup for a video player no lighting

Your video files should be stored in the Assets folder for this procedure.

FFMPEG
Use ffmpeg to encode h.265, windows DOS script for a batch file:
set dt="%USERPROFILE%"\Desktop
set tiffs=-framerate 30 -start_number 1 -i F:\tiff_filename.%%04d.tif -pix_fmt argb
set loopend=1000
set codec1=-vcodec libx265 -x265-params bitrate=35000:vbv-bufsize=8000:vbv-maxrate=40000 -pix_fmt yuv420p -movflags +faststart -pass 1
set codec2=-vcodec libx265 -x265-params bitrate=35000:vbv-bufsize=8000:vbv-maxrate=40000 -pix_fmt yuv420p -movflags +faststart -pass 2
set sp=1
set output=%dt%\filename
ffmpeg.exe -y %tiffs% -frames %loopend% -filter_complex scale=iw*%sp%:ih*%sp%,setsar=1 -r 30 %codec1% -f mp4 NUL
ffmpeg.exe -y %tiffs% -frames %loopend% -filter_complex scale=iw*%sp%:ih*%sp%,setsar=1 -r 30 %codec2% -f mp4 %output%.mp4
del ffmpeg2pass-0.log


I have am using bitrate=75000 and maxrate=80000 on a project, it works great.

Adobe Media Encoder Settings
Format: HEVC (H.265)
Preset:
     Uncheck Export Audio if you do not have audio
     Select Render at Maximum Depth
     Performance: Software Encoding
     VPR, 1 pass
     Target Bitrate [Mbps] 15
     Maximum Bitrate [Mbps] 20
     Quality: Highest (slowest)
     Key Frame Distance: 30
     Select Use maximum Render Quality


Computer Setup

You may need to install K-Lite Mega codecs
You may need to install HEVC Video Extensions for h.265.
Try running your h.265 mp4 file with Microsoft Windows Media Player, if the file runs, you don't need any HEVC codecs.


In Unity, use version 2019 or newer
File->Save as
your scene as a new name. This is a scene within the project.

For efficiency you can delete the default Directional Light in the Hierarchy tab

Select the Main Camera
     Change Clear Flags change Skybox to Solid Color
     Change the Background color to black
     Set Culling mask to Nothing, and then Default (default Everything)
    Uncheck Occlusion Culling
     Set HDR to Off    
     Set
MSAA to Off
     Uncheck Audio Listener (unless you have audio)

Choose Edit->Project Settings... Quality
     Uncheck all the Levels except Very Low  (Video does not need high)
     Hold the down arrow and set Default to Very Low
     The defaults for Very Low should be good.
     Close the window


Choose Window->Rendering->Lighting Settings
   Skybox Material, Select the unity_dot button and choose None
    Sun Source, Select the unity_dot button and choose None
    Environmental Lighting, select Source Color
    Change the Ambient Color to black
   
Environmental Reflections change Source to Custom
    Uncheck Realtime Global Illumination

    Uncheck Baked Global Illumination
    Close the window

Add a Video Player Object to your Hierarchy tab
Select GameObject->Video->Video Player
     Select the Video Player from the Hierarchy
     In the Inspector on the right:
         
Select the unity_dot button to the right of Video Clip add one of your video clips.  (In Assets folder)
          Select Loop
          Select Render Mode   Camera Near Plane
         
Select the unity_dot button to set Camera to the Main Camera, look in scene tab of the dialogue
          Set Aspect Ratio to No Scaling

          Set Audio Output Mode to None

Video Player Defaults
     Source Video Clip

     Video Clip None
     Play on Awake checked
     Wait for First Frame checked
     *Loop not checked
     Skip on Drop checked
     Playback speed 1
     *Render Mode render texture
     Target Texture None
     *Aspect Ratio Fit Horizontally
    * Audio Mode Direct


Add a Script to the Video Player to change videos with the keyboard
Select Video Player from the Hierarchy
     Choose Add Component from the Inspector
     Scroll down to New script

     Type switch_video for New script, Create and Add
     Double click the switch_video script from the Assets


Replace everything with this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class switch_video : MonoBehaviour
{
    private VideoPlayer videoPlayer;
    public VideoClip[] allClips;

    void Start()
    {
        videoPlayer = GetComponent<VideoPlayer>();
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            videoPlayer.clip = allClips[0];
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            videoPlayer.clip = allClips[1];
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            videoPlayer.clip = allClips[2];
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            videoPlayer.clip = allClips[3];
        }
    }
}



Select Video Player from the Hierarchy
Under All Clips, enter the number of clips you have (This script assumes 4, starting at 0)

Select the unity_dot button to the right of Element 0 and add your first video. repeat


Hit the Play arrow to check if everything is working.
unity_play_arrow


Publish a Player
Save your Unity Scene

File->Build Settings...
     Change Architecture to x86_64
     Click Player Settings... button
     Open Resolution and Presentation
          Change Fullscreen Mode to Exclusive Fullscreen   (default Fullscreen Window)
          Uncheck Default is Native Resolution
               Input your resolution below.
          Uncheck Mac Retina Support
          Uncheck Allow Fullscreen Switch

Open
Splash Image
     Change the Background Color to black
Close the window

Select
Build
Click New folder, make a new player folder on your desktop
     Select the folder, it will take a minute to build.

Doubleclick
the player.exe
     Alt + F4 to quit the player

(If you have problems with the build, uncheck any scenes listed Scenes in Build)

Publish Defaults
 
Resolution and presentation
     *Fullscreen Mode Fullscreen Window
     *Default is Native Resolution checked
     *Mac Retina Support checked
     Run in Background checked
     Capture Single Screen unchecked
     Display Resolution Dialogue Disabled
     Use Player Log checked
     Resizable Window unchecked
     Visible in Background checked
     *Allow Fullscreen Switch checked
     Force Single Instance unchecked
     Supported Aspect Ratios all selected


Add a script to hide the mouse cursor and add an Escape button

Select the Main Camera
Select the Add Component button
     Scroll down to New script
          Type a name: hide_cursor_escape
         Double click the C# script in your Assets folder

Add this script name it hide_cursor_escape:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class hide_cursor_escape : MonoBehaviour {

 // Use this for initialization
 void Start () {
  Cursor.visible = false;
 }
 
 // Update is called once per frame
 void Update () {
   if (Input.GetKeyDown(KeyCode.Escape)) {
   Application.Quit();
  }
 }
}



Republish your player

BUG work around
Unity sometimes resizes or changes the player window, and saves the changes to the Registry
Create a batch file to run your player on your desktop, name it RunBuildAndFocus.bat, add the following script.
Double click to start your player.

@ ECHO OFF
start "" C:\Users\%USERNAME%\Desktop\unity_player_folder\unityplayer.exe -screen-fullscreen 1 -screen-height 1200 -screen-width 1920 TIMEOUT /T 10



If you are having trouble with the window of the player, the corrupt Unity files are here:
Use Run, type regedit
delete Computer\HKEY_CURRENT_USER\Software\DefaultCompany\projectname

Scripting information:
https://docs.unity3d.com/Manual/CommandLineArguments.html