Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ExoPlayer - Get current frame number from video

I'm developing an Android video app where I need to get the current frame number of the video being displayed while in pause mode.

I need to send my Server the frame number currently paused in video and get back a list of items regarding that frame/time, right now I'm sending the current paused time in milliseconds, but it doesn't work quite well, because the Server compare the time sent to a specific frame it calculated, based on the time, but sometimes the comparison is not exact.

I know you can get a bitmap from that frame if you use MediaMetaDataRetriever, and I did it but it returns bitmap image and what I need is an index. I'm using ExoPlayer (I need that feature for MP4 and for HLS, too, if that matters).

Is there a way to get that info from the video?

like image 999
Gilad Eshkoli Avatar asked Nov 10 '15 09:11

Gilad Eshkoli


1 Answers

I post a solution to my problem, In order to get the exact frame time I simply extended MediaCodecVideoTrackRenderer.java class from ExoPlayer library and used the value of lastOutputBufferTimestamp which is in function:

@Override
protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs,
                                      MediaCodec codec, ByteBuffer buffer, MediaCodec.BufferInfo bufferInfo, int bufferIndex,
                                      boolean shouldSkip) {
    boolean processed = super.processOutputBuffer(positionUs, elapsedRealtimeUs, codec, buffer,
            bufferInfo, bufferIndex, shouldSkip);
    if (!shouldSkip && processed) {
        lastOutputBufferTimestamp = bufferInfo.presentationTimeUs;
    }
    return processed;
}

It does give me the exact time and not a rounded time from, last say, mPlayer.getDuration() or something like that. If you have a constant FPS in your video you can calculate that by division and get the number of the frame. It was simply enough for me to know the exact frame time.

I'm using ExoPlayer version r1.5.3 so I don't know if this solution will work for newer version since code has probably changed.

like image 110
Gilad Eshkoli Avatar answered Oct 19 '22 18:10

Gilad Eshkoli