Jump to content

LETheora playback library


Niosop
 Share

Recommended Posts

Sorry it took so long guys, finished a procedural version and didn't like how it polluted the global scope w/ it's functions so made it more object oriented. You can look at the files yourself, but here's a quick rundown of how to use:

 

But first: a video. Video is choppy as hell, but stayed above 60FPS on my system when not recording.

 

Installation:

 

http://leadwerks.com/werkspace/index.php?app=downloads&showfile=89

 

Instructions are on the download page.

 

Sample code:

require("scripts/class")
require("scripts/video")

local class=CreateClass(...)

function class:CreateObject(model)
local object=self.super:CreateObject(model)

TheoraVideo:Init()

local choice = math.random(3)

if choice == 1 then
	object.clip = TheoraVideo:CreateMaterial("bunny.ogg", "Bunny")
elseif choice == 2 then
	object.clip = TheoraVideo:CreateMaterial("Elephants_Dream.ogg", "ED")
elseif choice == 3 then
	object.clip = TheoraVideo:CreateMaterial("NoLD.ogv", "NoLD")
end


local new_mesh = makeUniqueMesh(object.model, "OldTV.001")

PaintEntity(new_mesh, object.clip.material, 1)

object.clip:SetLoop(1)
end

 

Here's a quick rundown of the functions. If it's not listed here then you probably shouldn't mess with it directly, but the code is pretty simple so feel free to dig in and do whatever.

TheoraVideo
 - Automatically created when you include video.lua.  Used to create video clips.

TheoraVideo:Init()
 - Should be called before creating any video clips.  Loads the DLL, initializes libtheoraplayer and installs a Flip hook for updating the video position.  You can call it in the creation stage of every entity that uses video if you like, or once in your main loop.
 Returns:  Nothing

TheoraVideo:CreateMaterial(filename, name)
 - Creates a new material and plays back the video referenced by filename on it.  name can be anything you want to uniquely identify this clip.
 Returns:  A TheoraClip object

TheoraVideo:AssignToMaterial(filename, material, name)
 - Plays a video back on the specified material.  filename is the filename of the video.  material can be either a TMaterial or a string that is the name of a material.  name can be anything.
 Returns:  A TheoraClip object

TheoraVideo:FindClipByMaterial(material)
 - Finds the TheoraClip object associated with the passed material.  material can be a TMaterial or a string.
 Returns:  A TheoraClip object or nil if no clip is using that material

TheoraVideo:FindClipByName(name)
 - Find the TheoraClip object associated with the passed name.  You assign a name to a clip when you create it using TheoraVideo:CreateMaterial or TheoraVideo:AssignToMaterial
 Returns:  A TheoraClip object or nil if no clip has that name

TheoraVideo:FindClipByVideo(filename)
 - Finds ALL TheoraClip objects that are playing the given video filename.
 Returns:  A lua table containing all the TheoraClip objects that are playing the given filename, may be an empty table.

TheoraVideo.clips
 -  Table containing all the TheoraClip objects that it knows about.  Safe to read from, shouldn't be directly altered.

TheoraVideo.initialized
 -  0 if TheoraVideo:Init() hasn't been called, 1 if it has been called.



TheoraClip
 -  Object containing information about a video clip.

TheoraClip:Release()
 - Releases a video clip when you're done using it.  Just removes it from the 

TheoraClip:SetLoop(loop)
 -  Tells a TheoraClip if it should restart when it reaches the end or not.  1 = restart, 0 = do not restart.

TheoraClip:SetPlaybackSpeed(speed)
 -  Sets the playback speed of the clip.  1 = normal speed, .5 = half speed, 2 = double speed.

TheoraClip:CalcAverageColor(rac)
 -  Determines if the average color of the video should be calculated every video frame.  1 = yes, 0 = no.  The average color of the last frame can be accessed via TheoraClip.average_color.  If the system is not calculating the average color it will return {r=0, g=0, b=0} or the last color that was calculated if CalcAverageColor was on and then off.

TheoraClip:IsDone()
 Returns:  1 if the clip has reached the end, otherwise 0.

TheoraClip:Restart()
 - Restarts the clip.

TheoraClip:Seek(time)
 - Seeks to the given time in seconds.

TheoraClip:Stop()
 - Stops the current clip and clears the video clips buffer.

TheoraClip:Play()
 - Plays the clip from it's current position

TheoraClip:Pause()
 - Pauses the clip.


TheoraClip.clip
 - The userdata that contains the actual clip data.  Shouldn't normally be read or altered.

TheoraClip.material
 -  The material that this clip is rendering to

TheoraClip.width
 -  The width of the texture that the video is playing on, NOT the actual width of the video.  The width will be the next higher power of 2 for each video dimension.

TheoraClip.height
 - The height of the texture that the video is playing on, NOT the actual height of the video.  The height will be the next higher power of 2 for each video dimension.

TheoraClip.buffer
 - The buffer used by the clip.  Each clip creates it's own TBuffer and renders to that buffer's texture.

TheoraClip.texture
 - The texture that the clip is rendering to.  This is the texture assigned to the buffer.

TheoraClip.filename
 -  The filename of the video being played by this clip.

TheoraClip.name
 -  The user assigned name of this clip.

TheoraClip.status
 -  The playback status of this clip.  Currently "Playing", "Paused" or "Stopped".

TheoraClip.calc_average_color
 -  1 if the system is calculating the average color of each video frame, 0 if not.  Modifying this does the same thing as using TheoraClip:CalcAverageColor(bool)

TheoraClip.average_color
 - A table in the format {r=x, g=y, b=z} where x,y and z are the red, green and blue values (0-255) of the average color of the last frame of the clip played IF calc_average_color == 1.  Otherwise it's the color of the last framed played when calc_average_color was 1 or 0,0,0 if not.

TheoraClip.loop
 -  Indicates whether this clip will loop when it reaches the end.  Should NOT be directly modified, use TheoraClip:SetLoop(bool) to alter this value.  You can query this variable to find the current setting though.

TheoraClip.speed
 - Indicates the current playback speed of the clip.  Setting this to a different value has the same effect as calling TheoraClip:SetPlaybackSpeed(number).

 

The two utility functions defined in nio_util.lua:

nextPow2(x)
 -  If x is not a power of 2, returns the next highest integer that is.

makeUniqueMesh(ent, meshname)
 - Finds the child of the Entity ent named meshname and duplicates and paints all the surfaces of this mesh.  It then positions the new mesh to where the old mesh was, parents it to ent and hides the original mesh.  This should be used with caution as it partially negates the speed gains of using instancing.  Only works with static meshes.  Will replaces surfaces on animated meshes, but they will no longer appear animated if you do so.

Returns:  The new mesh that was created.  Keep this variable around if you ever want to hide or remove it later as it could be hard to find because it has no name to use FindChild with.

 

I'll probably update this post with a slightly cleaner and commented version tomorrow, but figured I'd better release something before I forget about it again. Anyways, have fun w/ it and let me know if you find any problems or have any suggestions.

 

Josh: It would be cool if you added an implementation to the main engine. Then it could stream the audio from the same file and we wouldn't have to split the video/audio to different files, preload the audio and then add code to keep them in sync. It's not a huge deal, but would be cleaner since you have direct access to the audio buffers (I assume anyways), so could make better use of the audio data than we can.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Kewl new Toys to play with on a Sunday morning <_< thanks Nio, will play with this now ....

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Here's a modified version of GIMPY73's Old-TV model that is set up to work w/ the video player, includes Lua Script. You will need to change the video filename to something you have. Includes updated fbx, obj and blend file as well as new material/texture for the screen.

 

Feel free to update your download w/ this version if you'd like Gimpy73. Thanks for the model! The only problem with it was that there was only 1 surface attached to the main mesh, and two sub mesh's with no surfaces. So it was like this:

 

Mesh
- Surface
- Mesh
- Mesh

When it needed to be:

Mesh
- Mesh
  - Surface
- Mesh
  - Surface

 

Updated: Deleted file, use gimpy's updated download.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Thanks Nio.

 

Was gona post that i could'nt get it working with my old tv lol

 

So how do you get your file format like that???

 

I export from Cinema4D via FBX then into UU3D , But can't get the same structure as your's???

 

 

PS:Ive updated the download link with your converted model (thanks Nio)

 

Thanks

 

Gimpy73 :)

Link to comment
Share on other sites

Doh, macklebee discovered that I'm missing an important file in the zip. Unzip and place this in your materials directory or wherever.

 

UPDATE: Now included in the zip in the downloads section.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

So how do you get your file format like that???

 

Not sure about C4D or UU3D, what I do in blender is select all the vertices of the screen. Since you have them as disconnected already I just select one and hit ctrl-l (select linked vertices). Then I separate them from the other mesh which turns them into their own separate object. Then I apply smoothing to the screen, and unwrap the screen so it takes up the whole UV space. Then I export as FBX and run convertmesh.exe on it and it turns out like that.

 

I'll see about downloading the demo version of C4D and see if I can figure out the workflow in that.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Ok it might just be me , as no one else has posted saying they can't get it working :)

 

I drop the tv into the editor and it just sits there (blank screen). Ive put the files into there correct directory's , as stated by Niosop.

 

The Bunny.ogg file sits in the root of the LWE directory , as do the DLL files (its where the editor.exe is located).

 

Any idea's ???

 

Thanks

 

Gimpy73 :D

Link to comment
Share on other sites

Where did you put the mesh_shader.frag file? It needs to be in the actual shaders/mesh folder to work correctly. You may need to unzip the shaders.pak file if you haven't already. Afterward, you can zip the shaders folder back into a pak file if you wish.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Excellent work Nio, all works fine in Editor and in Bmax. :D

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

  • 2 years later...

I wanted to run this script in a standalone game painted on a cube...

but it won't work dry.png neither the script nor the engine gives a error which I understand and that is the well known: EXCEPTION_ACCESS_VIOLATION. I'm using this code:

 

 

TheoraVideo:Init()
cube = CreateCube()
cube:SetPosition(Vec3(0,0,0))
video = TheoraVideo:CreateMaterial("Video.ogg", "video")
cube:PaintEntity(video,1)
video:Play()

 

thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...