Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terrible performance with QMediaPlayer and QVideoWidget

I see a terrible performance while trying to play videos with QtMobility 1.2.0 and Qt 4.7.4 on Ubuntu 10.10 (Pentium 4 2.80GHz).

What's funny is that totem (which also use gstreamer as backend) and vlc are able to play these videos without a problem on this machine, even with higher resolutions (fullscreen, etc).

According to top, my application consumes 100% of CPU while totem and vlc consumes only ~ 40%. That's... weird! So I'm sharing the source code of the application below. It uses QMediaPlayer and QVideoWidget to do the job.

movie.cpp:

#include <QtGui/QMainWindow>
#include <QtGui>
#include <qmediaplayer.h>
#include <qvideowidget.h>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    QMainWindow mainWindow;

    mainWindow.resize(QSize(1280, 500));

    QMediaPlayer* mplayer = new QMediaPlayer;
    QVideoWidget* vid_widget = new QVideoWidget(&mainWindow);
    vid_widget->setAspectRatioMode(Qt::IgnoreAspectRatio);

    mainWindow.setCentralWidget(vid_widget);

    mplayer->setVideoOutput(vid_widget);
    mplayer->setMedia(QUrl::fromLocalFile(argv[1]));
    mplayer->setVolume(50);
    mplayer->setPlaybackRate(1);
    mplayer->play();

    mainWindow.show();

    return app.exec();
}

movie.pro:

TEMPLATE = app
QT += gui 

CONFIG += mobility
MOBILITY = multimedia

QMAKE_RPATHDIR += $$DESTDIR

SOURCES = \
movie.cpp

The performance remains awful even if I create a smaller window, such as:

mainWindow.resize(QSize(960, 540));

Does anyone know what could be causing this behavior and how do I fix it?

If anyone is interested, ffmpeg shows this information about one of the video files I'm using for testing:

Input #0, matroska, from '/home/user/movie.mkv':
  Duration: 00:02:23.22, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, yuvj420p, 1280x536 [PAR 1:1 DAR 160:67], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc
    Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16
like image 983
karlphillip Avatar asked Oct 13 '11 19:10

karlphillip


2 Answers

I started using QML Video Element and after having several rendering/performance problems with it I finally gave up and wrote a video player element to replace the one from QtMobility.

To whoever might be interested, GStreamer has a C++ interface that is very easy to use.

like image 200
karlphillip Avatar answered Nov 15 '22 21:11

karlphillip


There is nothing wrong with your code, you are just passing the ball to Qt for the decoding and playback of the movie.

You are either using a build of Qt that doesn't have hardware acceleration enabled, or your system doesn't have the proper hardware for Qt to accelerate decoding and playback.

like image 35
Miguel Avatar answered Nov 15 '22 23:11

Miguel