blog.mozbox.org

To content | To menu | To search

Tag - demo

Entries feed

Tuesday 10 March 2009

video tag and subtitles

I've written a little Javascript code that lets you add .srt subtitles to the video tag.

Subtitles are displayed on top of the video element, in an html:div. A subtitle is HTML content. That means you can include links, images, or whatever you want inside the subtitles.

Here is a demo:

Notice that links are clickables :)

You can add anything you want on top of the video, like a <canvas/> element. If pixels in the canvas are transparent or semi-transparent, you will see the video behind it.

Be creative ;)

P.S: you need Firefox 3.1/3.5: http://www.mozilla.com/en-US/firefo....

SubTitles

Wednesday 25 February 2009

video & canvas: special effects

From a <video/> element, you can play with the pixels of each frame. For example, you can replace each green pixels by a transparent one.

Here is little demo (Firefox 3.1 needed): http://www.mozbox.org/pub/green/.

42 lines of Javascript, powerful :)

If you don't have Firefox 3.1, see the Chris' screencast: http://www.0xdeadbeef.com/weblog/?p....

Friday 20 February 2009

Video, Canvas, Worker thread - A movement tracker

About User Experience, Firefox 3.1 is going to be a minor release. But about standards and performance, it's a great step forward.

Check out the new features you can use in your web page: Firefox 3.1 for developers.

I've created a little demo using the video element, canvas, DOM Workers (threads in JS) and a few Javascript 1.7/1.8 tips. It's a movement tracker. It's not perfect, but it's fun :)

Movement tracker: http://people.mozilla.com/~prouget/..., click on the Go button (Firefox3.1 needed).

How does it work ?

For each frame:

  • First, I compute the difference between the frame n and the frame n - 1 (greyscale);
  • then (in the Worker), I do a matrix convolution to detect pixel moving (you can choose between 3 kind of matrix: Sobel, Harris and Kirsch);
  • From the result, I compute the bounding box containing moving pixels (rects displayed in the video) and the centroid of the moving pixels (crosses inside the rects);
  • There is a bounding box and a centroid for the x movements (color red) and for y movements (color green);
  • The evolution of the weight of each centroid is displayed in the graph;

The arguments:

  • Threshold: when a moving pixel should be ignored;
  • Work factor: we don't need to compute the entire frame. We can reduce it;
  • Zoom factor: the resulting video is not a <video/>, but a canvas. Define the ratio between the canvas size and the original video size;
  • Sensibility: when a global movement should be ignored. Size of the bounding box;
  • Display video: display the original <video/> element;
  • Display diff: display the diff frames;

It's a really quick&dirty implementation, if I have time (or you, if you have some time), I think a good enhancement would be to implement the camshift algorithm to track objects.