Jump to content

Movie Player: Difference between revisions

From OpenBOR
No edit summary
Update to hardware acceleration.
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
OpenBOR provides a reusable source, playback, and channel system for movie media. The API uses the generic <code>movie_*</code> namespace so additional container or codec support can be added later. The current backend plays WebM files containing VP8 video and optional Vorbis audio.
== Introduction ==


The movie system has three main parts:
OpenBOR plays WebM movies containing VP8 video and optional Vorbis audio. Movies can supply cinematics, animated interfaces, video surfaces, picture-in-picture layouts, or the main content of a module.


* '''Source''' - A streamed path or cached WebM byte buffer identified by a source ID.
The movie system separates playback from drawing. Video and audio decoding run asynchronously on the CPU. The GPU samples the decoded video planes, converts their YUV colors to RGB, and renders the result. Scripts decide when and where to draw the retained frame while the movie channel manages position, pause, speed, repeat, and audio.
* '''Playback''' - One active use of a source, represented by a stable playback object pointer.
* '''Movie channel''' - One of 64 fixed slots that owns playback, timing, decoding, composition, and sound-routing state.


Keeping these concepts separate is important. One source may be played several times, each playback has independent state, and movie channels are separate from the sound channels used by embedded audio.
Both <code>movie_draw_to_screen()</code> and <code>movie_draw_to_yuv()</code> use GPU rendering. Their difference is the destination: an OpenBOR screen for composition, or the display for direct presentation.


== Formats ==
== Choosing a drawing destination ==


{| class="wikitable"
{| class="wikitable"
! Component
! Feature !! Screen composition !! Direct display
! Current support
|-
! Notes
| Function || <code>movie_draw_to_screen(screen, channel)</code> || <code>movie_draw_to_yuv(channel)</code>
|-
| Destination || Main virtual screen or a creator-owned subscreen. || Display window.
|-
| Rendering || GPU video sampling, YUV-to-RGB conversion, scaling, and drawing. || GPU video sampling, YUV-to-RGB conversion, scaling, and presentation.
|-
|-
| Container
| Placement || Movie dimensions and signed destination offsets, clipped to the screen. || Centered presentation using logical display dimensions and the display's stretch setting.
| WebM
| The supplied path is used exactly. Movie loading does not append an extension.
|-
|-
| Video
| Composition || Combine movies with sprites, text, effects, and other screen content. || Present one movie frame directly. Each call replaces the displayed window content.
| VP8
| Video track required. Stereoscopic WebM modes are not supported.
|-
|-
| Audio
| Image controls || Movie resampling and exact-black protection. Apply drawmethod effects when drawing the resulting screen. || Movie resampling and display brightness/gamma correction.
| Optional Vorbis, mono or stereo
| Embedded audio is decoded to 16-bit PCM and routed through an ordinary OpenBOR sound channel. Sample rates from 11.025 through 48 kHz are recommended.
|-
|-
| Composition
| Typical use || Video surfaces, captions, interfaces, multiple views, and layered scenes. || Full-window movie playback controlled directly by a script or scene.
| 32-bit RGB
| Frames may fill the main screen or be copied into a creator-owned 32-bit subscreen.
|}
|}


Source video dimensions must be at least 2 by 2, even on both axes, and small enough for the 32-bit screen renderer to represent safely. Compatibility is checked when <code>movie_play()</code> opens the decoder. Successful <code>movie_load()</code> calls only prove that the source path could be opened or cached.
Drawing uses the channel's retained frame. It does not advance playback or request a separate decode. One retained frame may be drawn repeatedly, sent to several screens, or shown through either drawing function. The renderer reuses its uploaded video planes until playback supplies another frame.


Movie functions remain visible on builds compiled without WebM support. Such builds report that movie playback is unavailable and return an empty value instead of opening media.
== Formats ==
 
== Streamed and cached sources ==
 
<code>movie_load()</code> accepts a loading-mode constant.


{| class="wikitable"
{| class="wikitable"
! Mode
! Component !! Format
! Constant
! Load behavior
! Playback behavior
! Best use
|-
|-
| Streamed
| Container || WebM. Supply the complete module path, including its extension.
| <code>MOVIE_LOADING_STREAM</code>
| Copies the path and confirms that the file can be opened.
| Each playback opens an independent packfile position and decoder.
| Long movies, one-time scenes, and memory-sensitive projects.
|-
|-
| Cached
| Video || VP8. Use even frame dimensions of at least 2 by 2 pixels. The video track must use a non-stereoscopic mode.
| <code>MOVIE_LOADING_CACHE</code>
|-
| Reads the complete compressed WebM file into memory once.
| Embedded audio || Optional Vorbis, mono or stereo. The engine's music sample-rate range is 11,025 through 48,000 Hz.
| Each playback reads the shared read-only buffer but still owns an independent decoder and frame queues.
|-
| Short clips, repeated playback, and seek-heavy controls when sufficient RAM is available.
| Screen destination || 32-bit OpenBOR screen, including screens created with <code>allocscreen()</code>.
|}
|}


Cached mode is a '''compressed source cache''', not a decoded frame cache. It removes repeated storage reads but does not remove VP8 or Vorbis decoding cost.
The decoder selects the first video track and first audio track. Unsupported video or audio codecs reject playback when the decoder opens. If initialization of a supported optional Vorbis track fails, video may continue silently with the reason recorded in the engine log.


Source storage grows dynamically from an initial capacity of 64 records. Source IDs are assigned in ascending order and are not reused during the session. Loading the same path more than once creates another source ID; OpenBOR does not merge duplicate movie-load requests automatically.
Loading checks that source data can be opened or cached. Codec and track validation takes place when playback opens asynchronously, so a loaded source can still report a playback-opening error.


One source can back several simultaneous playbacks. Cached playbacks share the source bytes, while every playback retains independent position, speed, repeat, screen, movie channel, and sound channel state.
== Sources, playback, and channels ==


== Movie channels ==
Three identifiers serve different purposes:


OpenBOR exposes one bank of 64 movie channels numbered <code>0</code> through <code>63</code>.
{| class="wikitable"
! Item !! Returned by !! Purpose
|-
| Source ID || <code>movie_load()</code> || Identifies a reusable streamed file or cached compressed file.
|-
| Playback object || <code>movie_play()</code> || Provides property access and playback control for a movie channel.
|-
| Movie channel index || <code>movie_get_channel_index()</code> || Selects the movie used by either drawing function.
|}


* Automatic playback selects the lowest inactive movie channel.
Movie channels are numbered 0 through 63. <code>MOVIE_CHANNEL_COUNT</code> provides the channel count, and <code>MOVIE_CHANNEL_AUTO</code> requests automatic selection. Automatic selection takes the lowest inactive channel and reports an error when every channel is active. Selecting an explicit index replaces playback on that channel.
* Automatic playback fails when all 64 channels are active.
* Explicit channel selection forces playback onto that slot and stops its previous occupant.
* Stopped or completed playback immediately releases its source reference and marks the channel inactive.
* The 64-bit active mask allows OpenBOR and scripts to skip inactive channels.
* Channel objects remain structurally stable until movie shutdown, even while their playback state is replaced or reset.


Movie channels have no priority system. Explicit selection is a forced replacement. The public constant <code>MOVIE_CHANNEL_COUNT</code> reports the current capacity of 64.
The playback pointer identifies an engine-owned channel object. Its address remains stable while the movie system is running, including when the channel is inactive. Reusing the channel replaces its playback state. Coordinate channel ownership between scripts, and use <code>MOVIE_PROPERTY_ACTIVE</code> to check whether a channel is playing. Release playback with <code>movie_stop()</code>; the engine manages the channel object's storage.


=== Practical limits ===
Source storage is separate from the 64-channel playback bank and grows as sources are loaded. Source IDs increase during the session and are not reassigned after unloading. Loading the same path twice creates two source IDs. One source may be played on several channels, with independent timing, presentation settings, and audio routing.


The 64-channel capacity provides consistency and creative headroom, not a realistic expectation of 64 simultaneous decoders. Every active movie may own demux, video-decoder, audio-decoder, packet-queue, frame-queue, conversion, scaling, and sound-stream resources. Available CPU time, memory bandwidth, storage speed, resolution, frame rate, and target hardware establish the practical limit.
== Loading modes ==
 
Most projects should expect one or two simultaneous movies to be a substantial workload. The fixed channel bank prevents an arbitrary API ceiling from becoming the first limitation.
 
== Playback defaults ==
 
Every successful <code>movie_play()</code> begins with the following state:


{| class="wikitable"
{| class="wikitable"
! Setting
! Constant !! Source storage !! Use
! Default
! Behavior
|-
| Movie channel
| Automatic
| Uses the lowest inactive movie channel unless a channel is supplied.
|-
| Screen
| <code>NULL()</code>
| Renders over the main screen at the presentation stage.
|-
| Width and height
| <code>0</code>, <code>0</code>
| Each zero dimension adopts the corresponding destination-screen dimension.
|-
| X and Y offset
| <code>0</code>, <code>0</code>
| Places the prepared frame at the destination origin.
|-
| Speed
| <code>1.0</code>
| Normal forward playback.
|-
| Paused
| <code>0</code>
| Playback clock and decoding advance normally.
|-
| Repeat
| <code>0</code>
| Stops when the movie reaches its terminal frame.
|-
|-
| Interrupt
| <code>MOVIE_LOADING_STREAM</code> || Retains the file path. Each playback opens its own file position and decoder. || Playback that reads its compressed data from the module as needed. This is the default.
| <code>1</code>
| Normal movie-skip input stops playback.
|-
|-
| Black filter
| <code>MOVIE_LOADING_CACHE</code> || Reads the complete compressed file into a shared source buffer. || Reusing a clip or avoiding repeated reads of its compressed data.
| <code>0</code>
| Exact RGB black remains unchanged.
|-
|-
| Sound channel
| <code>MOVIE_LOADING_AUTO</code> || Chooses cached or streamed storage using the engine's source-cache policy. || Automatic storage selection.
| <code>0</code>
| Embedded Vorbis audio uses conventional music and media space.
|}
|}
Cached storage contains the compressed WebM file. Each playback still owns its decoder, frame queues, position, and controls.
Automatic selection uses an aggregate movie-cache budget of one quarter of total system memory and preserves a reserve of at least one eighth of total memory or 128 MiB, whichever is greater. If a cache allocation cannot be satisfied, automatic mode can use streaming. Explicit cache mode reports a failed load. Open or size-validation failures fail loading. During caching, read errors fail the load instead of selecting streaming.


== Script playback ==
== Script playback ==
Line 140: Line 87:
=== movie_load() ===
=== movie_load() ===


Loads a reusable movie source and returns its integer source ID.
<syntaxhighlight lang="text">
movie_load(path [, loading])
</syntaxhighlight>


    int source_id = movie_load(
Returns an integer source ID. <code>path</code> is the exact module path; OpenBOR does not append an extension. Omitting <code>loading</code> selects <code>MOVIE_LOADING_STREAM</code>.
        string path,
 
        int loading
<syntaxhighlight lang="c" line="1">
    );
int source_id = movie_load(
    "data/scenes/intro.webm",
    openborconstant("MOVIE_LOADING_AUTO")
);
</syntaxhighlight>


{| class="wikitable"
Source ID 0 is valid. Invalid paths, empty files, invalid loading modes, and failed source allocations report script errors.
! Argument
! Required
! Default
! Description
|-
| <code>path</code>
| Yes
| None
| Exact module path to a WebM source.
|-
| <code>loading</code>
| No
| <code>MOVIE_LOADING_STREAM</code>
| <code>MOVIE_LOADING_STREAM</code> or <code>MOVIE_LOADING_CACHE</code>.
|}


Invalid paths, loading modes, allocation failures, or empty cached files fail with a script error.
=== movie_play() ===


=== movie_unload() ===
<syntaxhighlight lang="text">
movie_play(source_id [, movie_channel])
</syntaxhighlight>


Releases a loaded source.
Returns the playback object for the acquired movie channel. Omit the second argument, pass <code>NULL()</code>, or use <code>MOVIE_CHANNEL_AUTO</code> for automatic selection.


    movie_unload(int source_id);
<syntaxhighlight lang="c" line="1">
void playback = movie_play(source_id);
int channel = movie_get_channel_index(playback);


The source must exist and have no active playback references. Stop every playback using the source before unloading it. Unloaded IDs remain invalid and are not reassigned later in the session.
// Select a particular movie channel.
void another_playback = movie_play(source_id, 5);
</syntaxhighlight>


=== movie_play() ===
Every start restores the channel's default properties. Configure the returned playback object after calling <code>movie_play()</code>.


Starts a source and returns its stable movie playback object.
Startup is asynchronous. The channel becomes active before its first frame is necessarily ready. Drawing an active channel during startup can therefore complete without displaying a frame. Decoder-opening errors stop that playback and are reported in the engine log.


    void playback = movie_play(
=== movie_stop() ===
        int source_id,
        int movie_channel
    );


{| class="wikitable"
<syntaxhighlight lang="c">
! Argument
movie_stop(playback);
! Required
</syntaxhighlight>
! Default
! Description
|-
| <code>source_id</code>
| Yes
| None
| Source returned by <code>movie_load()</code>.
|-
| <code>movie_channel</code>
| No
| <code>MOVIE_CHANNEL_AUTO</code>
| Omit the argument or pass <code>NULL()</code> for automatic allocation. Values from <code>0</code> through <code>63</code> force that channel.
|}


Forced selection stops the current channel occupant before opening the new playback. Automatic selection never replaces an active movie and fails when no channel is free.
Stops the selected playback and makes its channel available for reuse. The channel's active state, source association, position, and duration are reset. Calling it with a valid inactive channel object leaves that channel inactive.


The returned pointer identifies the channel object, not a permanent unique playback instance. Later forced playback on the same channel reuses the same pointer with new state.
Decoder teardown can continue asynchronously after the channel becomes inactive. Playback objects remain owned by the engine. Creator-owned destination screens have their own lifetime and can be released with <code>free()</code> when the creator has finished using them.


=== movie_stop() ===
=== movie_unload() ===


Stops playback, closes its decoder, releases its source reference, and recycles its movie channel.
<syntaxhighlight lang="c">
movie_unload(source_id);
</syntaxhighlight>


    movie_stop(void playback);
Releases a loaded source after every playback and retiring decoder has finished using it. Invalid or still-referenced sources report a script error. This function returns no status value for polling.


Calling <code>movie_stop()</code> with a valid but already inactive channel object safely leaves it inactive.
'''Source unloading requires completed decoder teardown.''' Decoder teardown may still retain that source after a channel becomes inactive. The script API has no source-readiness query; checking <code>MOVIE_PROPERTY_ACTIVE</code> alone is insufficient for an immediate unload. Keep reusable sources loaded across playbacks. Movie-system shutdown completes decoder teardown and releases remaining sources automatically.


=== Basic example ===
=== Basic screen-composition example ===


This example streams a movie asynchronously to the main screen. Normal engine updates and scripts continue while it plays.
The following functions use global variables to retain the controller's state across callbacks. Call initialization once, call drawing while the interface is visible, and call cleanup when closing it. The source remains loaded for reuse.


<syntaxhighlight lang="c" line="1">
void movie_example_init()
{
     int source_id = movie_load(
     int source_id = movie_load(
         "data/scenes/intro.webm",
         "data/scenes/intro.webm",
         openborconstant("MOVIE_LOADING_STREAM")
         openborconstant("MOVIE_LOADING_AUTO")
     );
     );
     void playback = movie_play(source_id);
     void playback = movie_play(source_id);
    void screen = allocscreen(320, 180);


The source can be unloaded after playback stops:
    setglobalvar("movie_example_source", source_id);
    setglobalvar("movie_example_playback", playback);
    setglobalvar("movie_example_screen", screen);
}


    int active = movie_get_property(
void movie_example_draw()
        playback,
{
        openborconstant("MOVIE_PROPERTY_ACTIVE")
    void playback = getglobalvar("movie_example_playback");
     );
     void screen = getglobalvar("movie_example_screen");


     if(!active)
     if(playback == NULL() || screen == NULL()) return;
     {
     if(!movie_get_property(
         movie_unload(source_id);
         playback, openborconstant("MOVIE_PROPERTY_ACTIVE")
     }
     )) return;


== Screen composition ==
    int channel = movie_get_channel_index(playback);
    clearscreen(screen);
    movie_draw_to_screen(screen, channel);
    drawstringtoscreen(screen, 6, 6, 0, "PLAYING");
    drawscreen(screen, 16, 16, 5000);
}


=== Main-screen fallback ===
void movie_example_close()
{
    void playback = getglobalvar("movie_example_playback");
    void screen = getglobalvar("movie_example_screen");


Playback with no assigned screen renders to the main 32-bit screen. Default width and height are zero, so the movie fills the destination. This preserves the visual behavior expected from traditional fullscreen movie playback while allowing the new API to remain asynchronous.
    if(playback != NULL()) movie_stop(playback);
    if(screen != NULL()) free(screen);


Unbound movies are composed after the ordinary sprite queue at the main-screen presentation stage. When several unbound movies are active, OpenBOR renders them in ascending movie-channel order. Higher channels therefore overwrite lower channels where their destination rectangles overlap.
    setglobalvar("movie_example_playback", NULL());
    setglobalvar("movie_example_screen", NULL());
}
</syntaxhighlight>


Use a subscreen when ordinary script drawing or sprite composition must appear over the movie.
The drawing function uses the common drawmethod when submitting its completed screen through <code>drawscreen()</code>. Keep that shared state appropriate for the intended presentation, as described in [[Drawmethod]]. Close the controller after pending draws that reference its screen have finished.


=== movie_set_screen() ===
== Screen composition ==


Assigns a creator-owned 32-bit subscreen to a playback.
=== movie_draw_to_screen() ===


    movie_set_screen(
<syntaxhighlight lang="text">
        void playback,
movie_draw_to_screen(screen, movie_channel)
        void screen
</syntaxhighlight>
    );
 
The first argument is a screen pointer. The second is an integer movie-channel index. Obtain that index with <code>movie_get_channel_index(playback)</code>, read <code>MOVIE_PROPERTY_CHANNEL</code>, or supply the channel explicitly selected at playback start.


The creator must allocate the screen first. The movie system does not create, resize, draw, or free creator subscreens.
The function draws the retained frame immediately into the selected screen. Its opaque movie rectangle is clipped to the destination, and pixels outside that rectangle retain their existing contents. Scripts control clearing, layering, later screen submission, and screen lifetime.


* <code>allocscreen(width, height)</code> creates a compatible 32-bit screen.
Use this sequence when a movie shares a composition with other graphics:
* Invalid, freed, non-screen, or non-32-bit pointers are rejected.
* Passing <code>NULL()</code> detaches the subscreen and restores main-screen rendering.
* Freeing an assigned screen automatically stops every movie playback still targeting it. This prevents a decoder from retaining a dangling screen pointer.
* Assigning a screen does not automatically place that screen on the main display. Use <code>drawscreen()</code> or another normal composition path.


The screen property is read-only through <code>movie_set_property()</code>. Use <code>movie_set_screen()</code> whenever the target changes.
# Clear or prepare the destination.
# Draw background content.
# Draw the movie with <code>movie_draw_to_screen()</code>.
# Draw captions, sprites, or other overlays.
# Submit the completed screen with <code>drawscreen()</code>.


=== Drawing order ===
Multiple movies drawn into one screen follow call order. Later movie rectangles replace earlier content where they overlap. Movie channel numbers do not determine that order.


Bound movie frames are copied into their subscreens near the beginning of each engine update, before creator update and key scripts execute. This gives a bound movie the same downstream composition behavior as other subscreen content:
<code>movie_draw_to_screen()</code> uses the movie's own size, offset, resampling, and black-filter properties. Global drawmethod state does not control this operation. To rotate, curve, blend, or otherwise transform the complete movie image, draw it into a subscreen and apply [[Drawmethod]] settings when drawing that screen.


# OpenBOR advances the decoder and writes the newest movie frame into the assigned subscreen.
=== Main screen and subscreens ===
# Creator scripts may call <code>drawstringtoscreen()</code>, <code>drawspritetoscreen()</code>, <code>drawboxtoscreen()</code>, or other screen functions afterward.
# The script submits the completed screen with <code>drawscreen()</code>.
# Existing drawmethod features may rotate, scale, flip, blend, or otherwise compose that screen.


Anything drawn to the same subscreen after the movie stage appears over the movie. Clearing the subscreen afterward also erases the copied movie frame, so avoid <code>clearscreen()</code> over the movie region unless that is intentional.
Use <code>allocscreen(width, height)</code> to create a subscreen. For a drawing hook that operates directly on the main virtual screen:


When several movie channels target the same subscreen, lower channel numbers render first and higher channel numbers render afterward. Creator drawing still occurs after all bound movies.
<syntaxhighlight lang="c">
void destination = openborvariant("vscreen");
movie_draw_to_screen(destination, channel);
</syntaxhighlight>


=== Width, height, offsets, and clipping ===
Direct main-screen drawing participates at the point where the script executes. Subsequent drawing can cover it, and a subsequent clear removes it. Playback retains no destination pointer, so each call can select a different screen.


<code>MOVIE_PROPERTY_WIDTH</code> and <code>MOVIE_PROPERTY_HEIGHT</code> independently select the prepared frame dimensions.
Both drawing functions require an active channel. Before the first frame is ready, a valid draw can do nothing successfully. Invalid channels, inactive channels, invalid screen destinations, and failed rendering report script errors. The drawing functions return no script value.


* Zero width uses the destination screen width.
=== Dimensions and offsets ===
* Zero height uses the destination screen height.
* Positive values scale the decoded frame to the requested dimension.
* Width and height may be set independently, so scripts are responsible for preserving aspect ratio when desired.
* Negative width or height is rejected.


<code>MOVIE_PROPERTY_OFFSET_X</code> and <code>MOVIE_PROPERTY_OFFSET_Y</code> place the scaled frame inside the destination. Offsets are signed. Pixels outside the destination are clipped safely.
Width and height resolve independently:


Scaling a movie larger than its destination and applying negative offsets provides a controllable zoom-and-crop effect. Scaling it smaller provides picture-in-picture placement. The destination's normal <code>drawscreen()</code> drawmethod remains available for later whole-screen rotation or scaling.
{| class="wikitable"
! Property value !! Screen composition !! Direct display
|-
| <code>0</code> || Use the corresponding destination-screen dimension. || Use the corresponding WebM display dimension.
|-
| <code>MOVIE_SIZE_NATIVE</code> || Use the corresponding decoded-frame dimension. || Use the corresponding WebM display dimension.
|-
| Positive explicit value || Set the movie rectangle's dimension in destination pixels. || Set the requested logical display dimension.
|}


=== Zoom-and-crop example ===
Set <code>MOVIE_PROPERTY_OFFSET_X</code> and <code>MOVIE_PROPERTY_OFFSET_Y</code> to place the movie rectangle within a screen. Offsets are signed. Oversized dimensions combined with negative offsets provide zoom-and-crop layouts; smaller dimensions provide inset placement. Set both dimensions appropriately when preserving the movie's aspect ratio.


This example prepares a 320 by 180 movie image and clips its central 160 by 90 region into a subscreen.
For a 640 by 360 movie rectangle centered within a 320 by 180 subscreen:


    void screen = allocscreen(160, 90);
<syntaxhighlight lang="c" line="1">
    int source_id = movie_load("data/scenes/camera.webm");
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_WIDTH"), 640);
    void playback = movie_play(source_id);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_HEIGHT"), 360);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_X"), -160);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_Y"), -90);


    movie_set_screen(playback, screen);
movie_draw_to_screen(movie_screen, channel);
</syntaxhighlight>


    movie_set_property(
With width and height both zero, the same playback can fill destinations of different sizes:
        playback,
        openborconstant("MOVIE_PROPERTY_WIDTH"),
        320
    );


    movie_set_property(
<syntaxhighlight lang="c" line="1">
        playback,
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_WIDTH"), 0);
        openborconstant("MOVIE_PROPERTY_HEIGHT"),
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_HEIGHT"), 0);
        180
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_X"), 0);
    );
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_Y"), 0);


    movie_set_property(
movie_draw_to_screen(large_screen, channel);
        playback,
movie_draw_to_screen(small_screen, channel);
        openborconstant("MOVIE_PROPERTY_OFFSET_X"),
</syntaxhighlight>
        -80
    );


    movie_set_property(
Both calls draw the same retained frame. Changing dimensions or offsets changes its presentation without restarting playback.
        playback,
        openborconstant("MOVIE_PROPERTY_OFFSET_Y"),
        -45
    );


=== Subscreen overlay example ===
=== Exact-black protection ===


Run the overlay and <code>drawscreen()</code> calls from a normal update script after the engine has copied the current movie frame.
Screen transparency settings can use RGB <code>0, 0, 0</code> as a transparent key when a subscreen is drawn later. Enable black protection when the movie's black areas should remain visible through such a composition:


     drawstringtoscreen(screen, 4, 4, 0, "LIVE");
<syntaxhighlight lang="c">
    drawscreen(screen, 80, 30, 5000);
movie_set_property(
     playback, openborconstant("MOVIE_PROPERTY_BLACK_FILTER"), 1
);
</syntaxhighlight>


The text becomes part of the subscreen after the movie frame and therefore appears over it. Any configured drawmethod applied by <code>drawscreen()</code> transforms the completed movie-and-overlay composition together.
The GPU first resamples the video planes and converts the result to RGB. It then changes exact output black to RGB <code>1, 1, 1</code> when protection is enabled. Other output colors retain their values. This protection is disabled by default and applies to screen composition.


=== Exact-black protection ===
== Movie resampling ==


Some subscreen composition paths treat RGB <code>0, 0, 0</code> as a transparency mask. Enable <code>MOVIE_PROPERTY_BLACK_FILTER</code> to protect exact-black movie pixels:
<code>MOVIE_PROPERTY_RESAMPLE</code> selects the filter used when rendering the decoded video. It applies to screen composition and direct display.


    movie_set_property(
{| class="wikitable"
        playback,
! Constant !! Sampling
        openborconstant("MOVIE_PROPERTY_BLACK_FILTER"),
|-
        1
| <code>DC_RESAMPLE_MOVIE</code> || Movie default; equivalent to bilinear.
    );
|-
| <code>DC_RESAMPLE_NEAREST</code> || Nearest-sample reconstruction.
|-
| <code>DC_RESAMPLE_BILINEAR</code> || Linear reconstruction between neighboring samples.
|-
| <code>DC_RESAMPLE_BICUBIC_CATMULL_ROM</code> || Catmull-Rom cubic reconstruction.
|-
| <code>DC_RESAMPLE_BICUBIC_MITCHELL</code> || Mitchell cubic reconstruction.
|-
| <code>DC_RESAMPLE_BICUBIC_BSPLINE</code> || B-spline cubic reconstruction.
|-
| <code>DC_RESAMPLE_LANCZOS_2</code> || Two-lobe Lanczos reconstruction.
|-
| <code>DC_RESAMPLE_LANCZOS_3</code> || Three-lobe Lanczos reconstruction.
|}


When enabled, OpenBOR changes only exact RGB <code>0, 0, 0</code> movie pixels to RGB <code>1, 1, 1</code> after YUV conversion. Other near-black shades remain unchanged. The filter affects the prepared movie frame before scaling and composition.
<syntaxhighlight lang="c" line="1">
movie_set_property(
    playback,
    openborconstant("MOVIE_PROPERTY_RESAMPLE"),
    openborconstant("DC_RESAMPLE_BICUBIC_MITCHELL")
);


The filter is disabled by default because ordinary main-screen playback does not need transparency-mask protection.
int filter = movie_get_property(
    playback, openborconstant("MOVIE_PROPERTY_RESAMPLE")
);
</syntaxhighlight>


== Playback control ==
The GPU reconstructs the Y, U, and V planes at their respective resolutions before converting to RGB. Changing this property takes effect when the frame is drawn again, including while playback is paused. It does not seek or restart decoding.


Movie control is provided through the property API. Timing properties use milliseconds.
Movie resampling controls video-to-destination rendering. Drawmethod resampling can separately control a subsequent transformed <code>drawscreen()</code> operation. Final display filtering is another stage applied when presenting the completed game screen. See [[Drawmethod#Resampling|Drawmethod resampling]].


=== Position and seeking ===
== Direct display presentation ==


<code>MOVIE_PROPERTY_POSITION</code> reports the current playback position as an unsigned 64-bit millisecond value. Writing it seeks by reopening the decoder at the requested position.
=== movie_draw_to_yuv() ===


<code>MOVIE_PROPERTY_DURATION</code> reports the source duration in milliseconds and is read-only. Seeking at or beyond a known duration clamps the request to the final available millisecond.
<syntaxhighlight lang="c">
movie_draw_to_yuv(channel);
</syntaxhighlight>


    int position_id = openborconstant("MOVIE_PROPERTY_POSITION");
This function renders the retained movie frame directly to the display window and presents it immediately. It clears the window background, centers the movie using the selected logical display dimensions, and applies display brightness and gamma. The display's stretch setting can fill the window.


    movie_set_property(playback, position_id, 30000); // 30 seconds
Logical display dimensions are scaled for the actual window. They are independent of the game screen resolution configured in <code>video.txt</code>; explicit movie width and height are not literal window-pixel extents. Movie X/Y offsets and exact-black protection are screen-composition controls and do not apply here.


Seeking preserves the last prepared frame until a replacement frame is ready. Streamed seek latency depends on storage performance and WebM keyframe placement. Cached mode can reduce storage latency but still performs decoder work.
Each direct-display call presents a complete movie view. Use screen composition to assemble captions, sprites, several movies, or other overlays into one frame. Direct presentation preserves the normal graphics resources, so ordinary screen rendering and presentation remain available. Stopping a directly presented movie clears its direct-presentation state.


=== Pause ===
For example, after acquiring an active playback:


<code>MOVIE_PROPERTY_PAUSED</code> accepts zero or nonzero values. Pausing freezes the movie clock, preserves the current frame, and pauses embedded audio. Resuming continues from the stored position.
<syntaxhighlight lang="c" line="1">
movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_WIDTH"),
    openborconstant("MOVIE_SIZE_NATIVE")
);
movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_HEIGHT"),
    openborconstant("MOVIE_SIZE_NATIVE")
);


=== Speed, fast-forward, and reverse ===
// Call when the controller wants to present the retained movie frame.
if(movie_get_property(playback, openborconstant("MOVIE_PROPERTY_ACTIVE")))
{
    movie_draw_to_yuv(movie_get_channel_index(playback));
}
</syntaxhighlight>


<code>MOVIE_PROPERTY_SPEED</code> accepts a decimal from <code>-16.0</code> through <code>16.0</code>.
Position, pause, speed, repeat, interruption, and sound routing use the same playback properties for either destination.


{| class="wikitable"
== Playback timing and control ==
! Speed
! Video behavior
! Embedded-audio behavior
|-
| <code>1.0</code>
| Normal forward playback.
| Normal speed and pitch.
|-
| Greater than <code>1.0</code>
| Fast-forward.
| Speed and pitch increase with the positive rate.
|-
| Between <code>0.0</code> and <code>1.0</code>
| Slow forward playback.
| Speed and pitch decrease with the positive rate.
|-
| <code>0.0</code>
| Holds the current position and frame.
| Paused.
|-
| Less than <code>0.0</code>
| Reverse playback.
| Paused. OpenBOR does not reverse embedded audio.
|}


Reverse playback periodically seeks backward and decodes forward to recover the requested frame. It is therefore more expensive than ordinary forward playback and is sensitive to storage speed and keyframe spacing.
Position and duration use milliseconds. The playback clock begins when asynchronous decoder startup is ready. Drawing does not move the clock, and omitting drawing does not pause the movie.


    int speed_id = openborconstant("MOVIE_PROPERTY_SPEED");
While the movie owns an embedded audio stream, consumed audio provides the playback clock. Video follows that clock, with late frames discarded when necessary to preserve synchronization. Video-only playback uses the movie's own clock. If another audio producer replaces the movie's sound stream, the movie continues from a matching position on its own clock.


    movie_set_property(playback, speed_id, 2.0);  // Fast-forward
=== Position and seeking ===
    movie_set_property(playback, speed_id, -1.0); // Reverse
    movie_set_property(playback, speed_id, 1.0);  // Normal


=== Repeat ===
Read <code>MOVIE_PROPERTY_POSITION</code> for the playback position. Write it to request a seek:


<code>MOVIE_PROPERTY_REPEAT</code> accepts zero or nonzero values. Forward playback reopens at the beginning after its terminal frame. Reverse playback wraps from position zero to the final available millisecond when duration is known.
<syntaxhighlight lang="c">
movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_POSITION"), 12500
);
</syntaxhighlight>


Movie playback has no separate repeat offset. Scripts can implement custom loop regions by observing position and writing a new position.
This requests 12.5 seconds. Seeking reopens decoding asynchronously while retaining the displayed frame until replacement frames are ready. When duration is known, a seek at or beyond its end is clamped to the last available millisecond. <code>MOVIE_PROPERTY_DURATION</code> is read-only and remains zero until duration is known.


=== Input interruption ===
Use position changes for rewind controls and other backward navigation. Continuous negative-speed playback is not supported.


<code>MOVIE_PROPERTY_INTERRUPT</code> defaults to <code>1</code>. New Escape or normal movie-skip button presses stop playback during the engine update.
=== Pause ===


Set the property to <code>0</code> when playback must continue until natural completion or an explicit <code>movie_stop()</code> call:
Set <code>MOVIE_PROPERTY_PAUSED</code> to 1 to hold the position and displayed frame and pause the movie's audio. Set it to 0 to resume.


    movie_set_property(
<syntaxhighlight lang="c">
        playback,
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_PAUSED"), 1);
        openborconstant("MOVIE_PROPERTY_INTERRUPT"),
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_PAUSED"), 0);
        0
</syntaxhighlight>
    );


== Embedded audio ==
=== Speed ===


Movie channels and sound channels are independent address spaces.
<code>MOVIE_PROPERTY_SPEED</code> accepts finite nonnegative values. Normal speed is <code>1.0</code>. Values below 1 slow playback; values above 1 accelerate it. Positive speed changes also change embedded-audio speed and pitch.


* Movie channels range from <code>0</code> through <code>63</code> and own video playback objects.
Rates above <code>16.0</code> are clamped to 16.0, and accepted rates are rounded to the nearest 0.001. Negative or nonfinite values report an error. Zero holds the position and pauses audio. Returning from zero to a positive rate reopens decoding at the held position.
* Sound channels range from <code>0</code> through <code>4095</code> and mix audio.
* Every new movie playback initially routes embedded audio to sound channel <code>0</code>.
* Modern <code>movie_play()</code> playback replaces only its selected sound channel. It does not stop unrelated sound channels.
* WebM sources without an audio track leave existing sound playback unchanged.
* Failure to open an otherwise optional audio track leaves the video playing silently.


Channel <code>0</code> is OpenBOR's soft-reserved music and media channel. Starting a movie with embedded audio therefore replaces the current occupant of sound channel 0 unless the previous movie has already been routed elsewhere.
<syntaxhighlight lang="c" line="1">
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 0.5);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 2.0);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 1.0);
</syntaxhighlight>


=== movie_set_sound_channel() ===
These statements select half speed, double speed, and normal speed respectively; use the statement matching the desired control action.


Moves a playback's embedded audio to an explicit sound channel.
=== Repeat and interruption ===


    movie_set_sound_channel(
Set <code>MOVIE_PROPERTY_REPEAT</code> to 1 to reopen playback from the beginning when it reaches its terminal frame. Scripts can implement a custom loop region by observing position and requesting a seek to its beginning.
        void playback,
        int sound_channel
    );


Valid sound channels are <code>0</code> through <code>4095</code>. Changing the sound channel reopens the decoder at the current movie position so video and audio remain synchronized. The selected sound channel is forced: an existing occupant is replaced without a priority check.
<code>MOVIE_PROPERTY_INTERRUPT</code> defaults to 1. New Escape or normal movie-skip input stops interruptible playback during the engine update. Set it to 0 when a controller should handle stopping itself:


The sound-channel property is read-only through <code>movie_set_property()</code>. Use <code>movie_set_sound_channel()</code> to change routing.
<syntaxhighlight lang="c" line="1">
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_REPEAT"), 1);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_INTERRUPT"), 0);
</syntaxhighlight>


Route each movie to its intended sound channel immediately after starting it and before starting the next audible movie:
== Embedded audio ==


    int source_a = movie_load("data/scenes/feed_a.webm");
Movie channels select playback objects. Sound channels select destinations in the audio mixer. Their indexes are separate: movie channels run from 0 through 63, and sound channels run from 0 through 4095.
    int source_b = movie_load("data/scenes/feed_b.webm");


    void movie_a = movie_play(source_a, 4);
Each playback initially selects sound channel 0, the music and media channel. Embedded audio replaces the occupant of its selected sound channel. Ordinary <code>movie_play()</code> leaves unrelated sound channels running, and a movie without audio leaves existing sound playback alone.
    movie_set_sound_channel(movie_a, 10);


    void movie_b = movie_play(source_b, 5);
=== movie_set_sound_channel() ===
    movie_set_sound_channel(movie_b, 11);


The embedded streams are ordinary producer-fed sound objects. Scripts may inspect their volume, pause state, play ID, and other applicable common properties through the [[Audio Overview|sound object API]]. Sample-backed seeking properties do not apply to producer-fed movie audio; seek through <code>MOVIE_PROPERTY_POSITION</code> instead.
<syntaxhighlight lang="text">
movie_set_sound_channel(playback, sound_channel)
</syntaxhighlight>


== Movie object script API ==
Routes an active playback's embedded audio to the selected sound channel. Changing the destination reopens decoding asynchronously at the playback position. Selecting the already assigned channel leaves its routing in place. The destination is selected directly, so its existing audio is replaced without priority arbitration.


Advanced scripts may inspect the fixed movie channel bank, obtain stable channel objects, and read or change playback properties.
For simultaneous audible movies, assign separate sound channels immediately after starting each playback:


Use named constants from <code>openborconstant()</code>. Raw numeric property and mode IDs are implementation details.
<syntaxhighlight lang="c" line="1">
int source_a = movie_load("data/scenes/feed_a.webm");
int source_b = movie_load("data/scenes/feed_b.webm");


=== movie_get_channel_mask() ===
void playback_a = movie_play(source_a, 4);
movie_set_sound_channel(playback_a, 10);


    mixed active_mask = movie_get_channel_mask();
void playback_b = movie_play(source_b, 5);
movie_set_sound_channel(playback_b, 11);
</syntaxhighlight>


Returns an unsigned 64-bit mask. Bit <code>0</code> represents movie channel 0, bit <code>1</code> represents channel 1, and so on. Set bits indicate active playback.
<code>MOVIE_PROPERTY_SOUND_CHANNEL</code> reports this routing and is read-only through the property API. Embedded streams also expose applicable controls through the sound-object API. Seek the movie through <code>MOVIE_PROPERTY_POSITION</code> so audio and video remain coordinated. See [[Audio Overview]].


=== movie_get_channel_object() ===
== Movie object API ==


    void playback = movie_get_channel_object(int movie_channel);
Use <code>openborconstant()</code> for property and loading-mode names. Channel indexes are ordinary integers.


Returns the stable movie object for a channel from <code>0</code> through <code>63</code>. The fixed bank exists after movie-system initialization, so inactive channels still return objects. Test <code>MOVIE_PROPERTY_ACTIVE</code> or the active mask before treating the object as current playback.
=== Channel access ===


=== movie_get_channel_index() ===
{| class="wikitable"
! Function !! Result
|-
| <code>movie_get_channel_object(channel)</code> || Engine-owned object for that channel, including an inactive channel.
|-
| <code>movie_get_channel_index(playback)</code> || Index belonging to a valid playback object.
|-
| <code>movie_get_channel_mask()</code> || Unsigned 64-bit activity mask with one bit per movie channel. Set bits identify active playback on their corresponding channels.
|}


    int movie_channel = movie_get_channel_index(void playback);
For a particular channel, read its active state directly:


Validates a movie object pointer and returns its channel index.
<syntaxhighlight lang="c" line="1">
void playback = movie_get_channel_object(5);
int active = movie_get_property(
    playback, openborconstant("MOVIE_PROPERTY_ACTIVE")
);
</syntaxhighlight>


=== Property access ===
=== Property access ===


    mixed value = movie_get_property(
<syntaxhighlight lang="text">
        void playback,
movie_get_property(playback, property)
        int property
movie_set_property(playback, property, value)
    );
</syntaxhighlight>


    movie_set_property(
The getter returns the property's value. The setter returns no value. Invalid objects, property identifiers, values, and writes to read-only properties report script errors.
        void playback,
        int property,
        mixed value
    );


Property reads use a synchronized public-state snapshot. Playback-sensitive writes route through lifecycle-aware helpers so clocks, decoders, frame scaling, audio, and screen composition remain coherent.
The following defaults describe a newly started playback. Stopping resets the channel; its source becomes invalid and position and duration become zero.


{| class="wikitable"
{| class="wikitable"
! Property constant
! Property !! Access !! Default !! Meaning
! Type
! Access
! Default
! Description
|-
|-
| <code>MOVIE_PROPERTY_ACTIVE</code>
| <code>MOVIE_PROPERTY_ACTIVE</code> || Read || 1 after start || Whether the channel owns active playback.
| Integer
| Read
| <code>0</code> before play
| <code>1</code> while the channel owns active playback; otherwise <code>0</code>.
|-
|-
| <code>MOVIE_PROPERTY_BLACK_FILTER</code>
| <code>MOVIE_PROPERTY_BLACK_FILTER</code> || Read/write || 0 || Protect exact output black during screen composition.
| Integer
| Read/write
| <code>0</code>
| Converts exact RGB black movie pixels to RGB <code>1, 1, 1</code>.
|-
|-
| <code>MOVIE_PROPERTY_CHANNEL</code>
| <code>MOVIE_PROPERTY_CHANNEL</code> || Read || Acquired index || Movie channel index.
| Integer
| Read
| Channel index
| Stable movie channel from <code>0</code> through <code>63</code>.
|-
|-
| <code>MOVIE_PROPERTY_DURATION</code>
| <code>MOVIE_PROPERTY_DURATION</code> || Read || 0 until known || Unsigned 64-bit duration in milliseconds.
| Unsigned 64-bit integer
| Read
| Source value
| Duration in milliseconds.
|-
|-
| <code>MOVIE_PROPERTY_HEIGHT</code>
| <code>MOVIE_PROPERTY_HEIGHT</code> || Read/write || 0 || Height selection; see [[#Dimensions and offsets|Dimensions and offsets]].
| Integer
| Read/write
| <code>0</code>
| Prepared frame height. Zero uses the destination height.
|-
|-
| <code>MOVIE_PROPERTY_INTERRUPT</code>
| <code>MOVIE_PROPERTY_INTERRUPT</code> || Read/write || 1 || Allow normal movie-skip input.
| Integer
| Read/write
| <code>1</code>
| Nonzero allows normal movie-skip input to stop playback.
|-
|-
| <code>MOVIE_PROPERTY_OFFSET_X</code>
| <code>MOVIE_PROPERTY_OFFSET_X</code> || Read/write || 0 || Signed horizontal placement within a destination screen.
| Integer
| Read/write
| <code>0</code>
| Signed horizontal destination offset. Overflow is clipped.
|-
|-
| <code>MOVIE_PROPERTY_OFFSET_Y</code>
| <code>MOVIE_PROPERTY_OFFSET_Y</code> || Read/write || 0 || Signed vertical placement within a destination screen.
| Integer
| Read/write
| <code>0</code>
| Signed vertical destination offset. Overflow is clipped.
|-
|-
| <code>MOVIE_PROPERTY_PAUSED</code>
| <code>MOVIE_PROPERTY_PAUSED</code> || Read/write || 0 || Hold the playback clock and owned audio stream.
| Integer
| Read/write
| <code>0</code>
| Pause state. Writes require active playback.
|-
|-
| <code>MOVIE_PROPERTY_POSITION</code>
| <code>MOVIE_PROPERTY_POSITION</code> || Read/write || 0 || Unsigned 64-bit millisecond position. Writing requests a seek.
| Unsigned 64-bit integer
| Read/write
| <code>0</code>
| Current millisecond position. Writing seeks active playback.
|-
|-
| <code>MOVIE_PROPERTY_REPEAT</code>
| <code>MOVIE_PROPERTY_REPEAT</code> || Read/write || 0 || Restart from the beginning at the terminal frame.
| Integer
| Read/write
| <code>0</code>
| Nonzero repeats at the source boundary.
|-
|-
| <code>MOVIE_PROPERTY_SCREEN</code>
| <code>MOVIE_PROPERTY_RESAMPLE</code> || Read/write || <code>DC_RESAMPLE_MOVIE</code> || Filter used to render decoded video; the movie default is bilinear.
| Pointer
| Read
| <code>NULL()</code>
| Assigned 32-bit subscreen. Change with <code>movie_set_screen()</code>.
|-
|-
| <code>MOVIE_PROPERTY_SOUND_CHANNEL</code>
| <code>MOVIE_PROPERTY_SOUND_CHANNEL</code> || Read || 0 || Embedded-audio destination. Change with <code>movie_set_sound_channel()</code>.
| Integer
| Read
| <code>0</code>
| Generic sound channel used by embedded audio. Change with <code>movie_set_sound_channel()</code>.
|-
|-
| <code>MOVIE_PROPERTY_SOURCE</code>
| <code>MOVIE_PROPERTY_SOURCE</code> || Read || Played source || Source ID associated with playback.
| Integer
| Read
| <code>-1</code> while inactive
| Source ID owned by the current playback.
|-
|-
| <code>MOVIE_PROPERTY_SPEED</code>
| <code>MOVIE_PROPERTY_SPEED</code> || Read/write || 1.0 || Forward playback rate, normalized to 0 through 16.
| Decimal
| Read/write
| <code>1.0</code>
| Signed playback speed from <code>-16.0</code> through <code>16.0</code>.
|-
|-
| <code>MOVIE_PROPERTY_WIDTH</code>
| <code>MOVIE_PROPERTY_WIDTH</code> || Read/write || 0 || Width selection; see [[#Dimensions and offsets|Dimensions and offsets]].
| Integer
| Read/write
| <code>0</code>
| Prepared frame width. Zero uses the destination width.
|}
|}


=== Property example ===
Boolean properties use zero for disabled and nonzero for enabled. Pause, position, speed, and sound-routing changes require active playback. Configure appearance, repeat, and interruption after starting playback because each start restores the defaults.


This example pauses an active playback, seeks to 12.5 seconds, disables skip input, and resumes at half speed.
For a diagnostic listing of the public property map:


    if(movie_get_property(
<syntaxhighlight lang="c">
        playback,
movie_get_property(playback, openborconstant("PROPERTY_ACCESS_DUMP"));
        openborconstant("MOVIE_PROPERTY_ACTIVE")
</syntaxhighlight>
    ))
    {
        movie_set_property(
            playback,
            openborconstant("MOVIE_PROPERTY_PAUSED"),
            1
        );


        movie_set_property(
This writes the property listing to the engine log.
            playback,
            openborconstant("MOVIE_PROPERTY_POSITION"),
            12500
        );


        movie_set_property(
== Blocking playback ==
            playback,
            openborconstant("MOVIE_PROPERTY_INTERRUPT"),
            0
        );


        movie_set_property(
Use blocking playback when a movie should complete or be interrupted before its calling script or scene continues.
            playback,
            openborconstant("MOVIE_PROPERTY_SPEED"),
            0.5
        );
 
        movie_set_property(
            playback,
            openborconstant("MOVIE_PROPERTY_PAUSED"),
            0
        );
    }
 
== Legacy playback ==
 
Traditional WebM entry points remain available as wrappers around the movie system. Their defaults intentionally reproduce historical blocking fullscreen behavior.


=== playwebm() ===
=== playwebm() ===


    int result = playwebm(
<syntaxhighlight lang="text">
        string path,
playwebm(path [, noskip])
        int noskip
</syntaxhighlight>
    );


{| class="wikitable"
<syntaxhighlight lang="c">
! Argument
int result = playwebm("data/scenes/intro.webm", 0);
! Required
</syntaxhighlight>
! Default
! Description
|-
| <code>path</code>
| Yes
| None
| Exact WebM source path.
|-
| <code>noskip</code>
| No
| <code>0</code>
| Zero permits normal skip input. Nonzero forces playback to continue until completion or error.
|}


Return values:
<code>noskip</code> defaults to 0, allowing normal skip input. Nonzero disables that input interruption.


{| class="wikitable"
{| class="wikitable"
! Result
! Result !! Meaning
! Meaning
|-
|-
| <code>1</code>
| <code>1</code> || Movie completed.
| Playback completed normally.
|-
|-
| <code>0</code>
| <code>0</code> || Playback failed.
| Loading, decoding, rendering, or cleanup failed.
|-
|-
| <code>-1</code>
| <code>-1</code> || Permitted input interrupted playback.
| Creator-enabled input interrupted playback.
|}
|}


The wrapper performs the following operations:
The function stops existing movie playbacks, opens a streamed source, and presents it directly using the WebM display dimensions. It services input and movie playback while blocking the caller. Width and height use <code>MOVIE_SIZE_NATIVE</code>, playback speed is normal, repeat is disabled, and movie resampling uses its bilinear default.


* Stops every active movie playback.
Movies with embedded audio request exclusive audio playback through sound channel 0. Silent movies allow existing music to continue. Screenshot capture renders the movie through the GPU into a capture screen before reading the completed pixels for the screenshot.
* Loads the requested source in streamed mode.
* Uses automatic movie-channel selection.
* Leaves the screen unbound, with zero width and height, so the movie fills the main screen.
* Uses normal speed, no repeat, no black filter, and sound channel 0.
* Blocks the calling scene or script until completion, interruption, or error.
* Clears and presents the main screen directly during playback.
* Unloads its temporary source before returning.
* Preserves the historical replace-all sound behavior when the WebM contains audio.


Legacy WebM files with embedded audio stop current music and active sample playback before opening a producer-fed stream on sound channel 0. Legacy WebM files without audio leave existing channel 0 playback running.
Cleanup completes decoder teardown and releases the temporary source before returning. Normal game rendering remains available after direct movie presentation.


=== Scene video command ===
=== Scene video command ===


Scene files retain their existing command:
<syntaxhighlight lang="text">
video path [skipone] [noskip]
</syntaxhighlight>


    video {path} {skipone} {noskip}
Both optional flags default to zero.
 
{| class="wikitable"
! Setting !! Behavior
|-
| <code>skipone 0</code> || Interrupting a video skips the remaining scene media.
|-
| <code>skipone 1</code> || Interrupting a video skips it and continues with subsequent scene commands.
|-
| <code>noskip 0</code> || Normal movie-skip input is allowed.
|-
| <code>noskip 1</code> || Movie-skip input is disabled.
|}


<code>noskip</code> uses the same interruption rule as <code>playwebm()</code>. When interruption is enabled, <code>skipone</code> controls whether an interrupted video allows the scene parser to continue instead of closing the remaining scene.
For example, allow skipping just this video while continuing the scene:


Projects requiring asynchronous playback, composition, seeking, speed control, repeat, multiple channels, caching, or separate sound routing should use the <code>movie_*</code> API.
<syntaxhighlight lang="text">
video data/scenes/intro.webm 1 0
</syntaxhighlight>


== Practical guidance ==
Later <code>silence</code> commands still apply when interruption skips the remaining scene media.


* Stream long or one-time movies that would waste RAM as complete cached files.
The scene command uses the blocking player. Choose the <code>movie_*</code> functions when a controller needs asynchronous playback, screen composition, seeking, repeat, selectable resampling, or independent movie and sound channels.
* Cache short, frequently reused, or seek-heavy clips when storage latency matters and sufficient memory is available.
* Remember that cached sources still require full VP8 and Vorbis decoding for every playback.
* Bind a creator-owned subscreen whenever sprites, text, effects, or other screen drawing must appear over the movie.
* Leave the screen unset only when main-screen fallback and late fullscreen composition are desired.
* Treat zero width and height as destination-fill behavior. Set explicit dimensions when preserving aspect ratio or building picture-in-picture layouts.
* Use signed offsets with oversized dimensions for controlled zoom and clipping.
* Enable the black filter only when exact black must survive a subscreen transparency mask.
* Route simultaneous movies to distinct sound channels immediately after each <code>movie_play()</code> call.
* Expect reverse playback and frequent streamed seeks to cost substantially more than normal forward playback.
* Stop every playback using a source before calling <code>movie_unload()</code>.
* Treat movie pointers as stable channel slots rather than permanent unique playback instances.
* Use the 64-channel mask as a fast state summary, not as a target workload.
* Prefer the modern movie API for new projects. Reserve <code>playwebm()</code> and the scene <code>video</code> command for compatibility or intentionally blocking presentation.


== Related pages ==
== See also ==


* [[Graphics Overview]]
* [[Drawmethod]]
* [[Subscreens]]
* [[Direct Drawing]]
* [[Audio Overview]]
* [[Audio Overview]]
* [[Drawmethod]]
* [[Scenes]]
* [[Drawscreen()|drawscreen]]
* [[WebM]]
* [[Allocscreen()|allocscreen]]
 
[[Category:Openbor]]
[[Category:Openbor]]
[[Category:Script]]
[[Category:Script]]
[[Category:Graphics]]
[[Category:Graphics]]

Latest revision as of 19:33, 28 November 2026

Introduction

OpenBOR plays WebM movies containing VP8 video and optional Vorbis audio. Movies can supply cinematics, animated interfaces, video surfaces, picture-in-picture layouts, or the main content of a module.

The movie system separates playback from drawing. Video and audio decoding run asynchronously on the CPU. The GPU samples the decoded video planes, converts their YUV colors to RGB, and renders the result. Scripts decide when and where to draw the retained frame while the movie channel manages position, pause, speed, repeat, and audio.

Both movie_draw_to_screen() and movie_draw_to_yuv() use GPU rendering. Their difference is the destination: an OpenBOR screen for composition, or the display for direct presentation.

Choosing a drawing destination

Feature Screen composition Direct display
Function movie_draw_to_screen(screen, channel) movie_draw_to_yuv(channel)
Destination Main virtual screen or a creator-owned subscreen. Display window.
Rendering GPU video sampling, YUV-to-RGB conversion, scaling, and drawing. GPU video sampling, YUV-to-RGB conversion, scaling, and presentation.
Placement Movie dimensions and signed destination offsets, clipped to the screen. Centered presentation using logical display dimensions and the display's stretch setting.
Composition Combine movies with sprites, text, effects, and other screen content. Present one movie frame directly. Each call replaces the displayed window content.
Image controls Movie resampling and exact-black protection. Apply drawmethod effects when drawing the resulting screen. Movie resampling and display brightness/gamma correction.
Typical use Video surfaces, captions, interfaces, multiple views, and layered scenes. Full-window movie playback controlled directly by a script or scene.

Drawing uses the channel's retained frame. It does not advance playback or request a separate decode. One retained frame may be drawn repeatedly, sent to several screens, or shown through either drawing function. The renderer reuses its uploaded video planes until playback supplies another frame.

Formats

Component Format
Container WebM. Supply the complete module path, including its extension.
Video VP8. Use even frame dimensions of at least 2 by 2 pixels. The video track must use a non-stereoscopic mode.
Embedded audio Optional Vorbis, mono or stereo. The engine's music sample-rate range is 11,025 through 48,000 Hz.
Screen destination 32-bit OpenBOR screen, including screens created with allocscreen().

The decoder selects the first video track and first audio track. Unsupported video or audio codecs reject playback when the decoder opens. If initialization of a supported optional Vorbis track fails, video may continue silently with the reason recorded in the engine log.

Loading checks that source data can be opened or cached. Codec and track validation takes place when playback opens asynchronously, so a loaded source can still report a playback-opening error.

Sources, playback, and channels

Three identifiers serve different purposes:

Item Returned by Purpose
Source ID movie_load() Identifies a reusable streamed file or cached compressed file.
Playback object movie_play() Provides property access and playback control for a movie channel.
Movie channel index movie_get_channel_index() Selects the movie used by either drawing function.

Movie channels are numbered 0 through 63. MOVIE_CHANNEL_COUNT provides the channel count, and MOVIE_CHANNEL_AUTO requests automatic selection. Automatic selection takes the lowest inactive channel and reports an error when every channel is active. Selecting an explicit index replaces playback on that channel.

The playback pointer identifies an engine-owned channel object. Its address remains stable while the movie system is running, including when the channel is inactive. Reusing the channel replaces its playback state. Coordinate channel ownership between scripts, and use MOVIE_PROPERTY_ACTIVE to check whether a channel is playing. Release playback with movie_stop(); the engine manages the channel object's storage.

Source storage is separate from the 64-channel playback bank and grows as sources are loaded. Source IDs increase during the session and are not reassigned after unloading. Loading the same path twice creates two source IDs. One source may be played on several channels, with independent timing, presentation settings, and audio routing.

Loading modes

Constant Source storage Use
MOVIE_LOADING_STREAM Retains the file path. Each playback opens its own file position and decoder. Playback that reads its compressed data from the module as needed. This is the default.
MOVIE_LOADING_CACHE Reads the complete compressed file into a shared source buffer. Reusing a clip or avoiding repeated reads of its compressed data.
MOVIE_LOADING_AUTO Chooses cached or streamed storage using the engine's source-cache policy. Automatic storage selection.

Cached storage contains the compressed WebM file. Each playback still owns its decoder, frame queues, position, and controls.

Automatic selection uses an aggregate movie-cache budget of one quarter of total system memory and preserves a reserve of at least one eighth of total memory or 128 MiB, whichever is greater. If a cache allocation cannot be satisfied, automatic mode can use streaming. Explicit cache mode reports a failed load. Open or size-validation failures fail loading. During caching, read errors fail the load instead of selecting streaming.

Script playback

movie_load()

movie_load(path [, loading])

Returns an integer source ID. path is the exact module path; OpenBOR does not append an extension. Omitting loading selects MOVIE_LOADING_STREAM.

int source_id = movie_load(
    "data/scenes/intro.webm",
    openborconstant("MOVIE_LOADING_AUTO")
);

Source ID 0 is valid. Invalid paths, empty files, invalid loading modes, and failed source allocations report script errors.

movie_play()

movie_play(source_id [, movie_channel])

Returns the playback object for the acquired movie channel. Omit the second argument, pass NULL(), or use MOVIE_CHANNEL_AUTO for automatic selection.

void playback = movie_play(source_id);
int channel = movie_get_channel_index(playback);

// Select a particular movie channel.
void another_playback = movie_play(source_id, 5);

Every start restores the channel's default properties. Configure the returned playback object after calling movie_play().

Startup is asynchronous. The channel becomes active before its first frame is necessarily ready. Drawing an active channel during startup can therefore complete without displaying a frame. Decoder-opening errors stop that playback and are reported in the engine log.

movie_stop()

movie_stop(playback);

Stops the selected playback and makes its channel available for reuse. The channel's active state, source association, position, and duration are reset. Calling it with a valid inactive channel object leaves that channel inactive.

Decoder teardown can continue asynchronously after the channel becomes inactive. Playback objects remain owned by the engine. Creator-owned destination screens have their own lifetime and can be released with free() when the creator has finished using them.

movie_unload()

movie_unload(source_id);

Releases a loaded source after every playback and retiring decoder has finished using it. Invalid or still-referenced sources report a script error. This function returns no status value for polling.

Source unloading requires completed decoder teardown. Decoder teardown may still retain that source after a channel becomes inactive. The script API has no source-readiness query; checking MOVIE_PROPERTY_ACTIVE alone is insufficient for an immediate unload. Keep reusable sources loaded across playbacks. Movie-system shutdown completes decoder teardown and releases remaining sources automatically.

Basic screen-composition example

The following functions use global variables to retain the controller's state across callbacks. Call initialization once, call drawing while the interface is visible, and call cleanup when closing it. The source remains loaded for reuse.

void movie_example_init()
{
    int source_id = movie_load(
        "data/scenes/intro.webm",
        openborconstant("MOVIE_LOADING_AUTO")
    );
    void playback = movie_play(source_id);
    void screen = allocscreen(320, 180);

    setglobalvar("movie_example_source", source_id);
    setglobalvar("movie_example_playback", playback);
    setglobalvar("movie_example_screen", screen);
}

void movie_example_draw()
{
    void playback = getglobalvar("movie_example_playback");
    void screen = getglobalvar("movie_example_screen");

    if(playback == NULL() || screen == NULL()) return;
    if(!movie_get_property(
        playback, openborconstant("MOVIE_PROPERTY_ACTIVE")
    )) return;

    int channel = movie_get_channel_index(playback);
    clearscreen(screen);
    movie_draw_to_screen(screen, channel);
    drawstringtoscreen(screen, 6, 6, 0, "PLAYING");
    drawscreen(screen, 16, 16, 5000);
}

void movie_example_close()
{
    void playback = getglobalvar("movie_example_playback");
    void screen = getglobalvar("movie_example_screen");

    if(playback != NULL()) movie_stop(playback);
    if(screen != NULL()) free(screen);

    setglobalvar("movie_example_playback", NULL());
    setglobalvar("movie_example_screen", NULL());
}

The drawing function uses the common drawmethod when submitting its completed screen through drawscreen(). Keep that shared state appropriate for the intended presentation, as described in Drawmethod. Close the controller after pending draws that reference its screen have finished.

Screen composition

movie_draw_to_screen()

movie_draw_to_screen(screen, movie_channel)

The first argument is a screen pointer. The second is an integer movie-channel index. Obtain that index with movie_get_channel_index(playback), read MOVIE_PROPERTY_CHANNEL, or supply the channel explicitly selected at playback start.

The function draws the retained frame immediately into the selected screen. Its opaque movie rectangle is clipped to the destination, and pixels outside that rectangle retain their existing contents. Scripts control clearing, layering, later screen submission, and screen lifetime.

Use this sequence when a movie shares a composition with other graphics:

  1. Clear or prepare the destination.
  2. Draw background content.
  3. Draw the movie with movie_draw_to_screen().
  4. Draw captions, sprites, or other overlays.
  5. Submit the completed screen with drawscreen().

Multiple movies drawn into one screen follow call order. Later movie rectangles replace earlier content where they overlap. Movie channel numbers do not determine that order.

movie_draw_to_screen() uses the movie's own size, offset, resampling, and black-filter properties. Global drawmethod state does not control this operation. To rotate, curve, blend, or otherwise transform the complete movie image, draw it into a subscreen and apply Drawmethod settings when drawing that screen.

Main screen and subscreens

Use allocscreen(width, height) to create a subscreen. For a drawing hook that operates directly on the main virtual screen:

void destination = openborvariant("vscreen");
movie_draw_to_screen(destination, channel);

Direct main-screen drawing participates at the point where the script executes. Subsequent drawing can cover it, and a subsequent clear removes it. Playback retains no destination pointer, so each call can select a different screen.

Both drawing functions require an active channel. Before the first frame is ready, a valid draw can do nothing successfully. Invalid channels, inactive channels, invalid screen destinations, and failed rendering report script errors. The drawing functions return no script value.

Dimensions and offsets

Width and height resolve independently:

Property value Screen composition Direct display
0 Use the corresponding destination-screen dimension. Use the corresponding WebM display dimension.
MOVIE_SIZE_NATIVE Use the corresponding decoded-frame dimension. Use the corresponding WebM display dimension.
Positive explicit value Set the movie rectangle's dimension in destination pixels. Set the requested logical display dimension.

Set MOVIE_PROPERTY_OFFSET_X and MOVIE_PROPERTY_OFFSET_Y to place the movie rectangle within a screen. Offsets are signed. Oversized dimensions combined with negative offsets provide zoom-and-crop layouts; smaller dimensions provide inset placement. Set both dimensions appropriately when preserving the movie's aspect ratio.

For a 640 by 360 movie rectangle centered within a 320 by 180 subscreen:

movie_set_property(playback, openborconstant("MOVIE_PROPERTY_WIDTH"), 640);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_HEIGHT"), 360);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_X"), -160);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_Y"), -90);

movie_draw_to_screen(movie_screen, channel);

With width and height both zero, the same playback can fill destinations of different sizes:

movie_set_property(playback, openborconstant("MOVIE_PROPERTY_WIDTH"), 0);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_HEIGHT"), 0);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_X"), 0);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_OFFSET_Y"), 0);

movie_draw_to_screen(large_screen, channel);
movie_draw_to_screen(small_screen, channel);

Both calls draw the same retained frame. Changing dimensions or offsets changes its presentation without restarting playback.

Exact-black protection

Screen transparency settings can use RGB 0, 0, 0 as a transparent key when a subscreen is drawn later. Enable black protection when the movie's black areas should remain visible through such a composition:

movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_BLACK_FILTER"), 1
);

The GPU first resamples the video planes and converts the result to RGB. It then changes exact output black to RGB 1, 1, 1 when protection is enabled. Other output colors retain their values. This protection is disabled by default and applies to screen composition.

Movie resampling

MOVIE_PROPERTY_RESAMPLE selects the filter used when rendering the decoded video. It applies to screen composition and direct display.

Constant Sampling
DC_RESAMPLE_MOVIE Movie default; equivalent to bilinear.
DC_RESAMPLE_NEAREST Nearest-sample reconstruction.
DC_RESAMPLE_BILINEAR Linear reconstruction between neighboring samples.
DC_RESAMPLE_BICUBIC_CATMULL_ROM Catmull-Rom cubic reconstruction.
DC_RESAMPLE_BICUBIC_MITCHELL Mitchell cubic reconstruction.
DC_RESAMPLE_BICUBIC_BSPLINE B-spline cubic reconstruction.
DC_RESAMPLE_LANCZOS_2 Two-lobe Lanczos reconstruction.
DC_RESAMPLE_LANCZOS_3 Three-lobe Lanczos reconstruction.
movie_set_property(
    playback,
    openborconstant("MOVIE_PROPERTY_RESAMPLE"),
    openborconstant("DC_RESAMPLE_BICUBIC_MITCHELL")
);

int filter = movie_get_property(
    playback, openborconstant("MOVIE_PROPERTY_RESAMPLE")
);

The GPU reconstructs the Y, U, and V planes at their respective resolutions before converting to RGB. Changing this property takes effect when the frame is drawn again, including while playback is paused. It does not seek or restart decoding.

Movie resampling controls video-to-destination rendering. Drawmethod resampling can separately control a subsequent transformed drawscreen() operation. Final display filtering is another stage applied when presenting the completed game screen. See Drawmethod resampling.

Direct display presentation

movie_draw_to_yuv()

movie_draw_to_yuv(channel);

This function renders the retained movie frame directly to the display window and presents it immediately. It clears the window background, centers the movie using the selected logical display dimensions, and applies display brightness and gamma. The display's stretch setting can fill the window.

Logical display dimensions are scaled for the actual window. They are independent of the game screen resolution configured in video.txt; explicit movie width and height are not literal window-pixel extents. Movie X/Y offsets and exact-black protection are screen-composition controls and do not apply here.

Each direct-display call presents a complete movie view. Use screen composition to assemble captions, sprites, several movies, or other overlays into one frame. Direct presentation preserves the normal graphics resources, so ordinary screen rendering and presentation remain available. Stopping a directly presented movie clears its direct-presentation state.

For example, after acquiring an active playback:

movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_WIDTH"),
    openborconstant("MOVIE_SIZE_NATIVE")
);
movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_HEIGHT"),
    openborconstant("MOVIE_SIZE_NATIVE")
);

// Call when the controller wants to present the retained movie frame.
if(movie_get_property(playback, openborconstant("MOVIE_PROPERTY_ACTIVE")))
{
    movie_draw_to_yuv(movie_get_channel_index(playback));
}

Position, pause, speed, repeat, interruption, and sound routing use the same playback properties for either destination.

Playback timing and control

Position and duration use milliseconds. The playback clock begins when asynchronous decoder startup is ready. Drawing does not move the clock, and omitting drawing does not pause the movie.

While the movie owns an embedded audio stream, consumed audio provides the playback clock. Video follows that clock, with late frames discarded when necessary to preserve synchronization. Video-only playback uses the movie's own clock. If another audio producer replaces the movie's sound stream, the movie continues from a matching position on its own clock.

Position and seeking

Read MOVIE_PROPERTY_POSITION for the playback position. Write it to request a seek:

movie_set_property(
    playback, openborconstant("MOVIE_PROPERTY_POSITION"), 12500
);

This requests 12.5 seconds. Seeking reopens decoding asynchronously while retaining the displayed frame until replacement frames are ready. When duration is known, a seek at or beyond its end is clamped to the last available millisecond. MOVIE_PROPERTY_DURATION is read-only and remains zero until duration is known.

Use position changes for rewind controls and other backward navigation. Continuous negative-speed playback is not supported.

Pause

Set MOVIE_PROPERTY_PAUSED to 1 to hold the position and displayed frame and pause the movie's audio. Set it to 0 to resume.

movie_set_property(playback, openborconstant("MOVIE_PROPERTY_PAUSED"), 1);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_PAUSED"), 0);

Speed

MOVIE_PROPERTY_SPEED accepts finite nonnegative values. Normal speed is 1.0. Values below 1 slow playback; values above 1 accelerate it. Positive speed changes also change embedded-audio speed and pitch.

Rates above 16.0 are clamped to 16.0, and accepted rates are rounded to the nearest 0.001. Negative or nonfinite values report an error. Zero holds the position and pauses audio. Returning from zero to a positive rate reopens decoding at the held position.

movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 0.5);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 2.0);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_SPEED"), 1.0);

These statements select half speed, double speed, and normal speed respectively; use the statement matching the desired control action.

Repeat and interruption

Set MOVIE_PROPERTY_REPEAT to 1 to reopen playback from the beginning when it reaches its terminal frame. Scripts can implement a custom loop region by observing position and requesting a seek to its beginning.

MOVIE_PROPERTY_INTERRUPT defaults to 1. New Escape or normal movie-skip input stops interruptible playback during the engine update. Set it to 0 when a controller should handle stopping itself:

movie_set_property(playback, openborconstant("MOVIE_PROPERTY_REPEAT"), 1);
movie_set_property(playback, openborconstant("MOVIE_PROPERTY_INTERRUPT"), 0);

Embedded audio

Movie channels select playback objects. Sound channels select destinations in the audio mixer. Their indexes are separate: movie channels run from 0 through 63, and sound channels run from 0 through 4095.

Each playback initially selects sound channel 0, the music and media channel. Embedded audio replaces the occupant of its selected sound channel. Ordinary movie_play() leaves unrelated sound channels running, and a movie without audio leaves existing sound playback alone.

movie_set_sound_channel()

movie_set_sound_channel(playback, sound_channel)

Routes an active playback's embedded audio to the selected sound channel. Changing the destination reopens decoding asynchronously at the playback position. Selecting the already assigned channel leaves its routing in place. The destination is selected directly, so its existing audio is replaced without priority arbitration.

For simultaneous audible movies, assign separate sound channels immediately after starting each playback:

int source_a = movie_load("data/scenes/feed_a.webm");
int source_b = movie_load("data/scenes/feed_b.webm");

void playback_a = movie_play(source_a, 4);
movie_set_sound_channel(playback_a, 10);

void playback_b = movie_play(source_b, 5);
movie_set_sound_channel(playback_b, 11);

MOVIE_PROPERTY_SOUND_CHANNEL reports this routing and is read-only through the property API. Embedded streams also expose applicable controls through the sound-object API. Seek the movie through MOVIE_PROPERTY_POSITION so audio and video remain coordinated. See Audio Overview.

Movie object API

Use openborconstant() for property and loading-mode names. Channel indexes are ordinary integers.

Channel access

Function Result
movie_get_channel_object(channel) Engine-owned object for that channel, including an inactive channel.
movie_get_channel_index(playback) Index belonging to a valid playback object.
movie_get_channel_mask() Unsigned 64-bit activity mask with one bit per movie channel. Set bits identify active playback on their corresponding channels.

For a particular channel, read its active state directly:

void playback = movie_get_channel_object(5);
int active = movie_get_property(
    playback, openborconstant("MOVIE_PROPERTY_ACTIVE")
);

Property access

movie_get_property(playback, property)
movie_set_property(playback, property, value)

The getter returns the property's value. The setter returns no value. Invalid objects, property identifiers, values, and writes to read-only properties report script errors.

The following defaults describe a newly started playback. Stopping resets the channel; its source becomes invalid and position and duration become zero.

Property Access Default Meaning
MOVIE_PROPERTY_ACTIVE Read 1 after start Whether the channel owns active playback.
MOVIE_PROPERTY_BLACK_FILTER Read/write 0 Protect exact output black during screen composition.
MOVIE_PROPERTY_CHANNEL Read Acquired index Movie channel index.
MOVIE_PROPERTY_DURATION Read 0 until known Unsigned 64-bit duration in milliseconds.
MOVIE_PROPERTY_HEIGHT Read/write 0 Height selection; see Dimensions and offsets.
MOVIE_PROPERTY_INTERRUPT Read/write 1 Allow normal movie-skip input.
MOVIE_PROPERTY_OFFSET_X Read/write 0 Signed horizontal placement within a destination screen.
MOVIE_PROPERTY_OFFSET_Y Read/write 0 Signed vertical placement within a destination screen.
MOVIE_PROPERTY_PAUSED Read/write 0 Hold the playback clock and owned audio stream.
MOVIE_PROPERTY_POSITION Read/write 0 Unsigned 64-bit millisecond position. Writing requests a seek.
MOVIE_PROPERTY_REPEAT Read/write 0 Restart from the beginning at the terminal frame.
MOVIE_PROPERTY_RESAMPLE Read/write DC_RESAMPLE_MOVIE Filter used to render decoded video; the movie default is bilinear.
MOVIE_PROPERTY_SOUND_CHANNEL Read 0 Embedded-audio destination. Change with movie_set_sound_channel().
MOVIE_PROPERTY_SOURCE Read Played source Source ID associated with playback.
MOVIE_PROPERTY_SPEED Read/write 1.0 Forward playback rate, normalized to 0 through 16.
MOVIE_PROPERTY_WIDTH Read/write 0 Width selection; see Dimensions and offsets.

Boolean properties use zero for disabled and nonzero for enabled. Pause, position, speed, and sound-routing changes require active playback. Configure appearance, repeat, and interruption after starting playback because each start restores the defaults.

For a diagnostic listing of the public property map:

movie_get_property(playback, openborconstant("PROPERTY_ACCESS_DUMP"));

This writes the property listing to the engine log.

Blocking playback

Use blocking playback when a movie should complete or be interrupted before its calling script or scene continues.

playwebm()

playwebm(path [, noskip])
int result = playwebm("data/scenes/intro.webm", 0);

noskip defaults to 0, allowing normal skip input. Nonzero disables that input interruption.

Result Meaning
1 Movie completed.
0 Playback failed.
-1 Permitted input interrupted playback.

The function stops existing movie playbacks, opens a streamed source, and presents it directly using the WebM display dimensions. It services input and movie playback while blocking the caller. Width and height use MOVIE_SIZE_NATIVE, playback speed is normal, repeat is disabled, and movie resampling uses its bilinear default.

Movies with embedded audio request exclusive audio playback through sound channel 0. Silent movies allow existing music to continue. Screenshot capture renders the movie through the GPU into a capture screen before reading the completed pixels for the screenshot.

Cleanup completes decoder teardown and releases the temporary source before returning. Normal game rendering remains available after direct movie presentation.

Scene video command

video path [skipone] [noskip]

Both optional flags default to zero.

Setting Behavior
skipone 0 Interrupting a video skips the remaining scene media.
skipone 1 Interrupting a video skips it and continues with subsequent scene commands.
noskip 0 Normal movie-skip input is allowed.
noskip 1 Movie-skip input is disabled.

For example, allow skipping just this video while continuing the scene:

video data/scenes/intro.webm 1 0

Later silence commands still apply when interruption skips the remaining scene media.

The scene command uses the blocking player. Choose the movie_* functions when a controller needs asynchronous playback, screen composition, seeking, repeat, selectable resampling, or independent movie and sound channels.

See also