Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: scotch on Tue 24/06/2008 14:48:58

Title: Plugin: ags_theora Video Player
Post by: scotch on Tue 24/06/2008 14:48:58
I made this for background animation in my own game, thought I'd package it up for release... hope it's useful for someone. Essentially it's a video playing plugin, with an internal ogg/theora decoder. Theora is a free video codec targetted to compete with well known MPEG4 codecs (xvid, divx etc). Quality isn't quite there yet but close enough, and the encoder is still being improved.

Generally be careful with it because as I said, it's for my own use and may not work in unusual situations. For a start it only supports videos encoded in YUV420 which happens to be most of them. Also seeking doesn't align to keyframes so there will be momentary tearing when seeking to a non keyframe, tell me if you need that fixed. Doesn't interpolate chroma though I suppose it should. If anyone actually uses it they can tell me what they want adjusted for their purposes.

plugin download (http://www.caverider.com/plugins/ags_theora.dll) / demonstration download (http://www.caverider.com/plugins/ags_theora_005.zip) (try it in d3d mode to see the rotating etc if you care)

Interface

/* values specifying the "layer" of the scene to draw the video over */
enum RenderStage {
    RsBackground,
    RsScene,
    RsUI,
    RsOverlay
};

enum RelativeTo {
    RtRoom,
    RtScreen,
    RtScreenPixels
}

/* Each Theora instance represents an open video file. */
struct Theora {
    // opening
    static Theora* open(string name);
   
    // positioning
    void NextFrame();       // move to next frame
    void Sync(float time);  // advance 0 or more frames to sync with time
    void Seek(float time);  // attempt to seek to a position
   
    // status
    readonly bool broken;   // the video is bad and can no longer render properly
    readonly bool ended;    // end of video was hit, no more new frames will appear unless looped
    readonly float time;    // current time of video (may be inaccurate)
    readonly float fps;     // fps of encoded video, you don't have to stick to it if you don't want to
    readonly int width;
    readonly int height;
    bool loop;              // enable/disable automatic looping

    // rendering
    void Draw(RenderStage stage, int left, int top, RelativeTo);
    void DrawEx(RenderStage stage, float cx, float cy, float xscale, float yscale, float rotation, RelativeTo); // scale/rotation can only be used if d3d renderer is being used!
}


Advantages of this over regular video playing are
. doesn't require user to have installed any codecs, while providing better compression than available by default
. completely free format for free and commercial use
. draw videos within your scene and onto sprites for special effects
. (hopefully) no black frames or other signs of switching between game and video

Disadvantages
. is a plugin, therefore only works on windows engine right now
. decoding is fairly slow, YUV->RGB conversion needs to be done in software which is an additional overhead, not sure what the minimum specs for a full screen 640x480 30fps video would be, but somewhat higher than the regular video player. However, I did have someone test the demo on an ASUS EEE PC with 900mhz processor and it seemed fine.
. does not do audio. AGS already does audio, if you want you can sync up a sound/music file with the video with script. The main purpose of the plugin is background animation which does not require audio.
. requires some scripting to get it going, videos don't play on their own (although I could make them if people really want)
. only supports 32 bit mode at present
. software mode doesn't scale videos, therefore playing your game at the wrong resolution (scale filters are fine) will look bad. I don't think AGS should have this option on the setup though, personally.
. one unpredictable lockup issue which occurs from time to time when exiting in d3d mode, which I will fix some time, but it is fairly rare for me.

Details

It's quite basic as it is, I only need it for background animations, but if anyone uses it and would like features go ahead and suggest them. Support for 16 bit mode and video file obfuscation might be worth doing.

Here's the room script from the demo game, as an example of how to play a video on the background (and how to scale and rotate one in D3D mode.

Theora* video;
float rot = 0.0;

function repeatedly_execute_always() {
    if(video) {
      video.DrawEx(DsBackground, 160.0, 120.0, 0.5, 0.5, 0.0, RtScreen);
      if(System.HardwareAcceleration) video.DrawEx(DsScene, 260.0, 120.0, 0.25, 0.25, rot, RtScreen);
      video.NextFrame();
      rot += 0.2;
    }
}

function room_Load() {
  video = Theora.Open("theora.ogg");
  video.loop = true; 
  SetGameSpeed(24); // you don't need to use the same fps as the video like this, but it's easiest this way
}


I should also say, if you have a video open and go to another room, that video is still open! When you no longer need a video set the pointer to null. You can do this on exit, and load it on enter if you want. Just in case someone loads a video background in every room and wonders why it's taking 100s of MB of RAM.
Title: Re: Plugin: ags_theora Video Player
Post by: Pumaman on Tue 24/06/2008 18:48:29
Looks great scotch, excellent work!!

In D3D mode I do get the mini video overlay, but it doesn't seem to rotate?
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Tue 24/06/2008 18:51:13
Oh yes, I appear to have broken that when I removed another bit from the room script before release, I'll update it. And updating it I see I broke another rotation related thing so I'll have to update it again later, anyway... rotation probably isn't likely to get used much, glad it works in general.
Title: Re: Plugin: ags_theora Video Player
Post by: LimpingFish on Tue 24/06/2008 19:00:47
Wow! Excellent work indeed, Scotch! Very smooth playback. Is there a minimum and maximum bitrate/fps setting for the video, or does the plugin only work with video encoded to a set bitrate/fps?
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Tue 24/06/2008 19:15:07
Any bitrate or fps is fine (if you replace theora.ogg in the example it will hopefully work), you don't need to lock your game speed to the video speed as I did there, that's just the most convienient way. If your videos are different speed you could do something like: "video.Sync(gameFramesPassed * (1.0 / IntToFloat(GetGameSpeed())));" instead of using NextFrame and it'd run at the right rate whatever your game speed is, just not updating every frame. Hopefully.
Title: Re: Plugin: ags_theora Video Player
Post by: GarageGothic on Tue 24/06/2008 19:24:33
Very cool. This looks like it will solve a lot of problems for people working with FMV or prerendered cutscenes. I've seen several people in the tech forums having problems with black flashes when starting a video file using the internal video player, but rendering straight to background should solve that. I'm also quite impressed with the amount of animation you can store at that quality in a 6MB video file.

The best thing would of course be full integration with AGS, so it wouldn't need Windows to work. But I wonder, would it without further integration be possible to store all videos in a container format like speech.vox, so that players couldn't open the files outside the game? (On the other hand, I always did feel like a 1ee7 hax0r when I found ways to open external cutscene files from commercial games using smacker or deluxe paint).
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Tue 24/06/2008 19:40:12
Well like I said, obfuscating the videos is an option if someone cares enough, it's slightly easier to work with plain files but I'm willing to put in the work if someone is making a good video heavy game. An ogg theora file renamed to .dat is fairly obscure as it is, but yeah it'll still play in VLC and I can understand wanting to hide them better.

The video there is actually lower quality than you might be able to squeeze out at the same bitrate because it's cropped then transcoded from another medium bitrate video.

I also think this kind of thing should end up in the core but for now a plugin isn't too bad, considering the state of the other ports, and how video doesn't work on them anyway.
Title: Re: Plugin: ags_theora Video Player
Post by: deadsuperhero on Wed 25/06/2008 06:47:49
Alright! Free video codecs supported by AGS! It'll make porting the games (someday) easier, and it won't be legally encumbered!
Title: Re: Plugin: ags_theora Video Player
Post by: deltamatrix on Sat 28/06/2008 17:44:10
Good job. But I still think AGS ought to bring native support for this codec. Native support for at least one open source codec is good for the Linux and Mac OS X users who can't play videos in AGS.
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Sat 28/06/2008 18:27:52
I agree, but I also think the state of the ports makes those kinds of arguments unconvincing for now, unfortunately. If theora support went into the engine how many years until a new Mac/Linux engine appears, if it ever does? Unless the engine is a collaborative project maintaining ports seems rather difficult. Mac/Linux users seem better off on emulators.
Title: Re: Plugin: ags_theora Video Player
Post by: Ali on Thu 03/07/2008 15:17:14
This looks very impressive (as does the first glimpse I've had of big buck bunny)!

Great work, this will really help broaden the kinds of games we can make.
Title: Re: Plugin: ags_theora Video Player
Post by: AJA on Sat 05/07/2008 16:41:43
Great job, scotch! This'll be really useful.

Found a bug, though: If there's a theora video playing in windows (I use ffdshow for decoding, if that matters) and video playback starts in the demo game, both the game and the video player crash.
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Sat 05/07/2008 16:46:36
That sounds quite odd, the plugin doesn't interact with any other codecs. I can't replicate it myself.
Title: Re: Plugin: ags_theora Video Player
Post by: AJA on Sat 05/07/2008 17:37:27
Okay, that's weird. Now it seems to be working just fine. Never mind. :P
Title: Re: Plugin: ags_theora Video Player
Post by: Dusk on Sun 03/08/2008 19:17:14
*** EDIT ***
I managed to find a workaround introducing another room, so feel free to ignore the following :)

***********

What can cause the video to be considered "broken"?

I've prepared a "video playing" room for some cutscenes... the idea is to set a String variable (in a struct with other things, but that's not important here) to the video to load, then move the player to this special room and let the movie play. When the movie ends, I want another changeRoom...

Of course my target are full screen video cutscenes... but I'm having problems.
If I start the game from the "movie playing room", the video playing works smoothly and the room change at the end works.

If I start the game from another room, and then perform a player.ChangeRoom to the video playing room, the game crashes. So I added a "broken" check, and the video is reported as broken.

Why?
What could be interfering?

Thanks... and BTW, great plugin here, I'm one of the "Yeah we want Theora support in AGS" guys  :)




// video playing room script file

Theora* video;

function room_Load() {
  videoCut.played = false;
  video = Theora.Open(videoCut.fileName);
  video.loop = false;
}

function repeatedly_execute_always() {
  if(video) {
     if (video.broken) AbortGame("VIDEO BROKEN!");
     if (!video.ended) {     
        video.DrawEx(DsOverlay, 160.0, 120.0, 0.5, 0.5, 0.0, RtScreen);
        video.NextFrame();
      } else {
        videoCut.played = true;       
      }
  }
}

function room_RepExec() {
  if (videoCut.played) player.ChangeRoom(203);
}


Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Mon 04/08/2008 03:40:06
I don't know what's causing the problem with that setup but I will try it some time, glad you found a workaround for now.
Title: Re: Plugin: ags_theora Video Player
Post by: visionastral on Wed 13/08/2008 14:09:02
Hello Scotch, excuse my english please  :P

I found an issue with the theora plugin:
When you make a video background and run with Direct3D, Flipped sprites don't render!
Normal sprites are ok, it's just flipped sprites that disapear.
But it only happens when you run AGS in Direct3D.
It's weird, but it happens with everything you flip.
It's annoying because I'm coding the dialog system of my game and I was making big close-ups of the characters with huge sprites, fliping depending on the players position, but when you flip the sprite, it only disapears!

Another thing:

PLEASE PLEASE PLEASE allow video obfuscation!!!

I DO CARE A LOT!
Let me explain:
I'm making a game with plenty of full motion video, not only for intros and the like. For backgrounds, scene animations, quicktime events...
So, if I cannot obfuscate my video, every one could see the end of the game without playing it!
Of course, I know what some one could say: "you just have to change the extension bla bla bla"
No no no, if you just drop the file in windows media player, it will say "the file haven't the good extension" but it will play it!

Another thing wich would be realy great is sound support. Specialy the ability to mix the sound of the theora video with the background sound of AGS.
This way you don't loose continuity introducing video sequences because you don't break the background music.
However, this isn't so important for me than video obfuscation, because I'm already doing this by myself inside AGS along with a module wich load theora videos on demand and take care of playing them with their respective delays.

Another thing that makes me wonder:
How about a DESTROY method to explicitly clear memory from videos wich you won't run anymore??
I know about all the good things about "automatic garbage collector" but I'm from the old school, I would rather want to free memory by myself, just to be sure there isn't memory leaks  ::)

Of course, when the theora module will be finished, I'll upload it.
Right now it takes care of loading and managing up to 100 videos, allowing the user to load videos with only 1 function call and the module takes care of playing them at good delay.

However, I'm having troubles with the bottom of the video:
Imagine you have a background and don't wants to make a video of ALL the screen, but just the parts wich move. This will give you the ability to make multiple zones of animations at diferent playback rates, wich is much more interesting than having only one ciclic loop over the entire screen.
The module I'm making started with this goal.
However, the bottom of the videos don't render seamlessly, it makes me a green rectangle at the bottom of the video from left to right with variable height from video to video.
I suppose this is due to enconding chunks of the compression, that's why I made several trys making the video power of 2,4,8 and 16; but the green rectangle still appears at the bottom, in the best case, it becomes just a line, but still.

The main goal is to integrate little videos into the background seamlessly. It was a problem with the encoder changing gamma and contrast, but after spending hours trying, I finally found the correct setings to work around this, so the last issue is this green rectangle at the bottom of the videos.
After that, the module should be very useful for everyone.

Another thing that is a little problematic is the walk-behind zones being rendered over the videos.
I know it's because of AGS's design, but I wonder if something could be done to draw the videos directly to the buffer AGS take to draw the walk-behind zones of.


EDIT: I'm using the AGS beta release right now, perhaps something changed that made the flipped sprites to do not render over the videos, I have allready told Chris Jones about that, but, since it's a problem with your plugin, I thought I should told you about it.
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Wed 13/08/2008 22:51:24
Flipped sprites: I'll sort that out.
Obfuscation: Still not convinced it matters, but I might do it.
Sound: I don't have any intention of doing that because I have no idea how to do it reliably while AGS has the sound device.
Memory leaks: Set the pointer to null and it will be destroyed.
Walkbehinds: I suppose I could make it work... I can't see it getting used much but maybe I'll do it.
Green rectangle: I haven't seen this happen.
Title: Re: Plugin: ags_theora Video Player
Post by: naltimari on Wed 13/08/2008 22:59:34
Quote from: visionastral on Wed 13/08/2008 14:09:02
PLEASE PLEASE PLEASE allow video obfuscation!!!

That's not just a matter of a video plugin, in my point of view. But in case you want to try it, I came across something that should allow you to do that.

It's a project called Pismo File Mount (http://www.pismotechnic.com/pfm/). I quote the site:

"Encrypted and/or compressed folders can be created that exist as simple files while locked, but become file system folders when unlocked. Contents can be viewed, edited, and executed, without copying to unprotected storage."

Among other things.
Title: Re: Plugin: ags_theora Video Player
Post by: visionastral on Wed 13/08/2008 23:02:30
Wow, that was brief but acurate  ;)
Thank you very much Scotch.  ;D

Naltimari, I'll check this out right now, thank you!

(how friendly the people in this forum is  ;) )
Title: Re: Plugin: ags_theora Video Player
Post by: Dusk on Thu 14/08/2008 01:39:48
Mmm have you looked at ReadRawChar and WriteRawChar?
Maybe if your videos aren't too large you could split the header bytes (so that players should refuse to play the files) and the main data and, when a video is to be played,  do something like


File *okVideo = File.Open("temp.tmp", eFileWrite);
File *unplayableVideo = File.Open("unreadable.dat", eFileRead);
File *videoHeader = File.Open("someheaderbytes.dat", eFileRead);
if (okVideo == null || unplayableVideo == null)
  AbortGame("Error opening files.");
else {

  while (!videoHeader.EOF)
     okVideo.WriteRawChar(videoHeader.ReadRawChar());
  videoHeader.Close(); 
  while (!unplayableVideoHeader.EOF)
     okVideo.WriteRawChar(unplayableVideo.ReadRawChar());
  unplayableVideo.Close();
  okVideo.Close(); 
}

Then you play temp.tmp and when you've finished you delete it with File.Delete("temp.tmp");

To avoid delays in starting the video, you should pre-cache the next-to-play-one.
I think that you can't do better in AGS because AFAIK there's no way to seek into the files and write specific bytes to them (that would allow to overwrite a bad header with a correct header "in place" instead of creating a new file).

If you try this stuff and this happens to work not-too-bad-and-slowly, there might be infinite variations/complications instead of just concatenating two "good" files.
Some ideas:
- add something to the byte values of the good file and subtract the same while creating the new file (using the modulo of course, something like ROT13 with binary values)
- having a single, big binary file composed of your concatenated movies, and an index that tells where to start and stop reading to cut a specific movie from the blob

Of course this isn't nothing that can't be circumvented by a skilled user (that, simply, can copy the temporary file while it's playing), but if you just want to avoid that everyone can see your movie files just dragging them into a movie player, I think that's more than enough. :)

bye,
D.
Title: Re: Plugin: ags_theora Video Player
Post by: scotch on Thu 14/08/2008 02:15:41
Someone produced some code for doing just that a while ago, the problem is that writing one byte at a time is incredibly slow, and it only managed a few KB a second. Considering that videos can be tens or hundreds of MB it's not practical. I'll put obfuscation and packing in the next release but I'm not sure if that'll be today or after Mittens.
Title: Re: Plugin: ags_theora Video Player
Post by: visionastral on Thu 14/08/2008 15:38:33
Dusk, I thought to do just that but, as Scotch has confirmed, I thought it would be extremely slow inside AGS.
If AGS could run external aplications, one could do an external exe to do the binary shift and create a temporary file for the theora plugin.
Sadly, AGS don't have the ability to do a simple "shell" command execute.
I think it will be my first post in the Wish List...

Scotch, you make me a happy man knowing you will integrate this inside the DLL :)
However, if you do it, please let us complement the obfuscation simply with a password (doing binary shifts or rotations would be easy and marvelous, and I don't think it should slow down anything.)

But, hey, it's your plugin after all, I'm already very happy to have it the way it is right now!
Thank you for sharing this with us :)
Title: Re: Plugin: ags_theora Video Player
Post by: xenogia on Sat 23/08/2008 10:11:12
Okay I put the global code in globalscript.asc and I keep getting the following error.  What does this mean?

'relativeto' is already defined

how can this be?

I realise now it must be put in the ash file, but still getting the same issue.
Title: Re: Plugin: ags_theora Video Player
Post by: PixelPerfect on Sat 20/09/2008 15:11:57
Yeah I can't get it working either. Same problem as Xenogia. Maybe I'm doing something wrong? Video file plays fine when replaced in the demo so it's not that. Should the OP's upper example code really go to the global script?

EDIT: No takers? I guess I won't be using theora then.
Title: Re: Plugin: ags_theora Video Player
Post by: Anomaly on Sun 30/11/2008 00:04:41
could you use this for (virtually limitless layers of) background parallaxing?

like .. player walks left.. play video of parallaxing background scenery...
player walks left.. reverse the footage?
scale footage playback rate according to current game speed?


mm?

or forward / backward / turning corners "dungeon master" type games scrolling for that matter.

I'm not  scripting genius, just started with AGS. but I'm very curious about this plugin.

also i think it could be used for Don Bluth type games.. Dragon's Layer .. Space Ace etc...

-
Title: Re: Plugin: ags_theora Video Player
Post by: xenogia on Thu 23/04/2009 03:15:02
Just a quick question..

How do you set the pointer to null?
Title: Re: Plugin: ags_theora Video Player
Post by: guitar_hero on Wed 19/08/2009 18:39:55
Can anyone tell me how I get the ags_theora-Plugin to play a video?
I need the video playing in the background in a special area of the screen. I can't use an animation or PlayVideo().
I tried to copy the code from this thread but it doesn't work. I have the plugin placed in the right folder and it's active, the vid I want to play is in the "compiled"- folder. Please give me a hint where to place which piece of code.
Title: Re: Plugin: ags_theora Video Player
Post by: goldensox on Wed 16/09/2009 01:51:47
You guys think it is possible to make something like Strangehood with this plugin? I mean... I can totally see it.
Title: Re: Plugin: ags_theora Video Player
Post by: neseliadam on Fri 16/10/2009 08:49:44
Can anyone tell me how I get the ags_theora-Plugin to work ! it doesn't work. i copy the first code to globals script, it doesn't work.. and the error message is "RelativeTo has already defined" !!!

why didn't you put a sample project to zip?or any documents,help? i need to use this plugin,please help meeeeeeeeee !
Title: Re: Plugin: ags_theora Video Player
Post by: neseliadam on Sat 17/10/2009 15:08:58
anyone hear meeeee :( please hellllllllp :(((((
Title: Re: Plugin: ags_theora Video Player
Post by: Matti on Sat 17/10/2009 16:20:01
Double posting won't help you... ever.

There's the code of the demo at the end of the first post. That's what you need.
Title: Re: Plugin: ags_theora Video Player
Post by: neseliadam on Sun 18/10/2009 01:14:34
you mean this ?
Theora* video;
float rot = 0.0;

function repeatedly_execute_always() {
    if(video) {
      video.DrawEx(DsBackground, 160.0, 120.0, 0.5, 0.5, 0.0, RtScreen);
      if(System.HardwareAcceleration) video.DrawEx(DsScene, 260.0, 120.0, 0.25, 0.25, rot, RtScreen);
      video.NextFrame();
      rot += 0.2;
    }
}

function room_Load() {
  video = Theora.Open("theora.ogg");
  video.loop = true; 
  SetGameSpeed(24); // you don't need to use the same fps as the video like this, but it's easiest this way
}



i've tried to copy this code to room, it doesn't work.. this code don't load anything..plugin is on,code is okey,what is the next move :) don't be an enemy for repeting posts..i am searching an answer, good answer..
Title: Re: Plugin: ags_theora Video Player
Post by: neseliadam on Sun 18/10/2009 01:18:31
and i copy the video from demo with same name to my working folder and compiled folder..when i'm build the project, ags automtically copy the plugins dll to compiled folder..

what am i skipped , what is wrong i don't understand. if you help me, i'll give you a hug my friend..because this is my nigtmare !
Title: Re: Plugin: ags_theora Video Player
Post by: monkey0506 on Sun 18/10/2009 02:37:43
Quote from: neseliadam on Sun 18/10/2009 01:14:34i've tried to copy this code to room, it doesn't work.. this code don't load anything..

Simply copying the above code won't work. The room_Load function is not a standard built-in event like game_start or repeatedly_execute. The name of the room_Load function (unlike game_start, etc.) is not fixed. You can name the function whatever you want. And until it's properly linked it won't work at all.

Let me explain what I mean by "linking" the function. The function is called "room_Load" because that is the default name for the function. However if you are just pasting that code into the room script, the editor doesn't know what the function is. As I said, it's not a standardized name, though it is the default name.

When you have the room open (the actual room, not just the script) in the editor, you should see a Lightning Bolt icon above the room properties. Click on this. This takes you to the room events. There should be an option that says "Player enters room (before fade-in)". In the textbox beside this you must make sure that it has the exact text of "room_Load" (without quotes), same spelling, and same capitalization. Then when you run your game again AGS will know to call the function when the room is loaded and it should then be working.

As I told you in the PM, I've never used this plugin so if you need technical help directly involving the plugin I unfortunately can't help there. But it seems that what you first need is a more basic understanding of how to use AGS.

Also, when you're told not to double post it's not because anyone is trying to stop you from getting an answer or "be an enemy" toward you. It is because quite simply it is against the rules of the forums. Neither Mr Matti nor myself are moderators so it's not our place to go around enforcing rules and whatnot, but the members here do try to watch out for each other and tip each other off when we might be headed the wrong way. As I said before, just be patient. Trust me, it'll help. ;)
Title: Re: Plugin: ags_theora Video Player
Post by: neseliadam on Sun 18/10/2009 02:55:31
IT'S WORKINNNGGGGG WORKIIIIIIIIIIING :))))))))))))))))))))))
THANK YOU MAN THANK YOUUUUUUUUUUUUUUUUUUUUUUUU

I LOVE YOUUUUUUU :))))

i have made a mistake exactly you right ! the room script name is true,but repeatetly execute's name is false :) i have  check your message and look what was i found :

room_RepExec() :)) but i paste the original script repeatedly_execute_always() :))))))

thank you.. i will send you a link soon and you can check my full motion video game demo :)

but it's short now.. wish me everything.. i am a professional musician, if you need game ,tv advert,movie music just tell me :)

thank you again, thousands of tenk you,god bless you monkey :))))

Title: Re: Plugin: ags_theora Video Player
Post by: xenogia on Mon 15/02/2010 08:28:04
Once again after all this time I thought I would try and use this plugin again, but alas same problem..

Ogg_Theora.asc(10): Error (line 10): 'RelativeTo' is already defined

Here is my code


function repeatedly_execute_always() {
    if(video) {
      video.DrawEx(DsBackground, 160.0, 120.0, 0.5, 0.5, 0.0, RtScreen);
      video.NextFrame();
    }
}
function room_Load()
{
video = Theora.Open("video.ogv");
  video.loop = true;
  SetGameSpeed(24); // you don't need to use the same fps as the video like this, but it's easiest this way
}


And I put the inital plugin code into a new script as follows into an ogg_theora.asc module:


// new module script
/* values specifying the "layer" of the scene to draw the video over */
enum RenderStage {
    RsBackground,
    RsScene,
    RsUI,
    RsOverlay
};

enum RelativeTo {
    RtRoom,
    RtScreen,
    RtScreenPixels
}

/* Each Theora instance represents an open video file. */
struct Theora {
    // opening
    static Theora* open(string name);
   
    // positioning
    void NextFrame();       // move to next frame
    void Sync(float time);  // advance 0 or more frames to sync with time
    void Seek(float time);  // attempt to seek to a position
   
    // status
    readonly bool broken;   // the video is bad and can no longer render properly
    readonly bool ended;    // end of video was hit, no more new frames will appear unless looped
    readonly float time;    // current time of video (may be inaccurate)
    readonly float fps;     // fps of encoded video, you don't have to stick to it if you don't want to
    readonly int width;
    readonly int height;
    bool loop;              // enable/disable automatic looping

    // rendering
    void Draw(RenderStage stage, int left, int top, RelativeTo);
    void DrawEx(RenderStage stage, float cx, float cy, float xscale, float yscale, float rotation, RelativeTo); // scale/rotation can only be used if d3d renderer is being used!
}
Title: Re: Plugin: ags_theora Video Player
Post by: AJA on Tue 16/02/2010 14:52:45
Just get rid of the module code. The plugin has already defined that header script. That's the reason for the error.
Title: Re: Plugin: ags_theora Video Player
Post by: xenogia on Tue 16/02/2010 19:25:48
Yeah I realised that after ProgZMax helped me out.
Title: Re: Plugin: ags_theora Video Player
Post by: Willdon on Wed 21/04/2010 17:38:59
I'm trying to write the code so when I click on a hotspot, the video is overlaid full-screen. Any Ideas how to do this?
Title: Re: Plugin: ags_theora Video Player
Post by: xenogia on Wed 21/04/2010 22:12:03
Here you go:



int FMVX; // x co-ordinate of video
int FMVY; // y co-ordinate of video
int VideoCut; // tells AGS when the video needs to be played

function repeatedly_execute_always()
{
    if (VideoCut == 1) { // Play FMV
if (video) {
if (!video.ended) {
video.Draw(DsOverlay, FMVX, FMVY, RtScreenPixels);
video.NextFrame ();
}
             else {
                VideoCut = 0;
        }

    }
}

function item_interact()
{
              SetGameSpeed (24);
Wait (10);
      VideoCut = 1;
FMVX = 70;
FMVY = 130;
video = Theora.Open("assets/vid.ogv");
video.loop = false;

while (VideoCut != 2) Wait (1);
video = null;
Wait (10);
SetGameSpeed (40);



All this code is the room, nowhere else.
Title: Re: Plugin: ags_theora Video Player
Post by: Willdon on Wed 21/04/2010 22:44:45
Quote from: Xenogia on Wed 21/04/2010 22:12:03
Here you go:



int FMVX; // x co-ordinate of video
int FMVY; // y co-ordinate of video
int VideoCut; // tells AGS when the video needs to be played

function repeatedly_execute_always()
{
     if (VideoCut == 1) { // Play FMV
if (video) {
if (!video.ended) {
video.Draw(DsOverlay, FMVX, FMVY, RtScreenPixels);
video.NextFrame ();
}
              else {
                 VideoCut = 0;
         }

     }
}

function item_interact()
{
     SetGameSpeed (24);
Wait (10);
       VideoCut = 1;
FMVX = 70;
FMVY = 130;
video = Theora.Open("assets/vid.ogv");
video.loop = false;

while (VideoCut != 2) Wait (1);
video = null;
Wait (10);
SetGameSpeed (40);



All this code is the room, nowhere else.

:)  You just made my day! Thank you so much! 


How's your game going?
Title: Re: Plugin: ags_theora Video Player
Post by: theo on Thu 23/09/2010 20:58:22
I'm currently experimenting with this plugin to draw animated backdrops for chapter two of The Journey Down, and am experiencing two issues, I was hoping someone here might be able to shed some light on these:

* No matter what method I use to crate my .ogv files, the game ALWAYS starts out by rendering the first frame 100% pink. Once it's looping, it's gone. Just the very, very first frame of the first time. Any thoughts on this?

* As Willdon (I think) stated, walk-behinds override the animation, is there any way to work around this problem?

-

Is this plugin perhaps not the way for me to go? Are there any alternatives?

Sorry for digging up this old thread. I realize this may cause some confusion but this was the obvious place to post my questions.
Title: Re: Plugin: ags_theora Video Player
Post by: goodohman on Thu 04/11/2010 02:35:01
Hi there.

Thank you very much for the great plugin.

Could you help me?
I can't make sense of the x,y coords!!
They don't seem to correspond to the room coords, no matter what kind of relativity I choose.

Thanks!
Title: Re: Plugin: ags_theora Video Player
Post by: goodohman on Fri 05/11/2010 03:01:15
no response yet, but another problem suddenly popped up - and maybe they are related in a way?
Theora *vid=open() will always return null if inside the editor. it won't regardless of debug/non-debug mode!
BUT (and it's a big one) - if I compile an EXE, it does load the video.
Anything?
I checked Dx5 and D3D and original DLL and ? and?
Title: Re: Plugin: ags_theora Video Player
Post by: Khris on Fri 05/11/2010 19:59:38
My guess is that hitting both F5 and Strg+F5 in the editor will run the exe in the Debug folder. For every command related to files, AGS correctly uses the Compiled path, maybe with the exception of Theora commands?
Try copying the video(s) to the Debug folder.
Title: Re: Plugin: ags_theora Video Player
Post by: goodohman on Fri 05/11/2010 21:53:07

Thanks for the reply Khris,
However it's a "new" behavior.. it was working and then *pop*...
Also, I didn't use the keyboard to run it (just pressed the menu items), so...

Do you have any idea regarding the x,y position problem?

Thanks!
Title: Re: Plugin: ags_theora Video Player
Post by: goodohman on Wed 17/11/2010 00:01:50
Scotch,
Could you please take a look and help me here (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42219.0)?

Thanks!!!
Title: Re: Plugin: ags_theora Video Player
Post by: Monsieur OUXX on Tue 08/03/2011 16:21:08
Sorry for digging out the thread. I was considering PM'ing only scotch, but I thought maybe someone else could help.

Whatever values I enter in "scale", the video always appeared scaled up in the background. I used the source of the demo and copy-pasted it in my own game, I only changed the "scalex" and "scale" values.

I think I have AGS 3.1.2. I just replaced the name of the file with the name of my own video. My video's resolution (900 something by 600 something) is larger than my game's resolution (320x240), that's why I need to scale it down.

By the way, my computer doesn't enable hardware acceleration for some reason (I've got a sublaptop).

Sidenote: I don't understand why the coordinates and scale values used in the "hardware acceleration" instruction of the demo are not the same as the values used in the "no hardware acceleration"? Surely the hardware acceleration doesn't change the size in pixels of the game?
Title: Re: Plugin: ags_theora Video Player
Post by: Monsieur OUXX on Fri 11/03/2011 08:38:52
Bump. Nobody's using this plugin? Scotch doesn't answer either. :'-(
Title: Re: Plugin: ags_theora Video Player
Post by: Dualnames on Fri 11/03/2011 10:00:03
I was sure that I replied to this. Well, I am but I never tried scaling. I tried like once or twice,it worked,but I'm not currently using anything will scale. I will however look into this and try to scale. Just for you.

PS: If I manage to scale it, you must find me a bride. m0ds or Calin plx.
Title: Re: Plugin: ags_theora Video Player
Post by: Monsieur OUXX on Fri 11/03/2011 11:45:25
Quote from: Dualnames on Fri 11/03/2011 10:00:03
Just for you.

Oh Dual, what's happening to us?

Quote from: Dualnames on Fri 11/03/2011 10:00:03
m0ds or Calin plx.

You just ruined it. Stop playing with my feelings.

More seriously: I suspect it has somethingt o do with the fact I have no hardware acceleration. To be sure that you're in the same situation, use the function to test that in the sample code.

Also, I'm scaling *down* (that is: I use a scaling factor < 1.0). I don't think it should have any impact, since it's all DirectX 3D floating variables with "1.0f"=="100%", but just in case.

Title: Re: Plugin: ags_theora Video Player
Post by: Dualnames on Fri 11/03/2011 11:57:06
Awwww, cute.

Now, as I recalled, scaling (up or down), unfortunately works only on Direct3D.
So, yep that pretty much sums it up.

Now.

BRIDE!
Title: Re: Plugin: ags_theora Video Player
Post by: Monsieur OUXX on Fri 11/03/2011 14:06:14
Quote from: Dualnames on Fri 11/03/2011 11:57:06
Now.

BRIDE!

You don't deserve one (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=43045.0).

Quote from: Dualnames on Fri 11/03/2011 11:57:06
Now, as I recalled, scaling works only on Direct3D.

But that doesn't make any sense, as inside the demo code the DrawEx instruction has scale factors different fom 1.0 even in its non-accelerated version.

First things first: Are we talking about 2 different things when we chat about hardware acceleration? (1/DX5 vs. D3D, 2/if(System.HardwareAcceleration) {...})
Title: Re: Plugin: ags_theora Video Player
Post by: xerca on Mon 23/05/2011 17:11:30
I have a problem with this module. There is a room which has a video as background (and which we don't see the player character). When the player goes into that room and leaves, the flipped sprites become invisible. At first, I didn't understand why the player character becomes invisible while walking but I realised that only the flipped frames are invisible. Is there a solution to this?
Title: Re: Plugin: ags_theora Video Player
Post by: mode7 on Mon 23/05/2011 18:45:14
Switch to Direct Draw.
However, depending on the resolution and use of alpha blended sprites in your game this might not be the perfect solution.
Title: Re: Plugin: ags_theora Video Player
Post by: xerca on Mon 23/05/2011 18:49:54
I read that it needs to be D3D mode for scaling, and I use that. Also I use lots of high resolution sprites, some with alpha blending. Thanks for the advice anyway.
Title: Re: Plugin: ags_theora Video Player
Post by: mode7 on Mon 23/05/2011 19:48:53
Well you could of course flip the sprites beforehand in Photoshop or something
Title: Re: Plugin: ags_theora Video Player
Post by: xerca on Mon 23/05/2011 19:54:34
Quote from: mode7 on Mon 23/05/2011 19:48:53
Well you could of course flip the sprites beforehand in Photoshop or something
Okay, I'll do this if I can't find any other method. It would take a really long time and would be a waste of memory though. Maybe I can just give up and delete that room..
Title: Re: Plugin: ags_theora Video Player
Post by: Monsieur OUXX on Wed 24/08/2011 16:28:41
HELP!

When I use video.DrawEx (to draw the video's frame on the background) and THEN draw a sprite manually onto the background, the video is still on top.

Is it the expected behavior? How can I draw stuff on top of the video?
This is rather blocking for my game...


      if(System.HardwareAcceleration) {
        //the game is not designed to take advantage of hardware acceleration
      } else {
        video.DrawEx(DsBackground,   160.0, 150.0,   1.0,  1.0,  0.0, RtScreen);
      }
     
      video.NextFrame();

   
      //overwrite something
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
      surface.DrawImage(0, 0,  bg.Graphic,  0,  320,  156);
      surface.Release();


As you can see in both cases I target the background : DsBackground, GetDrawingSurfaceForBackground.