Plugin: ags_theora Video Player

Started by scotch, Tue 24/06/2008 14:48:58

Previous topic - Next topic

Dusk

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

Code: ags

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.

scotch

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.

visionastral

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 :)

xenogia

#23
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.

PixelPerfect

#24
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.

Anomaly

#25
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...

-
"The room is bright. 
You are likely to be vomited upon by a Shrunk."

xenogia

Just a quick question..

How do you set the pointer to null?

guitar_hero

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.

goldensox

You guys think it is possible to make something like Strangehood with this plugin? I mean... I can totally see it.
Faster than a doughnut, stronger than cardboard.
                                                                    -Wario

neseliadam

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 !

neseliadam

anyone hear meeeee :( please hellllllllp :(((((

Matti

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.

neseliadam

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..

neseliadam

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 !

monkey0506

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. ;)

neseliadam

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 :))))


xenogia

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

Code: ags

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:

Code: ags

// 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!
}

AJA

Just get rid of the module code. The plugin has already defined that header script. That's the reason for the error.

xenogia

Yeah I realised that after ProgZMax helped me out.

Willdon

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?

SMF spam blocked by CleanTalk