Video Playback with GFxVideo

Overview

Playing videos via Scaleform requires the GFxVideo license. This chapter explains how videos are run in fullscreen and how they can be mapped to a texture.

Converting a Video

To play a video with Scaleform you first have to convert the video file into the .usm format. The GFxVideo SDK comes with the tool ScaleformVideoEncoder.exe which allows converting .avi files into .usm format.

Fullscreen Video playback

Using the flow node Video:VideoPlayback is the easiest way to get an USM video onto the screen. All you need to do is to specify the filename of the .usm file.

The lookup path for files is inside: <root>/GameSDK/Libs/UI

If this does not give you enough control, you can alternatively trigger the video playback via UI:Display:Display. Your setup could be similar to the following screenshot:

Keep in mind to call "hide" of UI:Display:Display respectively.

Video playback on a texture

CRYENGINE allows video playback on any material by replacing the diffuse texture with the USM player.

If the extended video playback setup has been set up already, you just need to do a couple of changes to get the video rendered to a texture.

First specify an arbitrary InstanceID. In the following example we have used number 3. As long we have not assigned this InstanceID to a material, the rendering will still happen in fullscreen.

Tell the material which USM video is played on the texture, by adding the Element USMPlayer into the Diffuse channel. The @number defines the InstanceID you were using in the previous flowgraph setup.

In addition, set the TexType to Auto 2D-Map (or Dynamic 2D-Map in CRYENGINE 3.7 and beyond). After assigning the material to an object, the video will be played on that object at game startup.

Load video into CRYENGINE

There are two ways to load a video into CRYENGINE:

  1. Load the usm directly. Follow Scaleform GFx and CRYENGINE by loading a .usm file instead of .gfx.
  2. Embed a “linked video” object into your Flash asset.

Embed a “linked video” object into your Flash asset

Another way is to place a “linked video” object into your Flash file, load the usm file with a NetStream object and attach it to your linked video object.

To add a video object to your Flash asset, right-click on the library and choose "New Video…" from the context menu.

Place the video object onto the stage and set the instance name, e.g. "MyVideo".

Then add following ActionScript code in your fla file:

// enable gfx extensions
_global.gfxExtensions = true;
 
// create new NetStream object with an NetConnection object
var NetC = new NetConnection();
NetC.connect(null);2
ns = new NetStream(NetC);
 
// attach NetStream to the linked video object on stage
MyVideo.attachVideo(ns);
 
// play the video
onLoad = function()
{
  ns.play("myvideo.usm");
}

If you want to get information about the video state e.g. to send notifications via fscommand to your C++ code you can add an "onStatus" function to your ActionScript:

// listening to video events
ns.onStatus = function (infoObject)
{
    if (infoObject.level == "status")
    {
    if(infoObject.code == "NetStream.Play.Start")
        fsCommand("onVideoStart");
    else if (infoObject.code == "NetStream.Play.Stop")
        fsCommand("onVideoStop");
    }
    else if (infoObject.level == "error")
    {
        if (infoObject.code == "NetStream.Play.StreamNotFound")
        fsCommand("onVideoNotFound");
    }
}