Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Video frames display  (Read 4409 times)

0 Members and 2 Guests are viewing this topic.

Bobsinclare666

  • Newbie
  • *
  • Posts: 4
    • View Profile
Video frames display
« on: March 25, 2008, 07:03:28 pm »
Hi,

I am new in using SFML which I find quite interesting.
I was wondering if someone could confirm that my approach is correct:

I am trying to use SFML as a hardware accelerator to display 2D video frames in a GUI. I have a video camera which triggers a callback every time a new video frame (grey level, 8bpp) is available.

I created a view, an image and a sprite. In the callback, I call the following functions:

Code: [Select]

Image.LoadFromPixels(ImageWidth, ImageHeight, ImageDataPointer);
Sprite.SetImage(Image);
SFMLView.Draw(Sprite);
SFMLView.Display();


Is this the proper (ie. most efficient)way to do this?

Thanks

Bob

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Video frames display
« Reply #1 on: March 26, 2008, 02:24:19 am »
Yes, it is. I'm curious, what kind of framerate do you get with that ?

Note that the ultimate solution would probably be to create your own Drawable object and use an OpenGL dynamic texture (SFML will create a new texture each time you call LoadFromPixels, which is not optimal).

I think I could also add an optimization that would not recreate the texture if the new image has the same dimensions as the old one :)
Laurent Gomila - SFML developer

Bobsinclare666

  • Newbie
  • *
  • Posts: 4
    • View Profile
Video frames display
« Reply #2 on: March 26, 2008, 08:42:44 am »
Merci for the reply Laurent.

The idea is not necessarily to get a high frame rate but rather a low CPU usage at standard frame rates, say 30 fps.

I was not particularly impressed by the solution below, hence my question on whether I was doing things right. NOw that you are telling me that it is creating a new texture everytime, it makes more sense.

Displaying a 512x512 image at 30fps requires something like 40% of my CPU (I have a low profile dual core PC with no special videocard) which is far too much for my need.

Indeed if you could add a way to reuse the same texture, that would be nice. Maybe also adding a way to handle grey level images... I kind of remember that you can use the LUMINANCE type when calling the glTexSubImage2D() function in which case a pointer to a grey level array (ie. not rgba) is fine. I don't know if that is still current or makes sense in this context though.

Best,

Bob

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Video frames display
« Reply #3 on: March 26, 2008, 08:55:18 am »
Quote
Indeed if you could add a way to reuse the same texture, that would be nice. Maybe also adding a way to handle grey level images...

Using luminance textures would lower the memory usage, but probably not improve the performances. Unless you have a luminance surface at the source and always need to convert to RGBA, which is very CPU-consuming.

If you can use a profiler (valgrind on Linux) it would be interesting to see where exactly is the CPU bottleneck.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Video frames display
« Reply #4 on: March 27, 2008, 04:52:56 pm »
I've updated sf::Image to reuse the same texture if the dimensions are the same. If you can try the latest sources, tell me if it makes a difference for your app ;)
Laurent Gomila - SFML developer

Bobsinclare666

  • Newbie
  • *
  • Posts: 4
    • View Profile
Video frames display
« Reply #5 on: March 28, 2008, 02:16:27 pm »
Gee that was fast!
OK I will try asap.
And to reply to your previous question, the below function seems to be the one taking so much time. OK, back to the tests.


Code: [Select]

Image.LoadFromPixels()

Bobsinclare666

  • Newbie
  • *
  • Posts: 4
    • View Profile
Video frames display
« Reply #6 on: March 28, 2008, 02:35:18 pm »
Hmm.. Which files did you update?
IS it the Windows Development files?

Cheers,

Bob

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Video frames display
« Reply #7 on: March 28, 2008, 04:00:21 pm »
No no, I didn't make any new release. To use the latests sources you have to use a SVN client to download and recompile it. It's very easy ;)
Laurent Gomila - SFML developer

 

anything