Download Development 4.8kb Download Minified 3.5kb
Fork VideoFrame on GitHub

VideoFrame: HTML5 Video SMPTE Time Code capturing and Frame Seeking API

VideoFrame is a revolutionary open source JavaScript API built for working with the HTML5 Video Element in SMPTE time codes and individual video key frames. VideoFrame can be used in many scenarios but primarily for:

  • Frame/SMPTE time code capturing
  • Frame accurate seeking
  • SMPTE time code to frame conversion and vice-versa
  • SMPTE time code to milliseconds / seconds conversion
  • Triggering events at a certain frame / time code
Shortcuts

SMPTE Time Code Conversion Methods

SMPTE Time code to Milliseconds, Seconds, and Frames conversion.
Frame number to SMPTE Time code conversion.

© 2013 Allen Sarkisyan - Released under the Open Source MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, and/or distribute copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  • The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  • Attribution must be credited to the original authors in derivative works.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

VideoFrame Configuration: One step, and your rolling.

The configuration object accepts two properties and a callback function.

id defines the video element;
frameRate defines the frame rate of the video source being played.
callback defines a callback function that is called when a frame is captured.

var video = VideoFrame({
    id: 'videoPlayer',
    frameRate: FrameRates.film,
    callback: function(response) {
        console.log(response);
    }
});

You may also initiate VideoFrame without a configuration object if you are certain you have a HTML5 video element on the page, and the video source frame rate is 24fps.

var video = VideoFrame();

Properties

The FrameRates Object

The industry standard video frame rates are defined here, these properties are also available with the fps object after the video has been defined.

var FrameRates = {
    film: 24,
    NTSC : 29.97,
    NTSC_Film: 23.98,
    NTSC_HD : 59.94,
    PAL: 25,
    PAL_HD: 50,
    web: 30,
    high: 60
};

Methods

get

Retrieves the current frame number of the playing source.

var frame = video.get();

toSMPTE

Returns the current time with frame count in the SMPTE time code format hh:mm:ss:ff
Optional: Accepts a frame number for conversion to it's equivalent SMPTE time code.

var SMPTE = video.toSMPTE();

// @param frame Number - Optional: Frame number to convert to equivalent SMPTE time code.
var SMPTE = video.toSMPTE(108); // Returns 00:00:04:12

seekForward

Seeks forward the amount of frames declared by the frames parameter.
Defaults to 1 frame.

// @param frames Number - Optional: Number of frames to seek forward.
// @param callback Function - Optional: a callback function to invoke.

video.seekForward(frames, callback);

seekBackward

Seeks backward the amount of frames declared by the frames parameter.
Defaults to 1 frame.

// @param frames Number - Optional: Number of frames to seek backward.
// @param callback Function - Optional: a callback function to invoke.

video.seekBackward(frames, callback);

toTime

Returns the current time value in hh:mm:ss format.

var time = video.toTime();

toSeconds

Returns the current time value in seconds
Optional: Accepts a SMPTE time code for conversion to seconds.

var seconds = video.toSeconds();

// Convert a SMPTE time code to seconds
// @param SMPTE String - Accepted: a SMPTE Time Code E.G. (01:12:33:11)
var SMPTE = '01:12:33:11'; // SMPTE Time Code at 24fps
var seconds = video.toSeconds(SMPTE); // 4353

toMilliseconds

Returns the current time value in milliseconds
Optional: Accepts a SMPTE time code for conversion to milliseconds.

var milliseconds = video.toMilliseconds();

// Convert a SMPTE time code to milliseconds
// @param SMPTE String - Accepted: a SMPTE Time Code E.G. (01:12:33:11)
var SMPTE = '01:12:33:11'; // SMPTE Time Code at 24fps
var milliseconds = video.toMilliseconds(SMPTE); // 4353458

toFrames

Returns the frame count from a SMPTE time code.

var frames = video.toFrames();

// Convert a SMPTE time code to frames
// @param SMPTE String - Accepted: a SMPTE Time Code E.G. (01:12:33:11)
var SMPTE = '01:12:33:11'; // SMPTE Time Code at 24fps
var frames = video.toFrames(SMPTE); // 104483

listen

The listen method requires the format parameter values include: (SMPTE, time, frame), the tick argument over rides the default interval set by the frame rate of the video.

// @param format String - Accepted: 'SMPTE', 'time', 'frame'
// @param tick Number - Over rides the default interval set by the frame rate of the video.
video.listen(format, tick);

stopListen

Clears the interval set by the listen method.

video.stopListen();