13

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
karlphillip
  • 92,053
  • 36
  • 243
  • 426

2 Answers2

5

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.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • I have the same problem, video player reproduce the video in normal speed but Phonon is too slow. Could you explain in more detail how you solve the problem, I follow the GStreamer has a C++ interface link but I not found nothing there. Thanks. – HMarioD Oct 03 '13 at 22:47
  • Well, that's a question that deserves it's own thread, so I'll be brief: study a few GStreamer tutorials until you are able to write an application that can read a video file, retrieve it's frames, and display it on a window. During this process, you will find that the frame stores it's pixels in a format that is probably not RGB. To display the frames correctly, each frame needs to be converted to whatever format they are in (let's say YUV) to RGB. – karlphillip Oct 03 '13 at 23:12
  • The conversion process is actually responsible for the poor performance we observe with Phonon because it's done by the CPU. To speed things up, you can write a color space conversion code (i.e. YUV to RGB) to be executed on the GPU through [GLSL shaders](http://stackoverflow.com/q/8977489/176769). Feel free to up vote my questions/answers. Good luck! – karlphillip Oct 03 '13 at 23:20
  • From the (wiki) site: "The QtGStreamer C++ bindings are very out of date and unmaintained." – Kissaki Oct 28 '17 at 11:20
3

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.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • 2
    Poor video performance is frustratingly common on Linux. It's hard to believe that at 2.8 GHz one would need _any_ hardware acceleration to get decent performance, but here we are. – Randall Cook Nov 22 '11 at 06:42
  • h264 especially can be a pain to playback, and a 2.8 Ghz Pentium 4 is not really up to the task. Luckily for us Linux users VAAPI has come far enough with open source drivers that we are no longer bound to nVidia VDPAU to playback even 1080p. I found that my 1.2Ghz Core i3 laptop does just fine, even the open source ATI drivers manage to work with VAAPI if I switch over to the built in hybrid 5950 – r_ahlskog Nov 23 '11 at 13:50
  • Apparently VAAPI is not yet support by Qt Multimedia : https://bugreports.qt-project.org/browse/QTBUG-23761 – RzR Sep 01 '14 at 13:19