Sunday, August 23, 2009

Pulling resources from the web

In the upcoming release of muvee Reveal (R15), a new function fetch-uri has been introduced to simplify the task of downloading files from the web at "make muvee time". fetch-uri takes a URL, downloads its contents and returns a temporary path of a local file containing the contents. Some uses of fetch-uri are -

  1. To download media elements at construction time for use within muvees created by your style.

  2. To load .scm libraries directly from a URL.

  3. To query services such as search engines for data based on which other fetch-uri calls can be triggered.


The example style S10000_ImageSearch ("Image Search") is a simple example of how to use fetch-uri to turn photo caption text into images using Google's image search facility. The search functionality is packaged into a module google.scm which you can import into your style (see lib/about.html).

To use the "Image Search" style, add some photos and give them caption text for which Google's image search returns one or more images. In the result muvee, you'll see images from the search results instead of the text you entered.

Sunday, August 16, 2009

Anaglyphs using "ColorWriteMask"

The upcoming release of muvee Reveal (R15) features a new primitive effect called ColorWriteMask. Using it, you can selectively render a scene to the red, green, blue or alpha channels of the display area (aka "frame buffer"). Here is an example of a red write mask -

(define red-mask
(effect "ColorWriteMask" (A)
(param "Red" 1)
(param "Green" 0)
(param "Blue" 0)
(param "Alpha" 1)))

When you apply the red-mask to a scene, only the red channel values of the frame buffer will be affected and will consist of the red channel components of the scene itself (unless you have a pixel shader that mixes up channels, that is).

We can use the ColorWriteMask to spatially separate the red and cyan color components of the scene, thereby rendering the scene as an anaglyph. The example style S10000_CubeIn3D shows you how to get this effect. The key functionality is implemented in anaglyph.scm, which you can bring into your own styles like a library using -

(load (resource "anaglyph.scm"))


Now, whip out your red-cyan 3D glasses. Here is a sample muvee made using the "Cube Twist in 3D" style -

Monday, August 10, 2009

How to overlay an image

The style example S10000_ImageOverlay shows how to overlay a simple image atop your whole muvee by modifying the definition of muvee-global-effect. The relevant part of the code is close to trivial and is reproduced here -

(define spider
(effect "PictureQuad" ()
(param "Path" (resource "spider.png"))))

(define muvee-global-effect
(layers (A)
A
spider))

With the muvee-global-effect defined as above, the muvees you create will have a giant spider spanning the whole screen ... just for kicks :P

Here are sample 4:3 and 16:9 videos of what you'll get with the above code -

4:3 version


16:9 version


Notice that the spider is presented in the correct aspect ratio in both cases even though we didn't say anything about the scaling to be performed in each case. This is because the coordinate system of the scene is setup to preserve the aspect ratio of entities placed in the scene. For a 4:3 muvee, the x coordinate spans [-4/3,4/3] and the y coordinate spans [-1,1]. Similarly for the 16:9 muvee, the x coordinate spans [-16/9,16/9] and the y coordinate spans [-1,1]. The spider image is 150x150 - i.e. it has 1:1 aspect ratio - which fits within the unit square.

Selecting different images based on output aspect ratio

Suppose you have two images frame-4by3.png and frame-16by9.png, you can select one of them based on the aspect ratio for which your muvee is being constructed ... like so -

(define ar-suffix
(if (< (fabs (- render-aspect-ratio 4/3)) 0.01)
"-4by3"
"-16by9"))

(define spider
(effect "PictureQuad" ()
(param "Path" (resource (format "frame" ar-suffix ".png")))))

The render-aspect-ratio symbol gives you the aspect ratio for which the muvee is being constructed. We use its value to pick the suffix string we need to use with "frame" in order to select the correct file. If you consistently use "-4by3" and "-16by9" as a convention, then the above suffix code can be reused to select more than one overlay image based on the render aspect ratio within your style.

Modifying an existing muvee-global-effect

If you're looking at a complex muvee-global-effect expression like
(define muvee-global-effect ....)
, you can mechanically add the overlay by first renaming the original definition to, say, muvee-global-effect-original and then adding the following new definition after the original one.

(define muvee-global-effect-original ....) ; Renamed definition.

(define muvee-global-effect
(effect-stack
(layers (A)
A
spider)
muvee-global-effect-original))