UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

optimization

[AVPro] Achieve Stutter-Free Seamless Video Looping on Windows

Solution

video playbackplugin configurationmedia integrationvideo player

Unity 2021.x - Unity 6.3.x

Published Fri, May 1

Issue

 Dynamically loading video from StreamingAssets on Windows often results in visible stutters or frame drops at the loop point. Traditional methods like Seek() logic or cross-fading via two MediaPlayer components fail to provide a frame-perfect transition, especially with high-resolution source files.

Explanation

Seamless video looping on a Windows build is achieved using the AVPro Video plugin by leveraging the native playback path and optimized encoding.

  1. Integrate the AVPro Video plugin and add a MediaPlayer component to your script.
  2. Set the Video Pipeline to Media Foundation in the MediaPlayer inspector to utilize native Windows hardware acceleration.
  3. Enable the Loop toggle and ensure the Auto Play is configured if necessary.
  4. Encode source files to HEVC (H.265) using FFMPEG to minimize the I-frame interval, which reduces the seek time for the MediaPlayer.

Additional Tips

  • Use the Hap codec if file size is not a concern, as it is designed specifically for high-performance looping.
  • Ensure that the StreamingAssets path is referenced correctly using Application.streamingAssetsPath.
  • Use QueueEvent to handle logic specifically when the MediaPlayer reaches the end of the file.

TL;DR

Achieve frame-perfect looping by utilizing native Media Foundation pipelines and HEVC encoding within the MediaPlayer.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.