Horde3D

Next-Generation Graphics Engine
It is currently 23.11.2024, 03:48

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Playing videos in horde
PostPosted: 28.06.2010, 11:00 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
I'm trying to play videos on some textures of my 3d scene. For decoding I use FFmpeg. Everything is fine until I try to change textures in horde (so, everything is decoded correctly, h3dutCreateTGAImage works successfully). If I use only LoadResource then horde loads only the first frame of the video. If I use UnloadResource before it everything works, but I get 10 fps (normally the speed of the scene is more than 70 fps with 8xAA). Even with writing every frame to disk I got 23-25 fps with antialiasing. And with unloading texture resource and no AA I get 11 fps :P
I tried creating texture resource with different flags, like no compression, dynamic textures and other, but situation is the same.

I tried to use h3dMapResStream to directly modify the texture, but for some reason I get a null pointer and an "Invalid operation in h3dMapResStream" (even for reading. Maybe because I tried it after AddResource operation and texture data was not yet uploaded).

Any ideas?


Top
 Profile  
Reply with quote  
PostPosted: 28.06.2010, 13:10 
Offline

Joined: 15.02.2009, 02:13
Posts: 161
Location: Sydney Australia
Hi Irdis,

What are the specs for this video, like what resolution is it and what codec/bit-rate? If it is an non power of two try making it one and see what the performance is like. I'm not too sure how to use mapstream so I can't really help there. Using blender's video2texture approach with a 1080p video it wasn't very good performance-wise either.

http://www.opengl.org/registry/specs/AR ... object.txt
http://developer.nvidia.com/object/fast ... sfers.html

You might need to extend horde to support PBOs or something to get better performance, I'm not sure.

_________________
-Alex
Website


Top
 Profile  
Reply with quote  
PostPosted: 28.06.2010, 14:39 
Offline

Joined: 24.03.2010, 10:17
Posts: 55
You definitely have to use the mapStream functionality in Horde, which dynamically uploads the new texture data.
Internally it does use glTexImage2D (replacing the old texture, which seems a bit faster than using glTexSubImage2D).
We use this approach to dynamically upload new textures, and even a decent graphics card will allow an upload of 500MB/sec (e.g. NVIDIA 8600M GT, running Linux in Parallels, so virtualized).
The basic outline is:
Code:
- Use
  dynTex = ::h3dCreateTexture("$DYN_TEXTURE", videoWidth, videoHeight, TEX_BGRA8, H3DResFlags::NoTexMipmaps);
  to create a new texture - be careful to chose a name which is not yet occupied!
  Use TEX_BGRA8 as format - your video needs to be converted in this format or you have to patch the renderer to support BGR only
- Find the material resource you want to apply the video texture to
  matRes = ::h3dFindResource(H3DResTypes::Material, matName);
- Find the sampler index within the material
  int samplerIndex = h3dFindResElem(matRes, H3DMatRes::SamplerElem, H3DMatRes::SampNameStr, samplerName); // samplerName sth like "albedoMap"
- Apply the dynTex to the material
  h3dSetResParamI(matRes, H3DMatRes::SamplerElem, samplerIndex, H3DMatRes::SampTexResI, dynTex);
- You do this only once.

Then after getting a video frame from ffmpeg, upload it to horde (which will upload it to GL)
void *mappedData = h3dMapResStream(dynTex, H3DTexRes::ImageElem, i*countsPerSlice+mip, H3DTexRes::ImgPixelStream, false, true );
// (i, countsPerSlice and mip are only relevant if you have a mipmapped and/or cube texture, otherwise just set it to 0)
// copy image data over to horde's internal buffer
memcpy(mappedData, ffmpegVideoFrame, textureSize); // with texture size being videoWidth*videoHeight*4 in case of BGRA8
// tell horde to upload data to GL
h3dUnmapResStream(dynTex);


Hope this gets you going.
In our case a PBO approach wasn't really worth it. One could also avoid the memcpy, if horde accepts a raw memory pointer, but this might only work for OpenGL.

Alex


Last edited by AlexL on 29.06.2010, 14:09, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 28.06.2010, 16:49 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
MistaEd, video file is xvid encoded, 720*480, bitrate about 1800. It takes little time to decode (if I don't update the texture in horde decoding is not even noticable). Thanks for links. Great work on the ES port, by the way))

AlexL, thanks alot, everything worked!


Top
 Profile  
Reply with quote  
PostPosted: 28.12.2010, 22:29 
Offline

Joined: 28.12.2010, 21:38
Posts: 5
Location: Wilkes, Barre Pa
Could you post a working example on how you got ffmpeg working?


Top
 Profile  
Reply with quote  
PostPosted: 05.01.2011, 10:42 
Offline

Joined: 08.04.2008, 14:05
Posts: 14
Hi zester,

you could look at http://hcm-lab.de/public/Horde3D/trunk/ ... Component/ (Further details can be found here: http://hcm-lab.de/projects/GameEngine/d ... ials:vidoe)

Maybe you find some piece of code that is useful.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group