RenderHeads / UnityPlugin-AVProVideo

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

Incorrect current frame number on Android when using MediaPlayer API #1234

Closed artoonie closed 2 years ago

artoonie commented 2 years ago

Describe the issue GetCurrentTimeFrames always returns 0 on Android, which also causes SeekToFrameRelative to fail.

Your Setup (please complete the following information):

To Reproduce While the video is playing or paused, m_MediaPlayer.Control.GetCurrentTimeFrames always returns 0

Workaround Use m_MediaPlayer.Control.GetCurrentTime() * m_MediaPlayer.Info.GetVideoFrameRate(), which is not accurate but is a fine approximation.

Chris-RH commented 2 years ago

Hi @artoonie, What code are you using? Are you using the workarounds as a straight replacement?

AndrewRH commented 2 years ago

That's strange... GetCurrentTimeFrames() basically does the same thing, ie GetCurrentTime() * GetVideoFrameRate() but with some nuances to make it accurate... so I'm not sure why it's not working for you...

artoonie commented 2 years ago

It is possible that GetVideoFrameRate is 0 when paused - let me test more and let you know what I find.

I ended up not using the workaround above - I need to SeekToFrameRelative(3) to step forward, so I'm using Seek(currentTime + 0.1f) now which does work fine.

artoonie commented 2 years ago

I've taken a closer look, the underlying issue seems to be that MediaPlayer.Info.GetVideoFrameRate() is returning 0, so my workaround above does not work. (I had a different method of getting the framerate.)

Do you need an example video that has this 0fps framerate?

Ste-RH commented 2 years ago

Do you need an example video that has this 0fps framerate?

Yes please. Also. Are you using the ExoPlayer or MediaPlayer API path?

artoonie commented 2 years ago

I'm using MediaPlayer, not ExoPlayer.

Here is an example video (I can send a longer one if needed). It was generated from AVProMovieCapture (Android Beta 9, I believe). https://user-images.githubusercontent.com/537316/179601503-e4e31e63-1399-40a1-9f4c-334cbc966f40.mp4

Ste-RH commented 2 years ago

Ahh, MediaPlayer. Yeah, oki. That makes sense now.

There are a number of methods to obtain the video encoded framerate, and it appears the 'more optimal' method is not 100% reliable. I will revert back to the method that appears to be a bit better. Expect this change in v2.5.6 which we hope to release this week.

Of course, if you were to switch to using the ExoPlayer API path then this would all work as you expect. Is there a reason you are not using ExoPlayer?

Ste-RH commented 2 years ago

Bit of additional.

The Android MediaPlayer APIs return the frame rate as an integer value, and ExoPlayer reports it back as a float. For your video I get 30 from MediaPlayer, and 30.22109 from ExoPlayer. This will potentially result in an incorrect 'current frame' value. If you can use ExoPlayer, I would.

artoonie commented 2 years ago

I have in my notes that ExoPlayer was braking one of my shaders, but I'm not sure which - I tried to reproduce, but I'm getting AndroidJavaException: java.lang.NoClassDefFoundError: com.google.android.exoplr2avp.audio.AudioCapabilities. I'm sure I could work through each of these issues, but MediaPlayer works out-of-the-box for me.

Ste-RH commented 2 years ago

Better MediaPlayer source video framerate support coming in v2.5.6. Hope to get this released tomorrow.

AndrewRH commented 2 years ago

I have in my notes that ExoPlayer was braking one of my shaders, but I'm not sure which - I tried to reproduce, but I'm getting AndroidJavaException: java.lang.NoClassDefFoundError: com.google.android.exoplr2avp.audio.AudioCapabilities. I'm sure I could work through each of these issues, but MediaPlayer works out-of-the-box for me.

That sounds like a different issue - perhaps you could open a new issue with details about this. Also you could try disabling any stripping/proguard options in Unity player settings.

Thanks,

artoonie commented 2 years ago

Yes, definitely a separate issue - I don't have time to deeply investigate now, since I have an easy workaround, but let me know if you'd like me to investigate that and create a proper bug report for it. Otherwise, the 2.5.6 framerate fix will work for my needs. Thanks!

Chris-RH commented 2 years ago

Version 2.5.6 has been released, please let us know if this has solved your problem.

Chris-RH commented 2 years ago

Please reopen if this is still an issue