previous next

Chapter 8: SMIL Layout

When you stream more than one clip, you use SMIL to lay out the presentation. The layout defines where each clip appears in the RealPlayer media playback pane. Clips might appear side-by-side, for example, or stacked on top of each other. This chapter introduces you to SMIL's basic layout features. Before you create a layout, be sure to read "SMIL File Basics".

Tip: If your presentation displays one clip or a sequence of clips, you may not need to create a layout. Without defining a layout, you can stream a sequence of clips as described in Chapter 7, and create HTML page hyperlinks as explained in Chapter 6.

Setting the Media Pane Size

When you define a layout, you first create one (and only one) root-layout area, which sets the size of the RealPlayer media playback pane when the presentation starts. Because this size stays constant throughout the presentation, be sure that the root-layout area is large enough to encompass all of the clips that you plan to play at any point during the presentation.

Considerations For Setting a Root-Layout Size

Calculate the root-layout size based on the sizes of clips that play together, as well as any borders you want to add. When you select your root-layout size, keep the following in mind:

Suppose that you plan to display two clips, one 100 pixels wide and the other 200 pixels wide, side-by-side. If you want a five-pixel border around the clips, for example, the root-layout area needs to be 315 pixels wide:

Defining the Root-Layout

The <root-layout/> tag falls between <layout> and </layout> tags within the SMIL header section. The following example adds the layout section after the <meta/> tags:

<smil xmlns="http://www.w3.org/2001/SMIL20/Language"
xmlns:rn="http://features.real.com/2001/SMIL20/Extensions">
<head>
<meta name="title" content="My First SMIL File"/>
<meta name="author" content="Pat Morales"/>
<meta name="copyright" content="(c)2001 Spectacular Media Limited"/>
<layout>
<root-layout width="320" height="240"/>
...regions defined after the root-layout area...
</layout>
</head>
<body>
...clips defined here...
</body>
</smil>

The <root-layout/> tag requires height and width values in pixels. Because clips cannot play in the root-layout area, you need to define at least one playback region in addition to the root-layout area.

For More Information: See "Creating Playback Regions". "Adding Background Colors" tells how to change the color of the root-layout area.

Making Room for the Related Info Pane

When the media browser pane is attached, a SMIL presentation that plays without an HTML page for the related info pane appears centered above the media browser pane. (For an illustration of this, see "Media Playback Pane Sizing".) If an HTML page later opens in the related info pane, the SMIL presentation jumps to the left. To prevent this effect, which can be jarring for the viewer, include rn:contextWindow="openAtStart" in the <root-layout/> tag:

<root-layout width="320" height="240" rn:contextWindow="openAtStart"/>

When you use this attribute, the SMIL presentation appears at the left side of the top two panes. Any HTML pages then sent to the related info pane appear at the right side. To prevent height resizing when an HTML page appears, specify the same height for the related info pane that you use in the <root- layout/> area. The rn:contextWindow attribute has no visible effect when the media browser pane is detached.

View it now! (requirements for viewing this sample)
In RealPlayer, make sure that the media browser pane is attached. Then, play the first sample, which makes room for the related info pane when the presentation starts, placing the video flush left. The second sample does not use rn:contextWindow, so the video appears centered at first, moving to the left when the related info pane opens.

Creating Playback Regions

Every visual clip must be assigned to a region, which is a rectangular area that lays within the root-layout area. You don't necessarily have to create a separate region for each clip. When you play a sequence of clips, for example, you can assign each clip to the same region. When multiple clips play in parallel, though, define a separate region for each clip. Although similar to HTML frames, SMIL regions can overlap, letting you play a clip in one region in front of a background image in another region, for example.

SMIL Region Possibilities

SMIL Region Possibilities

Adding <region/> Tags

Just below the <root-layout/> tag, you define each region with a <region/> tag. Each <region/> tag must have a unique, user-defined ID. The following sample creates two regions that are the same size as the root-layout area. When regions overlap, the region defined first in the SMIL mark-up appears behind the region defined second, so the background region would appear behind the video region:

<layout>
<root-layout width="320" height="240"/>
<region id="background_region"/>
<region id="video_region"/>
</layout>

In the preceding sample, you could display an image clip in the background region. Then, if the video is smaller than 320-by-240 pixels, you could center it within the video region. Because region backgrounds are transparent unless you specify otherwise, the background image will display around the video.

For More Information: For more on ID values, see "Tag ID Values". "Adding Background Colors" explains how to change region colors.

Defining Region Sizes and Positions

In many cases, you'll need to specify region sizes to make them smaller than the root-layout area. This lets you play two clips side-by-side, for instance, or use the root-layout background color as a border around regions. The following figure illustrates how a region's size and position attributes control where the region appears.

Region Size and Position Attributes

Region Size and Position Attributes

The region size and position attributes constitute a simple coordinate system measured in pixels or percentages. Because each attribute has a default value of auto, you can leave it out of the <region/> tag to set its value automatically based on the values of the other attributes. The result is that, in most cases, you need to specify just one to four of the attributes listed in the following table.

Region Size and Position Attributes
Attribute Function Example
bottom Sets the region's bottom offset from pane's bottom border. bottom="22"
height Specifies the region's height. height="180"
left Sets the region's left offset from pane's left border. left="20%"
right Sets the region's right offset from pane's right border. right="5%"
top Sets the region's top offset from pane's top border. top="60"
width Specifies the region's width. width="240"

Layout Example 1: Region Width and Height

This example shows a region in which only the width and height are defined:

<region id="video_region" width="180" height="120"/>

In this case, the region is placed at the root-layout area's upper-left corner. The bottom and right offsets from the root-layout borders are set automatically based on the region's size and position. If the root-layout area were 300 pixels wide by 200 pixels high, you could achieve the same layout using percentage values:

<region id="video_region" width="60%" height="60%"/>

Tip: With percentage values, the region changes size if you modify the size of the <root-layout/> tag. With pixel measurements, though, the region size remains stable.

Layout Example 2: Four Region Offsets

This example shows a region placed in a root-layout area without specifying the region size:

<region id="video_region" left="60" right="60" top="40" bottom="40"/>

In this case, the four offsets from the root-layout borders determine the region size. If the root-layout area were 300 pixels wide by 200 pixels high, the region would be 180 pixels wide (300-60-60=180) and 120 pixels high (200-40- 40=120). You could create the same layout with percentage values:

<region id="video_region" left="20%" right="20%" top="20%" bottom="20%"/>

Tip: If you define a region size with these offset attributes, changing the root-layout area's size also changes the region's size whether the attributes use pixels or percentages.

Layout Example 3: Region Sizes and Two Offsets

This example shows a common way to define region size and position. It specifies a region width and height, then sets the region's offset from the root- layout area's upper-left corner:

<region id="video_region" left="60" top="40" width="180" height="120"/>

If the root-layout area were 300 pixels wide by 200 pixels high, the region layout would be the same as in "Layout Example 2: Four Region Offsets". Using pixel measurements for the region width and height, however, keeps the region size stable if you modify the root-layout size.

Using Different Offset Values

For this example, you could use the right and bottom attributes instead of left and top to create the same layout:

<region id="video_region" right="60" bottom="40" width="180" height="120"/>

Using Percentage Values

You could also define this layout using percentage values for the left and top offsets. This keeps the region's relative position within the root-layout area the same should you change the root-layout size:

<region id="video_region" left="20%" top="20%" width="180" height="120"/>

Layout Example 4: Two Offsets

This example sets the region's size and position by specifying only the right and bottom attributes:

<region id="video_region" right="60" bottom="40"/>

Because neither the left nor the top attribute is defined, the region is placed in the root-layout area's upper-left corner. The region's width and height expand to meet the right and bottom offset values.

Using Different Offset Values

Alternatively, you could set the region's left and top attributes instead of right and bottom to place the region at the root-layout area's lower-right corner:

<region id="video_region" left="60" top="40"/>

Layout Example 5: Single Offsets for Two Regions

Typically, you'll need to create more that one region to lay out clips that play together. To do this, you define each region with a separate <region/> tag, using any combination of size and position attributes to place each region within the root-layout area.

This example shows two regions laid out so that a small stripe of the root- layout background appears between the regions. Because vertical size or offset values (top, height, or bottom) are not specified, each region is as tall as the root-layout area:

<region id="region_1" right="55%"/>
<region id="region_2" left="55%"/>

Layout Example 6: Overlapping Regions

This example has one region in front of another, the region defined second appearing in front. There are many ways to define this layout with the size and position attributes. The following sample uses percentage values for the four border offsets:

<region id="region_1" top="5%" left="5%" bottom="5%" right="5%"/>
<region id="region_2" top="25%" left="25%" bottom="25%" right="25%"/>

Tips for Defining Region Sizes and Offsets

Adding Background Colors

By default, the <root-layout/> area has a black background. All regions are transparent. In a <root-layout/> or <region/> tag, you can specify a different background color with the backgroundColor attribute, as shown in the following example:

<layout>
<root-layout backgroundColor="maroon".../>
<region id="region1" backgroundColor="rgb(100,65,230)".../>
<region id="region2" backgroundColor="#C2EBD7".../>
<region id="region3" backgroundColor="inherit".../>
</layout>

For the color value, you can use inherit to make the region use the same color as the root-layout area. In the example above, the third region inherits maroon as its background color. To set a color value explicitly, use a predefined color name, a hexadecimal color value, or an RGB value. The following table lists the predefined names, along with that color's corresponding hexadecimal and RGB values.

white
#FFFFFF
rgb(255,255,255)
silver
#C0C0C0
rgb(192,192,192)
gray
#808080
rgb(128,128,128)
black
#000000
rgb(0,0,0)
yellow
#FFFF00
rgb(255,255,0)
fuchsia
#FF00FF
rgb(255,0,255)
red
#FF0000
rgb(255,0,0)
maroon
#800000
rgb(128,0,0)
lime
#00FF00
rgb(0,255,0)
olive
#808000
rgb(128,128,0)
green
#008000
rgb(0,128,0)
purple
#800080
rgb(128,0,128)
aqua
#00FFFF
rgb(0,255,255)
teal
#008080
rgb(0,128,128)
blue
#0000FF
rgb(0,0,255)
navy
#000080
rgb(0,0,128)

Setting When Background Colors Appear

By default, all region background colors display when the presentation starts. In some cases, you may not want a region's background color to appear until a clip plays in the region. To do this, add showBackground="whenActive" to the <region/> tag:

<region id="region1" backgroundColor="silver" showBackground="whenActive".../>

Transparency in Regions and Clips

If a clip that contains transparency (such as a GIF image) plays in a transparent region, viewers will be able see through the clip's transparent areas to underlying regions and clips. The following clip types can include transparent areas:

Helix Server can stream other types of clips, too, and some of those clips may include transparency. Support for transparency for each clip type has to be built into RealPlayer, however. Some clips that display transparency when rendered in a Web browser, for example, may not display transparency when played in RealPlayer.

Tip: To check if RealPlayer recognizes a clip's transparency, open the clip in RealPlayer and see if the pane background shows through the clip's transparent areas.

Positioning Clips in Regions

By default, a clip aligns with a region's upper-left corner and displays at its normal size. If it's too big for the region, it's cropped. If it's too small, the region's background color displays in the remainder of the region. You can modify this behavior by defining registration points in clip source tags, and adding a fit attribute to <region/> tags.

Creating Registration Points

A registration point positions a clip within a region at a point other than the region's upper-left corner. To define a registration point, you add regPoint and regAlign attributes to a clip source tag. For example, the following values center the clip in its region:

<video src="rtsp://helixserver.example.com/video1.rm" region="video_region"
regPoint="center" regAlign="center"/>

For More Information: The section "Assigning Clips to Regions" explains how the region attribute assigns a clip to a playback region.

Both the regPoint and regAlign attributes use one of nine values to align a clip within a region: topLeft, topMid, topRight, midLeft, center, midRight, bottomLeft, bottomMid, or bottomRight. The following figure illustrates where these values fall on a clip:

Alignment Values on Clips

Alignment Values on Clips

Although regAlign and regPoint both use the same alignment values, the values have different meanings for the two attributes:

For example, the next values select the region's lower-right corner, and place the clip's right midpoint at that corner. In this case, the clip's bottom half is cut off:

<ref src="rtsp://helixserver.example.com/video1.rm"
regPoint="bottomRight" regAlign="midRight"/>

Avoiding Problems When Defining Registration Points

Because you can use any of the nine predefined values for both regPoint and regAlign, there are 81 possible ways to place clips in regions. Not all possibilities are useful, though. Consider this alignment:

<ref src="..." region="..." regPoint="topLeft" regAlign="bottomRight"/>

In the preceding example, regPoint="topLeft" puts the registration point at the region's upper-left corner. The regAlign="bottomRight" attribute places the clip's lower-right corner on the registration point. This locates the clip outside the region. Because a clip cannot display outside its region, the clip does not display at all.

Using Common Registration Point Values in Clip Source Tags

The following table lists some of the more useful combinations of regPoint and regAlign that you can include in a clip source tag.

Common Registration Point Values in Clip Source Tags
Clip Placement Registration Point Values Example
top left (default) regPoint="topLeft" regAlign="topLeft"

top center regPoint="topMid" regAlign="topMid"

top right regPoint="topRight" regAlign="topRight"

middle left regPoint="midLeft" regAlign="midLeft"

center regPoint="center" regAlign="center"

middle right regPoint="midRight" regAlign="midRight"

bottom left regPoint="bottomLeft" regAlign="bottomLeft"

bottom center regPoint="bottomMid" regAlign="bottomMid"

bottom right regPoint="bottomRight" regAlign="bottomRight"

upper-left quadrant regPoint="center" regAlign="bottomRight"

upper-right quadrant regPoint="center" regAlign="bottomLeft"

lower-left quadrant regPoint="center" regAlign="topRight"

lower-right quadrant regPoint="center" regAlign="topLeft"

View it now! (requirements for viewing this sample)
Play the following sample to see the basic registration point alignments described in the preceding table.

Defining How Clips Fit Regions

Whereas a registration point determines where a clip displays in a region, a fit attribute specifies what happens when a clip is larger or smaller than its allotted area. The various fit values determine whether resizing, distortion, and cropping may occur. The fit attribute is part of a <region/> tag, and it applies to a clip played in the region whether or not the clip uses a registration point. The following example shows a fit attribute set in a <region/> tag:

<region id="video_region" width="128" height="64" fit="meet"/>

Using fit Attribute Values

The fit attribute uses one of the values described in the following table. The table's last three columns indicate if the fit attribute value may scale, distort, or crop the clip if it does not fit the region dimensions exactly.

fit Value Function Scaling? Distortion? Cropping?
fill Place the clip in the region's upper-left corner, or at the registration point. Scale the clip so that it fills the region exactly. Image distortion occurs if the encoded clip and playback region have different aspect ratios. yes yes no
hidden
(default)
Keep the clip at its encoded size, and place it in the region's upper-left corner, or at the registration point. If the clip is smaller than the region, fill the remaining space with the region's background color. If the clip is larger than the region, crop out the area that does not fit. no no yes
meet Place the clip at the region's upper-left corner or at the registration point. Scale the clip and preserve its width-to-height ratio until one dimension is equal to the region's size and the other dimension is within the region's boundaries. Fill empty space with the region's background color. yes no no
scroll Place the clip at the region's upper-left corner or at the registration point. Display the clip as its normal size, adding horizontal or vertical scroll bars if the clip extends beyond the region's boundaries. no no no
slice Place the clip at the region's upper-left corner or at the registration point. Scale the clip and preserve its width-to-height ratio until one dimension is equal to the region's size and the other dimension overflows the region's boundaries. Crop the overflow. yes no yes

The following illustration shows the effects that particular fit attribute values have on a source clip played in regions with different sizes and aspect ratios. Note that in some cases, based on the width-to-height ratio of the clip and the width-to-height ratio of the region, certain fit values have nearly the same effect. But display the same clip in a region with a different width-to-height ratio, and the fit values can have very different effects.

A Clip Played in Different Regions with Different fit Attribute Values

A Clip Played in Different Regions with Different fit Attribute Values

View it now! (requirements for viewing this sample)
This first sample lets you view how four different fit attribute values affect the same clip as it displays in the four quadrants of a region. The following samples show how the various fit values affect a clip when it displays in regions that have different sizes and aspect ratios:

fit="fill"
fit="hidden"
fit="meet"
fit="slice"
fit="scroll"

Tips for Defining the fit Attribute

Assigning Clips to Regions

After you define the playback regions, you use region attributes within clip source tags to assign visual clips to regions based on the region's ID. (Audio clips do not require playback regions.) In the following example, the video and text clips are assigned to the video and text regions defined in the header. This sample places clips in a parallel group, which the next section describes:

<smil xmlns="http://www.w3.org/2001/SMIL20/Language"
xmlns:rn="http://features.real.com/2001/SMIL20/Extensions">
<head>
<layout>
<root-layout backgroundColor="maroon" width="250" height="230"/>
<region id="video_region" top="5" left="5" width="240" height="180"/>
<region id="text_region" top="200" left="5" width="240" height="20"/>
</layout>
</head>
<body>
<par>
<video src="video.rm" region="video_region" .../>
<audio src="audio.rm"/>
<ref src="text.rt" region="text_region" .../>
</par>
</body>
</smil>

Playing Clips in Parallel

You can play two or more clips at the same time by grouping the clip source tags between <par> and </par> tags. In this case, you assign each clip to a different playback region. The following example creates a parallel group that plays a RealVideo clip along with a RealText clip in separate regions at the same time. The group ends when the longer clip in the group stops playing:

<par>
<video src="song.rm" region="video_region"/>
<ref src="lyrics.rt" region="text_region"/>
</par>

Ending a Parallel Group on a Specific Clip

By default, a <par> group ends when all clips in the group finish playing. You can modify this behavior with the endsync attribute. Suppose that a long clip of background music plays in parallel with a shorter RealText clip. Using endsync, you can stop the group when the RealText clip finishes, cutting off the background music once the text has displayed. The endsync attribute has no effect in <seq> tags or clip source tags.

Use endsync="first" in the <par> tag to stop the group when the first clip in the group stops playing. (Note that "first" refers to playback times and not the order that clips are listed in the group.) All other clips in the group stop playing at that point, regardless of their playback statuses or any timing parameters specified for them.

The attribute endsync="ID" causes the group to conclude when the designated clip ends playback. All other clips in the group stop playing at that point, regardless of their playback statuses or any timing parameters used with them. The designated clip must have a corresponding id value in its source tag, as illustrated in the following example:

<par endsync="vid1">
<video id="vid1" src="video1.rm" region="video_region"/>
<ref src="moreinfo.rt" region="text_region"/>
</par>

For More Information: For more on clip ID values, see "Tag ID Values".

Setting Clip Fills

The fill attribute, which uses three basic values of auto, remove, and freeze, is useful with clips that play in parallel groups. If a group lasts longer than a clip, use fill="remove" in the clip source tag to remove the clip when it finishes playing. A fill="freeze" value keeps the clip visible until the group completes.

In the following example, suppose that the video is longer than the RealText clip. The fill="freeze" attribute in the RealText source tag keeps the final text block visible after the clip finishes playing. The parallel group then ends with the video clip finishes playing:

<par>
<video src="song.rm" region="video_region"/>
<ref src="lyrics.rt" region="text_region" fill="freeze"/>
</par>

If you do not set the fill value explicitly, the default value of fill="auto" is used. This acts like a remove or a freeze value depending on whether timing attributes are used:

Using Images in Parallel Groups

You can stream still images, whether GIF, JPEG, or PNG, in parallel with other clips, using the images as buttons, banners, or ads, for example. Still images lack two characteristics that you find in a streaming media clip such as a video, though:

The following example shows a clip source tag for a still image. The <param/> tag sets the image's streaming speed to 5000 bits per second, or approximately 5 Kbps. Note that using <param/> requires that you turn the <img/> tag into a tag pair of <img> and </img>:

<img src="poster.jpg" region="image_region" dur="5s" fill="freeze">
<param name="bitrate" value="5000"/>
</img>

Note: You see the effects of the bitrate parameter only when streaming an image with Helix Server. The parameter does not affect local playback of clips stored on your computer. When images are on a Web server, the bitrate parameter has no effect, and the images simply download as fast as possible, which may interfere with other streaming clips playing in parallel.

Tips for Creating Parallel Groups

Defining Groups Within Groups

One of the powerful features of SMIL is the ability to nest groups, which lets you combine <seq> and <par> tags as needed to create any type of presentation. The organization of these tags greatly affects the presentation playback, though, and you need to be careful when creating nested groups. In the following example, clip 1 plays first. When it finishes, clip 2 and clip 3 play together. When both clip 2 and clip 3 have finished playing, clip 4 plays:

<seq>
clip 1
<par>
clip 2
clip 3
</par>
clip 4
</seq>

You get very different results, though, if you switch the <seq> and <par> groupings. In the next example, clips 1, 2, and 4 all begin at the same time. When clip 2 finishes, clip 3 starts:

<par>
clip 1
<seq>
clip 2
clip 3
</seq>
clip 4
</par>

The following illustration shows the difference between these groupings.

Different Playback Results with Nested Groups

Different Playback Results with Nested Groups

Layout Examples

The following sections illustrate how to use layout tags and attributes to create various types of presentations. Choose Sample Files from the pull-down menu to view all the playable sample files included in this guide.

Centering a Video on a Background

This example centers a video clip in front of an image. Because region sizes are not specified, the regions expand to the root-layout size. The registration point centers the video clip within its region. The image region's fit="fill" attribute expands the image to fill the entire region, distorting the image if the image does not have the same width-to-height ratio as the region:

<smil xmlns="http://www.w3.org/2001/SMIL20/Language"
xmlns:rn="http://features.real.com/2001/SMIL20/Extensions">
<head>
<layout>
<root-layout width="320" height="240"/>
<region id="image_region" fit="fill"/>
<region id="video_region"/>
</layout>
</head>
<body>
<par>
<img src="http://www.example.com/background.gif" region="image_region"
dur="10s" fill="freeze"/>
<video src="rtsp://helixserver.example.com/video1.rm" region="video_region"
regPoint="center" regAlign="center"/>
</par>
</body>
</smil>

Note: SMIL provides no way to tile an image throughout a region.

View it now! (requirements for viewing this sample)
Play this sample to view a video centered on a graphic image.

Displaying a Letterbox Clip

A wide screen movie displays on most television sets in a letterbox format, in which blank areas display above and below the movie. As shown in the following example, you can achieve the same effect for a clip that has a width- to-height ratio greater than its region's. Here, the video uses a registration point that centers it in a region that uses fit="meet" to scale the video up or down in size until its left and right edges meet the region boundaries:

<smil xmlns="http://www.w3.org/2001/SMIL20/Language"
xmlns:rn="http://features.real.com/2001/SMIL20/Extensions">
<head>
<layout>
<root-layout width="400" height="300"/>
<region id="video_region" fit="meet"/>
</layout>
</head>
<body>
<video src="rtsp://helixserver.example.com/widescreen.rm"
region="video_region" regPoint="center" regAlign="center"/>
</body>
</smil>

View it now! (requirements for viewing this sample)
This sample demonstrates the letterbox effect using a RealText clip.

Playing Three Clips Side-by-Side

The following example displays three regions: a news region, a video region, and a stock ticker region. The news and video regions are arranged side-by-side at the top of the RealPlayer media playback pane. The stock ticker region appears below them. The video uses a begin attribute to start it playing 15 seconds after the other clips have started.

<smil xmlns="http://www.w3.org/2001/SMIL20/Language"
xmlns:rn="http://features.real.com/2001/SMIL20/Extensions">
<head>
<layout>
<root-layout height="230" width="510" backgroundColor="black"/>
<region id="news_region" width="240" height="180" left="5" top="5"/>
<region id="video_region" width="240" height="180" right="5" top="5"/>
<region id="ticker_region" width="500" height="30" left="5" bottom="5"/>
</layout>
</head>
<body>
<par>
<ref src="rtsp://helixserver.example.com/news.rt" region="news_region"
fill="freeze"/>
<video src="rtsp://helixserver.example.com/video1.rm" region="video_region"
fill="freeze" begin="15s"/>
<ref src="rtsp://helixserver.example.com/ticker.rt" region="ticker_region"
fill="freeze"/>
</par>
</body>
</smil>

View it now! (requirements for viewing this sample)
Click this sample to view three clips played side-by- side.

Using Advanced Layout Features

SMIL 2.0 has even more layout features than those described in this chapter. If you download RealNetworks Production Guide from http://service.real.com/help/library/encoders.html, you'll find instructions for doing the following:


RealNetworks, Inc. ©2002, 2004 RealNetworks, Inc. All rights reserved.
For more information, visit RealNetworks
Click here if the Table of Contents frame is not visible at the left side of your screen.
previous next