问题
I'm writing a video processing app and need to know the actual time of each frame.
The app works fine at first when I used elapsedRealtime
To compute the time offset:
long timeOffset = java.lang.System.currentTimeMillis() - android.os.SystemClock.elapsedRealtime();
long actualTime = timestamp + timeOffset;
But when I used another device, I found some device will use uptimeMillis
for the SurfaceTexture.timestamp, so the code sould be:
long timeOffset = java.lang.System.currentTimeMillis() - android.os.SystemClock.uptimeMillis();
long actualTime = timestamp + timeOffset;
So my question is, is there any way to know which time source are the device use for SurfaceTexture?
Although I may compute the closest time source at start of app, but I think it may cause another accident that I can't know yet.
Is there any way to know that?
回答1:
MediaCodec doesn't invent the timestamps. The buffers that MediaCodec return only contain the same values for presentationTimeUs
as you pass in the presentationTimeUs
parameter to queueInputBuffer
, or when using Surface
input, is set on the input surface using eglPresentationTimeANDROID
.
So you need to check with whichever piece of code that actually produces the timestamps to know what time reference they use.
来源:https://stackoverflow.com/questions/52511236/actual-time-of-nativegettimestamp-in-surfacetexture