Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Fast Video Seeking

The reason why MX Player continues to playback content immediately after seeking, unlike other Android players, is because MX Player will seek to the nearest "key frame" (or I frame) instead of an exact position. These key-frames contain all of the data necessary to start playback rather than the interpolated frames which only contain data about the changes between them and the other frames around them. More info about the various frame types can be found here.

To start playback from non-keyframe position in a video, the player has to go back to the previous key frame and start decoding from there until it reaches your selected position, at which point it will resume playback. This means that sometimes playback will take a while to start, whereas at other times it will be almost instant.

If you want the speed of using nearest key-frames, but want to have a far better "seek resolution" then you may want to encode your videos with a smaller keyint option so that there is never a long time between I frames. This will also speed-up the average time it takes for a player to resume playback after exact seeking. However this will result in large file sizes so there is a balance to be maintained.

Why This Will Become More Important In The Future.

Chances are that you currently do not see an issue at all. This is because you are probably using a traditional computer with a far more powerful x86 processor than your ARM mobile device. This computer is probably playing content that is 720p or less and uses h264 video encoding. However, as we move into using higher definition content (e.g. 4k) and using HEVC/h265 encoding to keep files at a reasonable size, this issue becomes far more noticeable. This is because your CPU will have to perform many factors more work when decoding content for playback.

MPLayer and VLC

VLC appears be unable to skip/seek to key-frames. MPlayer on the other hand will use key-frames when you press the forward/backward buttons. These short-cuts will try to go ahead/backwards by 10 seconds but will use the nearest key-frame when doing so. This makes it extremely fast, especially if you have loaded the video from a RAM disk.

Unfortunately, only players that seek to exact positions (VLC/Totem) rather than key frames will currently work with HEVC content. If you know otherwise then please leave a comment.


Last updated: 16th August 2018
First published: 16th August 2018