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
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.