How to Use Syncbase Offsets for Relative Timing in SMIL?
Synchronized Multimedia Integration Language (SMIL) allows authors to coordinate media playback timelines declaratively using syncbases. A syncbase defines a temporal dependency where the start or end time of one media element is anchored directly to the start or end of another target element. By pairing syncbase identifiers with positive or negative offset values, authors can create dynamic, relative schedules that adapt automatically when dependent media durations or start times shift.
Understanding Syncbase Timing Syntax
A syncbase value in SMIL is assigned within the begin or
end timing attributes of an element. The syntax follows a
structured format referencing the ID of another element, an optional
sync point specifier, and an optional clock offset:
begin="[ElementID].[begin|end](+/-Clock-Value)"
- Element ID: The unique XML identifier assigned to
the referenced element (
id="targetElement"). - Sync Point: Specifies whether to synchronize with
the
beginorendboundary of the target element. If omitted, it defaults to thebeginevent of the target. - Offset (Clock-Value): A time value representing
hours, minutes, seconds, or milliseconds preceded by a
+or-operator.
Implementing Positive Offsets
A positive offset introduces a delay relative to the reference point. This approach is commonly used to create sequential chains or staggered media reveals without hardcoding absolute timestamps.
<smil xmlns="http://www.w3.org/ns/SMIL">
<body>
<par>
<!-- Target Element -->
<video id="introClip" src="intro.mp4" dur="10s" />
<!-- Begins 2.5 seconds after introClip starts -->
<audio id="backgroundMusic" src="music.mp3" begin="introClip.begin+2.5s" />
<!-- Begins 1 second after introClip finishes playing -->
<text id="credits" src="credits.html" begin="introClip.end+1s" dur="5s" />
</par>
</body>
</smil>In this structure, if introClip encounters a network
delay or if its duration is modified from 10 seconds to 15 seconds,
credits will still wait precisely 1 second after playback
completes before triggering.
Implementing Negative Offsets
A negative offset schedules an event to occur prior to a designated
syncbase boundary. While referencing an element's begin
with a negative offset may clamp the start to the parent container's
baseline if the resolved time becomes negative, applying negative
offsets to an element's end enables pre-emptive
transitions, crossfades, and preview overlays.
<smil xmlns="http://www.w3.org/ns/SMIL">
<body>
<par>
<!-- Main feature video with a defined duration -->
<video id="mainFeature" src="feature.mp4" dur="60s" />
<!-- Triggers 5 seconds before the main feature ends -->
<img id="nextUpBanner" src="banner.png" begin="mainFeature.end-5s" dur="5s" />
</par>
</body>
</smil>Best Practices and Dependency Resolution
Syncbase timing relies on a dependency graph calculated by the SMIL timing engine. When building complex synchronization logic:
- Avoid Circular Dependencies: An element cannot
depend on a syncbase that directly or indirectly references itself
(e.g.,
ElementA.begindepending onElementB.begin+2swhileElementB.begindepends onElementA.begin+1s), as this creates an unresolvable cyclic loop. - Handle Indefinite Durations: If a negative offset
targets the
endof an element whose duration is unknown, unresolved, or set toindefinite, the dependent element cannot resolve its start time until the target element actually terminates. - Use Explicit Scoping: Ensure that elements
referencing each other via syncbases exist within overlapping or
accessible timing containers (such as
<par>or<excl>) so their temporal lifecycles can interact correctly.