Results 1 to 10 of 10

Thread: Load a sequence of frames

  1. #1
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Load a sequence of frames

    Hello to all, I have one problem.

    My situation is the next:
    - I can extract all frames of one video. (I can't use QMovie because I have another format)
    - I would like to view these frames in a QLabel.

    I did these things but when I probe, I only view the last frame of my video, I think that this is a problem of refresh ¿?
    --> data is the bytes in unsigned char format. All the process is ok because I view the last frame perfect. Always I view the last frame perfect, but before this, I didn't see nothing...

    I do the next instructions for each frame:

    Qt Code:
    1. qimg = QImage(data, img_w, img_h, QImage::Format_RGB32);
    2. Label->setPixmap(QPixmap::fromImage(qimg));
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 1st April 2008 at 17:49. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load a sequence of frames

    It seems u are loading and displaying only the last image.
    To show movie, load the frames one by one in a timer and display it, that will give the effect of movie

    Hope I am making sense

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Load a sequence of frames

    Also, you cannot just set the images in a busy loop. You have to let the application process its events to let the label receive update events. You could change images with help of QTimer (or alternatively you can call QCoreApplication::processEvents() during every loop iteration which is a bit uglier approach).
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load a sequence of frames

    When do you change frames? Can we see a larger portion of code?

  5. #5
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Load a sequence of frames

    Yes... this code works, because I probe with sdl surfaces and i saw the video

    Qt Code:
    1. while ( (av_read_frame(pFormatCtx_l, &packet_l)>=0) && (av_read_frame(pFormatCtx_r, &packet_r)>=0) ) {
    2.  
    3. if ( (packet_l.stream_index == videoStream_l) && (packet_r.stream_index == videoStream_r) ) {
    4. // Decode video frame
    5. avcodec_decode_video(pCodecCtx_l, pFrame_l, &frameFinished_l, packet_l.data, packet_l.size);
    6. avcodec_decode_video(pCodecCtx_r, pFrame_r, &frameFinished_r, packet_r.data, packet_r.size);
    7. // Did we get a video frame?
    8. if ( (frameFinished_l) && (frameFinished_r) )
    9. {
    10. img_convert( (AVPicture *) pFrameRGB_l, PIX_FMT_BGR24, (AVPicture*)pFrame_l,
    11. pCodecCtx_l->pix_fmt, pCodecCtx_l->width, pCodecCtx_l->height);
    12. img_convert( (AVPicture *) pFrameRGB_r, PIX_FMT_BGR24, (AVPicture*)pFrame_r,
    13. pCodecCtx_r->pix_fmt, pCodecCtx_r->width, pCodecCtx_r->height);
    14.  
    15. // Write pixel data
    16. for(ay=0; ay<img_h; ay++)
    17. {
    18. memcpy(aux_l, pFrameRGB_l->data[0]+ay*pFrameRGB_l->linesize[0], ancho);
    19. memcpy(aux_r, pFrameRGB_r->data[0]+ay*pFrameRGB_r->linesize[0], ancho);
    20. // incrementar data_l, data_r para recorrer la imagen nueva e irla generando
    21. aux_l += ancho;
    22. aux_r += ancho;
    23. }
    24.  
    25. img_raw_set_data (img_l, data_l);
    26. img_raw_set_data (img_r, data_r);
    27.  
    28. data32_l = RGB24toARGB(img_l);
    29. data32_r = RGB24toARGB(img_r);
    30.  
    31. qimg_l = QImage(data32_l, img_w, img_h, QImage::Format_RGB32);
    32. qimg_r = QImage(data32_r, img_w, img_h, QImage::Format_RGB32);
    33.  
    34. leftLabel->setPixmap(QPixmap::fromImage(qimg_l));
    35. rightLabel->setPixmap(QPixmap::fromImage(qimg_r));
    36.  
    37. }
    38. aux_l = data_l;
    39. aux_r = data_r;
    40. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 1st April 2008 at 18:00. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load a sequence of frames

    It's a busy loop, so it won't work. You have to process events somewhere in between like jpn suggested.

  7. #7
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Load a sequence of frames

    I tried to introduce one timer and now i have one problem when i run the program:

    Qt Code:
    1. private slots:
    2. void updateLabel(unsigned char *data32_l, unsigned char *data32_r);
    3.  
    4. ///////
    5. QTimer *timer = new QTimer(this);
    6. connect(timer, SIGNAL(timeout()), this, SLOT(updateLabel(data32_l,data32_r)));
    7. timer->start();
    8.  
    9. and the function updateLabel is:
    10.  
    11. void FormMain::updateLabel(unsigned char *data32_l, unsigned char *data32_r)
    12. {
    13. timer->stop();
    14. qimg_l = QImage(data32_l, img_w, img_h, QImage::Format_RGB32);
    15. qimg_r = QImage(data32_r, img_w, img_h, QImage::Format_RGB32);
    16.  
    17. leftLabel->setPixmap(QPixmap::fromImage(qimg_l));
    18. rightLabel->setPixmap(QPixmap::fromImage(qimg_r));
    19. }
    To copy to clipboard, switch view to plain text mode 
    When i run the program i have this:
    Object::connect: No such slot FormMain::updateLabel(data32_l,data32_r)
    Object::connect: (receiver name: 'FormMainInterf')
    I need help!

    Thanks!
    Last edited by jpn; 2nd April 2008 at 08:25. Reason: missing tags

  8. #8
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load a sequence of frames

    Qt Code:
    1. connect(timer, SIGNAL(timeout()), this, SLOT(updateLabel(data32_l,data32_r)));
    To copy to clipboard, switch view to plain text mode 

    That code makes no sense. You're hooking up timeout() to a slot expecting arguments. Where do you think this data is going to come from? Also you have to give connect the types of the arguments, not the names. So unsigned char* instead of data32_l.

  9. #9
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Load a sequence of frames

    Thank you very much to all, now my code works.
    I use one timer.

  10. #10
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Load a sequence of frames

    I was able to load the sequence of frames into the label widget but having trouble with timing of the frames. It is displaying only the last frame of the file.

Similar Threads

  1. Program not compiling on Fresh install of Leopard
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 11:22

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.