Loading images fast

  • Hello,

    I working at the moment on a project for the university. In this we had to write an mediaplayer that renders videos out of single pictures. We also need to draw some rectangles on the frame, but this shouldn't be the problem.
    We want so support at least HD better would be full HD, with 24 or 30 Frames.

    At the moment we use QImage to load the images, but this is far to slow, we need for a singel full HD image about 70 ms to load it from the path. On a i7-4700HQ processor. The time is the same on a SSD and on a HDD, so the disk is not problem.
    Then we used a QPixmap but this needs also about 70 ms.

    So is there a correct/better way to load between 24 and 30 full HD images in a Second?

    Our code at the moment:

    In the constructor of the renderer
    connect(&mTimer, SIGNAL(timeout()), this, SLOT(renderNewFrame()));

    @void VideoRenderer::renderNewFrame() {
    emit currentFrameChanged(mCurrentFrame);

    //we want so render the next frame
    if(mCurrentFrame >= mVideo->frames().size()){
    mCurrentFrame = 0;


    The prepareFrame method th prepare the next frame
    @void VideoRenderer::prepareFrame(){
    //Load the the image

    QImageReader reader(mVideo->absolutePath() + "/" + mVideo->frames()[mCurrentFrame]);
    QImage frame;
    reader.read(&frame); //needs 70 ms thats the problem

    qCritical() << "couldn't load:"
    << mVideo->absolutePath() + "/" + mVideo->frames()[mCurrentFrame];

    //getting all anotations for this frame
    QList<QSharedPointer<Annotation>> annoList = mVideo->annotations(mCurrentFrame); //also about 0-1 ms

    //render annotations on frame
    renderAnnoations(annoList, frame); //needs about 0-1 ms so no problem

    //cutting out the rect that should be shown
    QRect cutRect = mVideo->clippingRect();
    QImage frameMap = frame.copy(cutRect); //about 10-15 ms could be better

    mNextFrame = QVideoFrame(frameMap);


    Would be grate if someone could help :)


  • Moderators

    It all comes down to basically one thing - the format the images are in.

    First of all do some simple math. A raw full HD image file is 1920x1080*4 bytes in size and you want to load about 30 of them every second which gives required throughput of over 230MB/s. Not many average HDDs or SSDs can pull that off, and loading your images is not the only thing they do every given moment. So a good compressed format is a must.

    The other side of the spectrum is how fast can that format be uncompressed on load. Note that QImageReader will not only load, but also transform the underlying data format if needed, which might take time. Try to pick a format that's internal data is in ready to use format i.e. doesn't need yuv rgb conversion etc.

    Also, try to just read the same files using plain old QFile readAll(). Benchmark that and it will tell you how much you spend on IO versus processing the image, so that you can choose the format better.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.