Results 1 to 14 of 14

Thread: Render raw video on a fullscreen window

  1. #1
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Render raw video on a fullscreen window

    Hi,

    I new to Qt, and I have an small app to do.
    I need to show a video coming from a driver and draw it in a Qt window.
    I read the video frame from the driver as RGB32 data and I'm looking for a efficient way to display each frame.

    My first try was to use a QGraphicsScene and put a QPixMap in it created from a QImage.
    But I think it will be slow and I need to draw 30fps video.

    Anybody have another approach on this thing ?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    What is the size of the frame?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    There are 2 resolutions 1024x768 and 768x576, but for this one, it will be put in a 1024x768 buffer.


    Added after 1 17 minutes:


    http://doc.trolltech.com/4.4/threads-mandelbrot.html
    I've just found the Mandelbrot example that implements 2 threads, one from compute and the other for drawing.
    It might be a good foundation for my app, isn't it ?
    Last edited by BBT; 25th November 2010 at 14:18.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    I think direct painting will be the most performant, so not with QGraphicsView.
    I don't know though, if 30fps can be reached ,probably, but it needs testing.
    To test it quick, you can make a smal app with a widget, and in the painEvent() do something like:
    Qt Code:
    1. QPainter painter(this);
    2. QImage image(pData, iWidth, iHeight, QImage::Format_ARGB32);
    3. panter.drawImage(rectImage,image,rectImage); //In this case make the widget as large as the Image 1:1
    To copy to clipboard, switch view to plain text mode 

    and time it.
    See if you get 30fps.


    Added after 4 minutes:


    It might be a good foundation for my app, isn't it ?
    In your case no, since you are not doing anything with the data you get except show it.
    If you need to manipulate the data, then, threads MIGHT be of benefit.
    Last edited by high_flyer; 25th November 2010 at 14:22.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    But how can I refresh the data if it isn't done in another thread ?
    I think I will not put this refresh in the paintEvent.

    Sorry for dummy questions, I'm totally new to Qt.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    But how can I refresh the data if it isn't done in another thread ?
    Well, you know when the device is ready with new data right?
    Then you call widget->repaint() - which will cause paintEvent() to be called.

    NOTE: usually you should not use repaint() - but in this case you want an imitate repainting.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    True, I'll use a select() on the device of the driver to know when new frame is available.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. Widget w;
    5. w.show();
    6.  
    7. return a.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Here's my main(), and I saw that a.exec() is where all Qt messages are processed so I can not call w->repaint(); from the main() as a.exec() is blocking.
    So I thought the only way was to use a thread.
    Am I missing something ?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    Am I missing something ?
    Yes.
    Basic C++ concepts, but that is outside the scope of this forum.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    You're right, I didn't use C++ for years, but I understand basic C++ concepts.
    Do you think that I need to create a class which extends QApplication or something else ?

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    no, you need to subclass QWidget, and overload the paintEvent() (at least).
    But the very fact that this is not clear to you, is not a good sign to your ability to cope with the task you set for your self (Video player).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    I've already created a subclass of QWidget and overloaded paintEvent().
    With this code, my widget is refreshed whenever a paint event occurs (which is good) but my problem is that I want to know a frame arrived before the next paint event.

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    but my problem is that I want to know a frame arrived before the next paint event.
    I didn't get that - can you please explain again?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  13. #13
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render raw video on a fullscreen window

    Quote Originally Posted by BBT View Post
    I've already created a subclass of QWidget and overloaded paintEvent().
    With this code, my widget is refreshed whenever a paint event occurs (which is good) but my problem is that I want to know a frame arrived before the next paint event.
    Hi,
    you can decide when the next paintEvent occours by calling the update ( or repaint in your case for an immediate repainting of your widget ) as told by high_flyer.
    I think your driver has some routines/mechanism to inform you when a new frame is available ( in my case it use windows messages ). In such case repaint your widget
    with the new frame data.

    In my case I had to reimplement winEvent and did something like this:

    Qt Code:
    1. bool CameraView::winEvent(MSG *m, long* result)
    2. {
    3. uint msgType = m->message; // test line
    4.  
    5. if(msgType != IS_UEYE_MESSAGE)
    6. return false; // Let Qt handle other messages
    7.  
    8. switch ( m->wParam )
    9. {
    10. case IS_DEVICE_REMOVED:
    11. qDebug("Device removed");
    12. break;
    13. case IS_DEVICE_RECONNECTED:
    14. qDebug("Device reconnected");
    15. break;
    16. case IS_FRAME:
    17. {
    18. // a new frame is available from my camera driver
    19. ui.camViewerLabel->setPixmap(QPixmap::fromImage(image));
    20. ui.camViewerLabel->update(); // <-----REPAINT THE WIDGET
    21. break;
    22. }
    23. default:
    24. break;
    25. }
    26. return true;
    27. }
    To copy to clipboard, switch view to plain text mode 

    I hope this code can help you.
    Regards
    Franco Amato

  14. #14
    Join Date
    Nov 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Render raw video on a fullscreen window

    My goal is to synchronize the repaint on arrival of new frames, like Franco said.
    The driver provides a char device and my app do a select() on the file descriptor opened on this char device.
    When the driver has a new frame, it changes char device state so the select() call returns and I can get my frame on a nmapped memory block.

    Right now, I've made a QThread which do the select() and it send a signal to the widget. The slot in the widget update the image data and call repaint() method.

    I've just read about update() method which seems to be more "elegant", I'll test the two methods.

    Qt Code:
    1. void Widget::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter Painter(this);
    4. if (this->Image != NULL)
    5. {
    6. QImage resizedImage = this->Image->scaledToWidth(this->width());
    7. Painter.drawImage(resizedImage.rect(), resizedImage);
    8. }
    9. else
    10. {
    11. QWidget::paintEvent(event);
    12. }
    13. }
    14.  
    15. void Widget::showPix(const QImage* pic)
    16. {
    17. this->Timer.start();
    18.  
    19. this->Image = pic;
    20. //this->repaint();
    21. this->update();
    22. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by BBT; 26th November 2010 at 08:28.

Similar Threads

  1. Replies: 6
    Last Post: 14th September 2010, 22:18
  2. Playing video using Phonon video widget
    By Leolander in forum Newbie
    Replies: 0
    Last Post: 26th February 2010, 06:15
  3. open a video file in a new window...
    By jiapei100 in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 14:53
  4. Video freezes during mpeg video playback using Phonon
    By davejames in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2009, 08:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.