3

When I have a HTML5 video object, I can set its currentTime property to jump (seek) to a specific time position.

Is there also a way to jump or seek to a specific frame number?

Or related: is there a way for a paused video to step or skip to the next or previous frame?
I mean when it's currently paused or freezes at some arbitrary position, cause the video to jump to the succeeding or preceding frame.

RocketNuts
  • 9,958
  • 11
  • 47
  • 88
  • What if it's not a key frame? – Kaiido Dec 28 '20 at 10:02
  • @Kaiido then I'd guess the decoder should get the last preceiding keyframe and internally do a quick render or playback or something, in order to generate the requested frame index. Either way, the same as when jumping to an arbitrary time position where there's no keyframe. – RocketNuts Dec 28 '20 at 10:06
  • For the "related" part, Firefox has a [`seekToNextFrame`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seekToNextFrame) non-standard method. – Kaiido Dec 28 '20 at 10:14
  • @Kaiido oh thanks! Although not universally available (it doesn't work in Chrome or Brave) the `seekToNextFrame` method works fine in my Firefox. I realize it's an unofficial feature but for my use case it definitely comes in handy – RocketNuts Dec 28 '20 at 10:20

1 Answers1

2

As mentioned in the comments, and AFAIK, there is no standard defined to support frame accurate seeking for the HTML5 video tag itself, other than the mentioned 'seekToNextFrame' which is not widely supported as you can see here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/seekToNextFrame

There are commercial Javascript HTMl5 players which provide this functionality - e.g.:

You'll also find discussion on this topic in the open source Shaka player discussion groups.

The reason it is not straightforward is that it usually requires the player or the browser (or something client side) to first find the nearest 'I' frame and then to decode forwards and/or backwards from that to get to the exact frame you want. It's certainly technically possible, as proven by the above example implementations, but I would guess there has not been the demand in the browser or open source player community to prioritise this functionality.

Mick
  • 24,231
  • 1
  • 54
  • 120
  • A couple of other players to consider: - https://videogorillas.com/player - https://allensarkisyan.github.io/VideoFrameDocs/ (open-source, but abandoned) – emveeoh Jan 08 '21 at 13:54