Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What's the fastest way to show JPG/JPEG images
Forum Updated to NodeBB v4.3 + New Features

What's the fastest way to show JPG/JPEG images

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlabelqtimerstreaming
18 Posts 7 Posters 7.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #4

    You could probably use QtMultimedia module for this (with https://doc.qt.io/qt-5/qvideoframe.html class).

    How do you show/delete your image? How do you read the image? To avoid unnecessary repaints, try deleting the frame only after a new one has been displayed. Then QLabel does not go through show - hide - show cycle.

    Also, try moving the image reading and deleting code to a thread. Perhaps your hard drive IO is responsible.

    Lastly, if you can, try steaming the frames from your video source directly to your app.

    (Z(:^

    R_IrudezuR 1 Reply Last reply
    2
    • R_IrudezuR R_Irudezu

      Hi, I know title is not exactly explanatory. But my issue is simple to explain.
      I have a directory and i'm loading frames from a video source to this directory.

      I'm trying to show frames in GUI with QLabel. So it should look like a video player.

      → get first frame
      → show it
      → delete it

      The video source loads 24 frames in a second but my GUI program cannot catch up its speed. I mean, speed(load to directory) > speed(show in QLabel and delete it)

      Showing frames in QLabel provide by a function and i call this function with a QTimer. (Call function every 25 milliseconds)

      How can i solve this speed problem? Any suggestions...

      • I have to do it in this way. Because i'm manipulating frames with another program.

      I wanted to revise the question. What's the fastest way to show JPG/JPEG formatted images in a sequence way in Qt Window?
      (JPEG images named with a timestamp so all of them is in an order.)
      I want to show over 20 frames in a second so it should look like a video. I really need help about this.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #5

      @R_Irudezu
      I'm assuming, you use setPixmap to asign the Label the modfied fram ?

      I would probably go with subclassing QWidget and overwriting paintEvent, and drawing the Pixmap directly with QPainter and drawPixmap.

      should be faster. Also calling update() after getting the new pixmap should encourage a redraw.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • J.HilkJ Online
        J.HilkJ Online
        J.Hilk
        Moderators
        wrote on last edited by
        #6

        Also reading the additonal information you profided,

        Creating a new QImage/QPixmap via QImage("filepath") is horribly expensive. Holding a Image/Pixmap in memory and changing the bytes, read via QFile; Should be a good bit faster.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        R_IrudezuR 1 Reply Last reply
        0
        • sierdzioS sierdzio

          You could probably use QtMultimedia module for this (with https://doc.qt.io/qt-5/qvideoframe.html class).

          How do you show/delete your image? How do you read the image? To avoid unnecessary repaints, try deleting the frame only after a new one has been displayed. Then QLabel does not go through show - hide - show cycle.

          Also, try moving the image reading and deleting code to a thread. Perhaps your hard drive IO is responsible.

          Lastly, if you can, try steaming the frames from your video source directly to your app.

          R_IrudezuR Offline
          R_IrudezuR Offline
          R_Irudezu
          wrote on last edited by
          #7

          @sierdzio I will post my code here:

          void MainWindow::showFrames()
          {
              QDirIterator it("/framesPath", QDirIterator::Subdirectories);
          
              it.next();  // Pass first..
              it.next();  // .. two dots
          
              QString nextFirstFile = it.next();
              QImage Img;
          
              Img.load(nextFirstFile);
              Img = Img.scaledToWidth(ui->QLabel1->width(), Qt::SmoothTransformation);
              ui->QLabel1->setPixmap(QPixmap::fromImage(Img));
          
              QFile imgFile(nextFirstFile );
              imgFile.remove();
          }
          

          The timer in constructor:

              frameTimer = new QTimer(this);
              connect(frameTimer, SIGNAL(timeout()), this, SLOT(showFrames()));
              frameTimer->start(35);
              frameTimer->setInterval(45);
          

          I don't know my approach is good or not, i need your help.

          @sierdzio as you say:
          "Lastly, if you can, try steaming the frames from your video source directly to your app."

          I said "I have to do it in this way. Because i'm manipulating frames with another program."

          @J-Hilk
          Dear J.Hilk, i've posted code how i'm trying to do. Maybe you can show me a little code example.

          Keizoku wa chikaranari.

          jsulmJ sierdzioS 2 Replies Last reply
          0
          • R_IrudezuR R_Irudezu

            @sierdzio I will post my code here:

            void MainWindow::showFrames()
            {
                QDirIterator it("/framesPath", QDirIterator::Subdirectories);
            
                it.next();  // Pass first..
                it.next();  // .. two dots
            
                QString nextFirstFile = it.next();
                QImage Img;
            
                Img.load(nextFirstFile);
                Img = Img.scaledToWidth(ui->QLabel1->width(), Qt::SmoothTransformation);
                ui->QLabel1->setPixmap(QPixmap::fromImage(Img));
            
                QFile imgFile(nextFirstFile );
                imgFile.remove();
            }
            

            The timer in constructor:

                frameTimer = new QTimer(this);
                connect(frameTimer, SIGNAL(timeout()), this, SLOT(showFrames()));
                frameTimer->start(35);
                frameTimer->setInterval(45);
            

            I don't know my approach is good or not, i need your help.

            @sierdzio as you say:
            "Lastly, if you can, try steaming the frames from your video source directly to your app."

            I said "I have to do it in this way. Because i'm manipulating frames with another program."

            @J-Hilk
            Dear J.Hilk, i've posted code how i'm trying to do. Maybe you can show me a little code example.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @R_Irudezu No need to create QFile instance to delete a file, use http://doc.qt.io/qt-5/qfile.html#remove-1 instead.
            Use QDir::NoDotAndDotDot in QDirIterator it("/framesPath", QDirIterator::Subdirectories); and remove these two it.next().
            I'm not sure why you create a QImage first and then QPixmap. You can scale QPixmap as well: http://doc.qt.io/qt-5/qpixmap.html#scaled

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3
            • R_IrudezuR R_Irudezu

              @sierdzio I will post my code here:

              void MainWindow::showFrames()
              {
                  QDirIterator it("/framesPath", QDirIterator::Subdirectories);
              
                  it.next();  // Pass first..
                  it.next();  // .. two dots
              
                  QString nextFirstFile = it.next();
                  QImage Img;
              
                  Img.load(nextFirstFile);
                  Img = Img.scaledToWidth(ui->QLabel1->width(), Qt::SmoothTransformation);
                  ui->QLabel1->setPixmap(QPixmap::fromImage(Img));
              
                  QFile imgFile(nextFirstFile );
                  imgFile.remove();
              }
              

              The timer in constructor:

                  frameTimer = new QTimer(this);
                  connect(frameTimer, SIGNAL(timeout()), this, SLOT(showFrames()));
                  frameTimer->start(35);
                  frameTimer->setInterval(45);
              

              I don't know my approach is good or not, i need your help.

              @sierdzio as you say:
              "Lastly, if you can, try steaming the frames from your video source directly to your app."

              I said "I have to do it in this way. Because i'm manipulating frames with another program."

              @J-Hilk
              Dear J.Hilk, i've posted code how i'm trying to do. Maybe you can show me a little code example.

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #9

              @R_Irudezu said in What's the most efficient way to use QLabel as video player:

              I said "I have to do it in this way. Because i'm manipulating frames with another program."

              Yes, but perhaps that other program supports sending the data through a pipe. Or you have some influence on that program and can request streaming support to be added. Et cetera

              (Z(:^

              1 Reply Last reply
              2
              • J.HilkJ J.Hilk

                Also reading the additonal information you profided,

                Creating a new QImage/QPixmap via QImage("filepath") is horribly expensive. Holding a Image/Pixmap in memory and changing the bytes, read via QFile; Should be a good bit faster.

                R_IrudezuR Offline
                R_IrudezuR Offline
                R_Irudezu
                wrote on last edited by
                #10

                @J.Hilk Can you make simple example. I don't know how to do it with QFile.

                Keizoku wa chikaranari.

                J.HilkJ 1 Reply Last reply
                0
                • R_IrudezuR R_Irudezu

                  @J.Hilk Can you make simple example. I don't know how to do it with QFile.

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #11

                  @R_Irudezu

                  this is of course untested. And as the comment says, you have to modfy the QbyteArray to actually get the rgb(a) values you want. You'll have too look that one up. Also the memberImage needs to have the same size as the images you want to load.

                  void myWidget::showFrames()
                  {
                      QDirIterator it("/framesPath", QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
                  
                      memberQFile.setFileName(it.next());
                      
                      if(memberQFile.exists() && memberQFile.open(QIODevice::ReadOnly)){
                          QByteArray data = memberQFile.readAll();
                          
                          //This will fail, the QByteArray has to be trimmed/changed according to img file/header
                          memcpy(memberImage.bits(),data.data(), data.size());
                  
                          memberQFile.remove();//Also automatically closes the file
                          
                          update();//request repaint
                      }
                  }
                  
                  void myWidget::paintEvent(QPaintEvent *event)
                  {
                      QWidget::paintEvent(event);
                      
                      QPainter p(this);
                      
                      p.drawImage(rect(),memberImage, memberImage.rect());
                  }
                  

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • K Offline
                    K Offline
                    kuzulis
                    Qt Champions 2020
                    wrote on last edited by
                    #12

                    There are no efficient way with QLabel.

                    1 Reply Last reply
                    0
                    • R_IrudezuR Offline
                      R_IrudezuR Offline
                      R_Irudezu
                      wrote on last edited by
                      #13

                      i've just edited the question, seperated with (____)

                      Keizoku wa chikaranari.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        Hi,

                        Jpeg decompression is expensive. What size are you images ? What quality ? And to what application are you going to send them ?

                        You might want to consider using turbo-jpeg to handle the decompression.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        R_IrudezuR 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          Hi,

                          Jpeg decompression is expensive. What size are you images ? What quality ? And to what application are you going to send them ?

                          You might want to consider using turbo-jpeg to handle the decompression.

                          R_IrudezuR Offline
                          R_IrudezuR Offline
                          R_Irudezu
                          wrote on last edited by R_Irudezu
                          #15

                          @SGaist I'm receiving jpeg data and decoding it with GDI+ in quality of between 30-50 (with a native c++ compiled .exe file)

                          long  quality = 50;
                          encoderParameters.Parameter[0].Value = &quality;
                          

                          All images save under a directory. I don't want to use any other decompress handling. Images are about 30-50 Kb and i just want to show them in a Qt item. (QLabel is very useless for this). All images will be shown with a QTimer (40 ms) and will be deleted.

                          Keizoku wa chikaranari.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            Where are you getting these images from in the first place ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            R_IrudezuR 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Where are you getting these images from in the first place ?

                              R_IrudezuR Offline
                              R_IrudezuR Offline
                              R_Irudezu
                              wrote on last edited by R_Irudezu
                              #17

                              @SGaist I'm getting images from a .exe program written in C. The C program connects a camera, getting images, manipulate them with GDI+ and save them under a specific directory. The program uses some libraries, these libraries are not compatible with any of Qt versions.

                              Keizoku wa chikaranari.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18

                                Why are they not ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved