Comments (6)
Hi,
Currently we don't really have a system for this. There might be a few ways you can try though.
On some platforms (like Windows) you can retrieve the timestamp of the texture. This is more accurate than querying the mediaPlayer for it's time, as the mediaPlayer time is the time is decoding but not the frame you're about to display.
long time = mediaPlayer.TextureProducer.GetTextureTimeStamp();
This 64-bit value is returned in HNS format (hundreds of nanoseconds), so you might want to convert it to seconds or frames:
double seconds = time / 10000000.0;
float frameRate = mediaPlayer.Info.GetVideoFrameRate();
int frame = Helper.ConvertTimeSecondsToFrame((float)seconds, frameRate);
You then have an accurate way to update your animation to the correct frame.
Also a good idea when you need to sync a video to something is for the video to be encoded in a way that is very fast to seek randomly. For this you need a video with lots of key-frames. Ideally each frame should be a key-frame. See the PDF documentation where we have a whole section on seeking and key-frames.
from unityplugin-avprovideo.
The technique works perfectly on Windows with GetTextureTimeStamp(). Unfortunately, on Android the results remain too inconsistent to be useable.
Part of the problem is that on Android the timestamp does not start at 0 for frame 0. Instead it seems to be time of day or some such. I'm not choosing the exactly correct moment to store the timestamp. It's not entirely clear how to go about it; I tried storing the first reported number above zero, but that was off by 35-37 frames. Then I tried storing it based on when GetCurrentTimeMs() is zero, which ends up being off by 0-2 frames. I also tried using MediaPlayerEvent.EventType.FirstFrameReady to set the initial timestep, which again was off by 35-37 frames. And that range changes as the video plays so I go out of sync. Generally it does not seem to be more reliable timing than just using GetCurrentTimeMs().
On Android you can change the video API, but results were the same with MediaPlayer and ExoPlayer, except that with MediaPlayer the 35-37 frame gap became 4-5 frames.
from unityplugin-avprovideo.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from unityplugin-avprovideo.
This issue has been automatically closed because it has not had recent activity. If you wish to continue this issue, then please create a new issue as we do not monitor closed issues.
from unityplugin-avprovideo.
I found a workaround by storing frame information in the video and reading it out of a shader, but it's inconvenient and leaves artifacts in the video. So I'm hoping the new Android version will work better for this use case.
from unityplugin-avprovideo.
In version 2.x we have improved the time precision and frames have an accurate timestamp. There is always latency though when asking for a video frame, so to keep them in sync you could either buffer decoded frames and then select the one with the matching timestamp, or you could wait/block while the decoder is processing the requested frame and poll for it in a loop with some sane timeout value.
Closing this as there's nothing we can do to improve this
from unityplugin-avprovideo.
Related Issues (20)
- Type or Namespace does not exist HOT 1
- [Bug] v3 Android play video crash. HOT 4
- Can't build with Firebase HOT 9
- Can I have the video display in gamma color space while Unity project is in linear color space HOT 2
- Changing volume does not affect sound on Android platform HOT 3
- Audio Capture Buffer always flushing HOT 3
- Why UnityEditor window is focused when start playing video with meta XR Simulator. HOT 1
- [Android][Oculus] OES shaders do not work in Release builds with "Low Overhead Mode (GLES)" enabled HOT 10
- [Android] 4K video is upside down using OES fast path HOT 11
- AVPro Video v3 has problem(screen kept flickering) on (2017.4.23f1 & 2018.4.31f1) HOT 3
- Does AvProVideo Will Support HarmonyOS? HOT 1
- MediaPlayer.Info.IsPlaybackStalled() doesn't work on Android HOT 1
- AVPro Video doesnt work on Google Chromecast with Google TV HOT 1
- [Android] When playing multiple videos in the scene, a crash occurs intermittently with the log below. HOT 6
- AVProMedia Player Compatibility with MIUI Platform HOT 5
- The issue with GetMatrixForOrientation. HOT 11
- Vision OS, DD+JOC Audio Play Issue HOT 2
- Small videos freezing HOT 23
- [Android] The orientation while playing portrait video on android is incorrect HOT 3
- [iOS] Facing crashes on iOS 12 and iPadOS 12 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unityplugin-avprovideo.