PDA

View Full Version : Simulating Video on QLabel or QGraphicsView



forrestfsu
20th March 2007, 15:42
I want to simulate video by displaying incoming image frames. I wanted to display the video on a QGraphicsView's scene, but was unsure if there would be a problem with performance. Is there any known performance problems with setting a pixmap on QGraphicsView rather then a QLabel? The reason I want it on a QGraphicsView, is so that I can add overlays to the scene (which will be shown over the video).

Thanks in advance

high_flyer
20th March 2007, 16:25
I made a QVideo widget with Qt3.3.
There is no issue with perfomance, but the way to go is not with QPixmap.
Under Qt3.3 I bitBlt() the buffer directly on the widget.
I had no problem showing a stero stream at 30fps. each video was 640x480.
I guess (but didn't check it out) that with Qt4 it will be more elegant then using bitBlt().
I suggest reading the Arthur docs. http://doc.trolltech.com/4.0/qt4-arthur.html

Bitto
20th March 2007, 22:43
The fastest approach should be to call drawImage() from your video item.

high_flyer
20th March 2007, 23:36
The fastest approach should be to call drawImage() from your video item.
Could you elaborate on that?
What video object?

wysota
21st March 2007, 01:00
I implemented a video widget using Qt4 and QGLWidget. Works nice (smooth), even on fullscreen, and there is still some place for optimisations (for instance hardware accelerated yuv to rgb conversion or buffering the video stream).

high_flyer
21st March 2007, 09:29
Wysota - could you explain in few words how did you implement that?
Thanks.

wysota
21st March 2007, 09:49
In a few words? Hmm... Video stream is decoded using libavcodec (so should be portable) to rgb frames (the yuv->rgb conversion is slow, so we lose some time here) which are placed in a small buffer. A QTimer synchronises the display that takes such a rgb image and converts it to an OpenGL texture which is then applied to an orthogonal plane inside QGLWidget. I can't get sound to work, unfortunately I don't have any experience with using ALSA, OSS or anything else (I'm developing under Linux) and using xinelib is out of question (it would be silly then not to use it for display as well). The code is a mess though, so I won't make it public right now :)

high_flyer
21st March 2007, 09:58
hehe..
I just meant this:

that takes such a rgb image and converts it to an OpenGL texture which is then applied to an orthogonal plane inside QGLWidget.
that is, the frame drawing implementation.
So basically you are doing it in openGL (creating a texture), and using Qt to show show your openGL (texture).
Don't worry, I wont ask for the code, I was after the principal.;)
As I noted above, on Qt3 it was possible with out openGL, I wonder if Qt4 allows it as well.
It would be cool if Bitto would elaborate on that - Bitto?

wysota
21st March 2007, 10:05
Yes, I'm using OpenGL. It's portable and fast enough (probably even on software) and gives easy ways of manipulating the image displayed (like making it full screen). Using QWidget with a QLabel or whatever is sooo slow - I doubt I'd achieve 25fps and full screen. For smaller streams you can surely write data directly to QImage and render it on a widget or graphicsview (QGraphicsViewMovieItem?).

A side question - how much work would it be to render an OpenGL item on the graphics view? I'm not an expert on QGL, but it should be possible using QGLFrameBufferObject, right?

high_flyer
21st March 2007, 10:39
Using QWidget with a QLabel or whatever is sooo slow - I doubt I'd achieve 25fps and full screen
As I said, I had no trouble doing 2 x 640x480 video streams in parallel at 30fps. with QWidget and bitBlt(), on a low end maschine.
I don't claim it is better then using OGL, I think if I would had to do it today again, I wouild go for OGL too.
I am no OGL expert either, so I can't answer your last question...:(