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

Can't activate more Mediaplayers after about 15 #1889

Closed rcwongtk closed 2 weeks ago

rcwongtk commented 3 weeks ago

Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE

Describe the issue I am working on an AR application that overlays videos on images. Each image has it's own mediaplayer, and it works perfectly until about the 17th image. After that, new mediaplayers simply won't start.

Only one mediaplayer is active at a time, so anytime an image is activated the other mediaplayers are deactivated. I am assuming this means that somehow the mediaplayers are still storing some sort of memory that is accumulating over time.

Any thoughts on how to resolve this?

Your Setup (please complete the following information):

To Reproduce

  1. Create 20 Mediaplayers with different videos and associated meshes
  2. Turn one on, play the video, turn it off
  3. After about 15-18 the next Mediaplayers will not start up.

Logs If applicable, add error logs to help explain your problem.

Screenshots If applicable, add screenshots to help explain your problem.

Videos If applicable, add a copy of your video or the URL

Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE

Instead email the link to us unitysupport@renderheads.com

MorrisRH commented 3 weeks ago

Each media player instance will require hardware resources which are limited and will eventually run out which is why you're seeing things stop working. The decoder resources and texture memory required will be based on the resolution and frame rate of the video being decoded so you could look to use smaller videos to try and increase the number of active media players you can use.

If the videos are short (10s or less) then you could look to using the HAP codec (windows only) which doesn't require GPU decoding resources.

You mention only one video is ever playing at a time so I would recommend using just a few players and having the next video to play queued up ready to go and swapping between them as necessary.

rcwongtk commented 3 weeks ago

Thanks for the quick response Morris! I like the idea of using just a few players and having things queued up.

Right now, my videos only download when a certain event is triggered. Is there a way to change the URL value of the Mediasource without modifying the MediaPlayer or Interfaces component directly? Might just use one player and have the URL change during the event.

Also, if I decided to stick with multiple MediaPlayers would there be a way for me to "unload" the resources of a video when the next one plays? Typical users will only watch the video once, so thinking this could also be a potential solution.

Thanks again, appreciate the support!

MorrisRH commented 2 weeks ago

You can all mediaPlayer.OpenMedia() with a new URL, all the existing player set-up will remain in place. Calling mediaPlayer.Close() will release resources currently allocated to a player.