OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Multiple video textures using ffmpeg plugin


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins]
View previous topic :: View next topic  
Author Message
mmaurus
Newbie


Joined: 05 Oct 2017
Posts: 3

PostPosted: Thu Oct 05, 2017 10:02 am    Post subject:
Multiple video textures using ffmpeg plugin
Reply with quote

Hello everyone,

I am currently trying to display a video (mp4) on a textured quad using the osgmovie example. When displaying two of those, I suddenly get a frame drop from 60fps to 12fps.

So my question: what's the proper way to to this without performance issues?

I am not sure how the ImageStream class works in the background. Already looked at the source code but I couldn't figure out, if the current video frame will be loaded to the graphics cards every frame or the whole video will be uploaded to GPU memory

Thank you!

Cheers,
Michael
Back to top
View user's profile Send private message
Voerman, L.
Guest





PostPosted: Thu Oct 05, 2017 1:58 pm    Post subject:
Multiple video textures using ffmpeg plugin
Reply with quote

Try to make sure the ffmpeg decoding happens on different actual cores. osg currently cannot detect hyperthreading, so the decode threads can end up on the same core. Try to see in taskmanage (for windows) or top (for linux) how many cores you actually use - this might hint to the problem.The ImageStream sends frames one by one to the gfx in the graphics thread, after detecting that a decoding thread changed the modified count.
Regards, Laurens.


On Thu, Oct 5, 2017 at 12:02 PM, Michael Maurus < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hello everyone,

I am currently trying to display a video (mp4) on a textured quad using the osgmovie example. When displaying two of those, I suddenly get a frame drop from 60fps to 12fps.

So my question: what's the proper way to to this without performance issues?

I am not sure how the ImageStream class works in the background. Already looked at the source code but I couldn't figure out, if the current video frame will be loaded to the graphics cards every frame or the whole video will be uploaded to GPU memory

Thank you!

Cheers,
Michael

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72108#72108





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
mmaurus
Newbie


Joined: 05 Oct 2017
Posts: 3

PostPosted: Thu Oct 05, 2017 2:41 pm    Post subject:
Reply with quote

This was actually a nice hint.
Only one of my CPUs was working at full capacity.

The FFmpegImageStream inherits from OpenThreads.
So I should have two separate threads for both decoders, right?

Is there a possibility to SetProcessorAffinityOfCurrentThread() from outside FFmpegImageStream?

How about ffmpeg plugin puts different encoders in different processors?
And why doesn't it upload a bunch of frames (maybe even the whole video) as a texture2darray to the graphics card which would improve performance even further?

Is it possible to create a Texture2DArray out of the loaded ImageStream to do that manually?

Cheers, Michael
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11193

PostPosted: Thu Oct 05, 2017 2:55 pm    Post subject:
Multiple video textures using ffmpeg plugin
Reply with quote

Hi Michael,

On 5 October 2017 at 15:41, Michael Maurus < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
This was actually a nice hint.
Only one of my CPUs was working at full capacity.


I haven't looked at the code recently so I'm a bit cold on the ffmpeg implementation side.  I don't recall any external way to control the threads that the ffmpeg creates. 



From what it sounds like is the threads that the ffmpeg plugin is creating is inheriting the affinity of the thread that created them.  In OSG master there is finer grained control over the affinity setting behaviour, in your case it might be appropriate to disable the default setting of affinity.


In an ideal world you want to decided which threads you want to run on what threads, but this reques knowledge of all the threads, their needs, and the hardware you are working on.



FYI, the OSG by default tries to make a best guess based on your the number of CPU cores the OS says the machine has and the configuration of your viewer, this scheme doesn't know about any extra threads that plugins might create though.  This scheme is more hardwired in OSG-3.4 and prior releases, so master might be the thing to use if you do end up needing more control.



Robert.

 


 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Voerman, L.
Guest





PostPosted: Fri Oct 06, 2017 12:57 pm    Post subject:
Multiple video textures using ffmpeg plugin
Reply with quote

Hi Michael,we use a modified version of the ffmpeg plugin with changes in
OpenSceneGraphsrcosgPluginsffmpegFFmpegDecoderVideo.cpp 

to move the threads to different processors. (full modified file attached) It's a crude bit of code, 
but it allows us to decode and show 2  1920x1080 movies at 30 fps.
I've pulled out just the code for cpu affinity, this should work with osg 3.4.2 as well as git master.
Regards, Laurens.




+ #define RESERVERD_CORES 2
+ static int next_cpu = RESERVERD_CORES;


void FFmpegDecoderVideo::decodeLoop()
{
    FFmpegPacket packet;
    double pts;
+     {
+         int num_cpus = OpenThreads::GetNumberOfProcessors();
+         if (num_cpus > RESERVERD_CORES + 1) {
+             int cpu = next_cpu;
+             ++next_cpu;
+             if (next_cpu >= num_cpus) next_cpu -= num_cpus - RESERVERD_CORES;
+             if (cpu >= num_cpus) cpu -= num_cpus - RESERVERD_CORES;
+             OpenThreads::SetProcessorAffinityOfCurrentThread(cpu);
+             OSG_WARN << "FFmpegDecoderVideo::run : OpenThreads::SetProcessorAffinityOfCurrentThread" << cpu << std::endl;
+         }
+     }




On Thu, Oct 5, 2017 at 4:54 PM, Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Michael,

On 5 October 2017 at 15:41, Michael Maurus < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
This was actually a nice hint.
Only one of my CPUs was working at full capacity.


I haven't looked at the code recently so I'm a bit cold on the ffmpeg implementation side.  I don't recall any external way to control the threads that the ffmpeg creates. 



From what it sounds like is the threads that the ffmpeg plugin is creating is inheriting the affinity of the thread that created them.  In OSG master there is finer grained control over the affinity setting behaviour, in your case it might be appropriate to disable the default setting of affinity.


In an ideal world you want to decided which threads you want to run on what threads, but this reques knowledge of all the threads, their needs, and the hardware you are working on.



FYI, the OSG by default tries to make a best guess based on your the number of CPU cores the OS says the machine has and the configuration of your viewer, this scheme doesn't know about any extra threads that plugins might create though.  This scheme is more hardwired in OSG-3.4 and prior releases, so master might be the thing to use if you do end up needing more control.



Robert.

 


 




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 794

PostPosted: Fri Oct 06, 2017 1:16 pm    Post subject:
Multiple video textures using ffmpeg plugin
Reply with quote

Hi Guys,

Maybe this [1] might help to increase performance.
I'm not sure which ffmpeg is supported now, but maybe that's a good
argument to upgrade.

Cheers
Sebastian

[1] https://developer.nvidia.com/ffmpeg

Quote:
Hi Michael,
we use a modified version of the ffmpeg plugin with changes in
OpenSceneGraph\src\osgPlugins\ffmpeg\FFmpegDecoderVideo.cpp
to move the threads to different processors. (full modified file
attached) It's a crude bit of code,
but it allows us to decode and show 2  1920x1080 movies at 30 fps.
I've pulled out just the code for cpu affinity, this should work with
osg 3.4.2 as well as git master.
Regards, Laurens.


+ #define RESERVERD_CORES 2
+ static int next_cpu = RESERVERD_CORES;

void FFmpegDecoderVideo::decodeLoop()
{
    FFmpegPacket packet;
    double pts;
+     {
+         int num_cpus = OpenThreads::GetNumberOfProcessors();
+         if (num_cpus > RESERVERD_CORES + 1) {
+             int cpu = next_cpu;
+             ++next_cpu;
+             if (next_cpu >= num_cpus) next_cpu -= num_cpus -
RESERVERD_CORES;
+             if (cpu >= num_cpus) cpu -= num_cpus - RESERVERD_CORES;
+             OpenThreads::SetProcessorAffinityOfCurrentThread(cpu);
+             OSG_WARN << "FFmpegDecoderVideo::run :
OpenThreads::SetProcessorAffinityOfCurrentThread" << cpu << std::endl;
+         }
+     }

On Thu, Oct 5, 2017 at 4:54 PM, Robert Osfield <
<mailto:>> wrote:

Hi Michael,

On 5 October 2017 at 15:41, Michael Maurus <
<mailto:>> wrote:

This was actually a nice hint.
Only one of my CPUs was working at full capacity.


I haven't looked at the code recently so I'm a bit cold on the
ffmpeg implementation side.  I don't recall any external way to
control the threads that the ffmpeg creates.

From what it sounds like is the threads that the ffmpeg plugin is
creating is inheriting the affinity of the thread that created
them.  In OSG master there is finer grained control over the
affinity setting behaviour, in your case it might be appropriate to
disable the default setting of affinity.

In an ideal world you want to decided which threads you want to run
on what threads, but this reques knowledge of all the threads, their
needs, and the hardware you are working on.

FYI, the OSG by default tries to make a best guess based on your the
number of CPU cores the OS says the machine has and the
configuration of your viewer, this scheme doesn't know about any
extra threads that plugins might create though.  This scheme is more
hardwired in OSG-3.4 and prior releases, so master might be the
thing to use if you do end up needing more control.

Robert.


_______________________________________________
osg-users mailing list

<mailto:>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
<http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
mmaurus
Newbie


Joined: 05 Oct 2017
Posts: 3

PostPosted: Tue Oct 10, 2017 11:44 am    Post subject:
Reply with quote

Hi guys,

Thanks for the replies.
I tried using the suggested ffmpeg plugin changes, but it didn't make a difference.
Turns out the culprit was automatic texture scaling to power of two texture size.
After setting the resizePowerOfTwoHint to false, I was able to play two 720p videos with 60fps.

Cheers,
Michael
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins] All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Make ObjOptionsStruct in obj plugin a... Ralf Habacker Submission 1 Fri Oct 20, 2017 8:31 am View latest post
No new posts Multi-threaded usage of textures anishuz Submission 5 Tue Oct 17, 2017 8:38 am View latest post
No new posts obj plugin does not support diffuse a... Ralf Habacker General 5 Tue Sep 19, 2017 6:21 am View latest post
No new posts Executing subtree multiple times / re... antiro42 General 2 Thu Sep 14, 2017 10:10 am View latest post
No new posts Is it possible to clear just certain ... amudhan79 General 3 Mon Sep 11, 2017 7:48 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP