Results 1 to 9 of 9

Thread: How to play video using libavcodec frames using QLable Widget

  1. #1
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default How to play video using libavcodec frames using QLable Widget

    Hi All,
    I am new to Qt and am implementing video phone in my new company. For displaying video I choosed QLable Widget and I am able to play video frame by frame, But when I trying to
    display all frames in one shot It's not displaying (I put nextFrame function in a loop to diplay continue frames). Only I am seeing last frame . Is this correct approach or am I doing anything wrong here.
    Please help me to come out of this problem.


    Here is my code:

    Qt Code:
    1. /************************************/
    2. Working code: Frame by Frame display
    3. /************************************/
    4.  
    5. void MainWindow::image2Pixmap(QImage &img,QPixmap &pixmap)
    6. {
    7. // Convert the QImage to a QPixmap for display
    8. pixmap = QPixmap(img.size());
    9. QPainter painter;
    10. painter.begin(&pixmap);
    11. painter.drawImage(0,0,img);
    12. painter.end();
    13. }
    14.  
    15.  
    16. void MainWindow::displayFrame()
    17. {.
    18. .
    19. .
    20. .....
    21.  
    22. image2Pixmap(img,p);
    23. // Display the QPixmap
    24. ui->labelVideoFrame->setPixmap(p);
    25. ....
    26. ....
    27. }
    28.  
    29.  
    30. void MainWindow::on_pushButtonNextFrame_clicked()
    31. {
    32. if(!decoder.seekNextFrame())
    33. {
    34. QMessageBox::critical(this,"Error","seekNextFrame failed");
    35. }
    36.  
    37. decoder.decodeSeekFrame();
    38.  
    39. displayFrame();
    40. }
    41.  
    42. /*********************************/
    43. Not Working: play all frames in one shot (playing video)
    44. /*********************************/
    45. void MainWindow::on_pushButtonNextFrame_clicked()
    46. {
    47. while(decoder.seekNextFrame()) {
    48.  
    49. decoder.decodeSeekFrame();
    50.  
    51. displayFrame();
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 


    Thanks in advance
    Last edited by Lykurg; 15th May 2011 at 21:26. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to play video using libavcodec frames using QLable Widget

    the while loop is blocking the event loop, so the gui only gets updated at the end of the loop. Thus, move the decoder to a separate thread and connect it to the gui via signal and slot mechanism or call QApplication::processEvents() or read wysota's qq article on how to keep the ui responsive. You will find it in our wiki.

    Further, please use the code tags next time.

  3. #3
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to play video using libavcodec frames using QLable Widget

    Thanks for your valuable solution... Now I am able to play the frames continuely by using processEvents() function, but only problem is video playing very very fast (like fast forward) and one more problem is not able to maximus or close my main video while play video .

    Do I need to follow some other approach for avoiding thses kindof problems. Please cn you provide sample code for this .

    Thanks in advance.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to play video using libavcodec frames using QLable Widget

    Quote Originally Posted by vijayQt View Post
    Thanks for your valuable solution... Now I am able to play the frames continuely by using processEvents() function, but only problem is video playing very very fast (like fast forward) and one more problem is not able to maximus or close my main video while play video .
    Yes, that's because your while loop still kind of blocks the entire application. Thus, the only solution is to move all in a thread like I said. But furthermore, can's you use phonon or the QtMultimedia module?

    Please cn you provide sample code for this .
    Hmm, let me consider: You work in a company. You get paid. I should do your work. hmm. Yes that is how life works today all over the world, but no you have to do it yourself. We are here to help people but not in providing working code. We try to push them in the right direction or simply say what we would do, but it is up to everybody to solve their problems (=coding) alone.

  5. #5
    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: How to play video using libavcodec frames using QLable Widget

    but only problem is video playing very very fast (like fast forward)
    That is a good problem!
    Usually the problem is to have the video run fast enough.
    You need to know what is the speed your video has to have - how many frames per second.
    Since it looks you have either a very small frame, or some other reason that makes you frame render very quickly, you can use a QTimer, and fire it in the right frequency for your video.
    This will also solve you non responsive GUI problem as you wont be needing your loop.
    ==========================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.

  6. #6
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to play video using libavcodec frames using QLable Widget

    As I am new to Qt I choosed QLable Wedget by default. I am not sure which widget will be suitable for my requirement.

    My requirements are:
    -> Display frames of local video file.
    -> Display streamed frames from server (like youtube).
    -> One Widget should display more than one source (From multiple video cams). Basically widget should display videos from multiple video cams.

    Which widget will be suitable for my requirements? Please guide me in right direction so that later on I should not change the widget.

    I am using libavcodec for encoding and decoding video and audio. I am not sure Phonon OR QMultiMedia will support this . Please let me know your comments.

    Thanks in advance
    VijayQt

  7. #7
    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: How to play video using libavcodec frames using QLable Widget

    Who said that QLabel was not a good choice?
    It seems to work for you, so stay with it.
    ==========================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.

  8. #8
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to play video using libavcodec frames using QLable Widget

    Hi high_flyer,
    Thanks for your quick reply. You mean to say QLable will fulfill all my feature requirements??..

    Thanks
    VijayQt

  9. #9
    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: How to play video using libavcodec frames using QLable Widget

    I don't know.
    Your original post was about non responsive gui and a too fast video.
    So based on that I take it you have no problem showing your video.
    On that topic Lykurg and I answered you.
    ==========================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.

Similar Threads

  1. Replies: 19
    Last Post: 13th May 2013, 11:17
  2. play a video from youtube
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2011, 07:17
  3. How to play video , by rotating at 90 degree?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 21st April 2011, 12:11
  4. Video play issue
    By baluk in forum Newbie
    Replies: 3
    Last Post: 4th December 2010, 13:43
  5. Play video in QT4 application
    By carlosmele in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2009, 22:24

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.