Topic: Game Cinematics

Hi,

Does anybody know how to add cinematics to game (i.e load a video and play it).

I looked at the wiki and it seems that there's no straight solution. Another thing i thought about is to convert the video to image sequence then animate it and play a sound but it seems like a bad solution .. Does anybody have ideas??

Re: Game Cinematics

Hi,

the engine doesn't have a integrated feature for reading video.

But you can use a 3rdparty library, like libtheora (to read ogg theora video) : http://www.theora.org/
I did it for a project some years ago, unfortunately I don't have the code anymore.

You read the stream and send the result to a texture using MRenderingContext

Or using FFMpeg maybe, but I never tried : http://ffmpeg.org/

Re: Game Cinematics

anael wrote:

Hi,

the engine doesn't have a integrated feature for reading video.

But you can use a 3rdparty library, like libtheora (to read ogg theora video) : http://www.theora.org/
I did it for a project some years ago, unfortunately I don't have the code anymore.

You read the stream and send the result to a texture using MRenderingContext

Or using FFMpeg maybe, but I never tried : http://ffmpeg.org/

Well, thanks for the fast reply. And that was really helpfull thanks.

Re: Game Cinematics

If you decided this is a task you want to take on, use OpenCV instead of LibTheora or FFMPEG. Because ...

1. OpenCV already uses those librarys for video playback
2. Getting OpenCV to play video on  texture is only a couple lines of code.
3. You get the added benefit of its builtin motion tracking, in a first person type game this feature could be used
to actualy look round a corner by slightly tilting and turning your head. Or controling a game in the sameway as Kinetic.

It would probable take 5min to get this feature implemented in the Maratis Engine and an hour for the Lua bindings. I could do it but everytime I even breath on those scon's build scripts they blow up in my face.

Last edited by zester (2013-01-11 18:46:01)

Re: Game Cinematics

zester wrote:

If you decided this is a task you want to take on, use OpenCV instead of LibTheora or FFMPEG. Because ...

1. OpenCV already uses those librarys for video playback
2. Getting OpenCV to play video on  texture is only a couple lines of code.
3. You get the added benefit of its builtin motion tracking, in a first person type game this feature could be used
to actualy look round a corner by slightly tilting and turning your head. Or controling a game in the sameway as Kinetic.

It would probable take 5min to get this feature implemented in the Maratis Engine and an hour for the Lua bindings. I could do it but everytime I even breath on those scon's build scripts they blow up in my face.

Thanks i'll consider using OpenCV specially if it's easier to implement. I don't know about scons or even lua that much i started learning it for maratis.

Re: Game Cinematics

Fady_osman wrote:
zester wrote:

If you decided this is a task you want to take on, use OpenCV instead of LibTheora or FFMPEG. Because ...

1. OpenCV already uses those librarys for video playback
2. Getting OpenCV to play video on  texture is only a couple lines of code.
3. You get the added benefit of its builtin motion tracking, in a first person type game this feature could be used
to actualy look round a corner by slightly tilting and turning your head. Or controling a game in the sameway as Kinetic.

It would probable take 5min to get this feature implemented in the Maratis Engine and an hour for the Lua bindings. I could do it but everytime I even breath on those scon's build scripts they blow up in my face.

Thanks i'll consider using OpenCV specially if it's easier to implement. I don't know about scons or even lua that much i started learning it for maratis.

I have nothing to offer in the way of scons but for C/C++ and Lua this might help give you a better understand on how to tie C and Lua

http://code.google.com/p/zester/wiki/Lua_C

Scripting in Lua is very simular to Javascript except lighter and faster unless your comparing lua's speed and ease of use to Qt5 and the V8 Javascript Engine in that case Qt5/V8 win hands down.

Last edited by zester (2013-01-11 19:18:09)

Re: Game Cinematics

I found this: http://code.google.com/p/liboggplayer/ as a potential candidate for helping achieve OGG video-playback functionality.

A Mac version of the library will have to be compiled, but I'm guessing we have some people here who can probably help out with that. smile

I could see this working as a plugin IF you're able to map the data streamed from the video as a texture while writing your game logic. Otherwise, I think it would be best if video-playback were a core engine feature, and you would access it through the visual editor.

Re: Game Cinematics

The down side of liboggplayer is the GPL license, it's not a huge problem but it's not the best in case of commercial game,
I think theora is more permissive, but I checked it long ago.

Re: Game Cinematics

Ah, okay. It's says it's LGPL v3, which I think is pretty liberal? I used this site: http://www.tldrlegal.com/license/gnu-le … gpl-3.0%29 to try to figure out if it was worth bothering with.

If it turns out that this is something I'd have to manually build using Theora/Vorbis directly, I'll probably put it on the shelf until I get used to the Maratis plugin interface.

EDIT:

Also, is it currently possible to call game object textures from Lua? My understanding is that that's the only way to get the data from the video onto a plane using a plugin interface. Please correct me if I'm wrong.

Last edited by sunnystormy (2014-01-28 21:37:31)

Re: Game Cinematics

I found this just now: http://sourceforge.net/projects/libtheoraplayer/

It has a BSD license. Will that be more permissive for commercial purposes, Anael?

EDIT:

More info here: http://libtheoraplayer.cateia.com/wiki/ … =Main_Page

Sample class here: http://libtheoraplayer.cateia.com/wiki/ … e=Tutorial

Last edited by sunnystormy (2014-01-29 18:50:30)

Re: Game Cinematics

it looks quite good, BSD is more adapted to commercial purpose,
and there is even support for H.264 on ios and mac !

Re: Game Cinematics

Hey, Anael. Glad you like it!

Is there a way of being able to manually map the texture of a game object through the engine's Lua interface? Please let me know.

Last edited by sunnystormy (2014-02-09 03:46:47)

Re: Game Cinematics

Sorry to double-post, but I haven't gotten a response yet:

I was looking over the documentation, and I'm still trying to figure out how to map the OGG Theora video data as a texture onto a game object passed through Lua into the C++ interface. Mind giving me a point in the right direction, Anael?

Thanks.

Re: Game Cinematics

Hi, sorry I missed this post.

First, here's how you will send the video data to a texture in C++ :

MEngine * engine = MEngine::getInstance();
MSystemContext * system = engine->getSystemContext();
MRenderingContext * render = engine->getRenderingContext();
MLevel * level = engine->getLevel();

// get a texture reference that will receive the video stream
char globalFilename[256];
getGlobalFilename(globalFilename, system->getWorkingDirectory(), name); // "name" if a local path like "maps/dummy.png"
MTextureRef * texture = level->loadTexture(globalFilename, 0, 0);

// send the video clip data to the texture
TheoraVideoFrame * f = clip->getNextFrame();
if(f)
{
    unsigned int textureId = texture->getTextureId();
    if(textureId == 0)
    {
        render->createTexture(&textureId);
        texture->setTextureId(textureId);
    }

    render->bindTexture(textureId);
    render->setTextureFilterMode(M_TEX_FILTER_LINEAR, M_TEX_FILTER_LINEAR);
    render->setTextureUWrapMode(M_WRAP_CLAMP);
    render->setTextureVWrapMode(M_WRAP_CLAMP);
    render->texImage(0, clip->getWidth(), clip->getHeight(), M_UBYTE, M_RGB, f->getBuffer());
}

Re: Game Cinematics

To bind c++ code in lua, look at this doc : http://wiki.maratis3d.org/index.php?tit … iptContext

What you could do is something like that :

TheoraVideoManager * mgr = NULL;

// bind all your functions here (see wiki)

void StartPlugin(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext* script = engine->getScriptContext();

    // create the video manager
    mgr = new TheoraVideoManager();

    // register the script functions
    script->addFunction("loadVideoClip", loadVideoClip);
    script->addFunction("updateVideoClip", updateVideoClip);
    script->addFunction("playClip", playClip);
    script->addFunction("pauseClip", pauseClip);
    script->addFunction("stopClip", stopClip);
    script->addFunction("destroyVideoClip", destroyVideoClip);
    //etc...
}

void EndPlugin(void)
{
    // delete the video manager
    SAFE_DELETE(mgr);
}

Re: Game Cinematics

For the sound I need to check, try to do that first and get back to me.

Re: Game Cinematics

Hi, Anael. Thank you very much for posting those code samples. It looks like this may take a while because the libtheoraplayer API is only built for Windows and Mac OSX/iOS (at least, that's what's indicated on the site). I think (because I'm a Linux user) I'm going to have to build my own Theora video API from scratch.

When I make some progress, I will be sure to let you know. Thanks again.