QMPwidget Documentation



QMPwidget is a small class which allows Qt developers to embed an MPlayer instance into their application for convenient video playback. Starting with version 4.4, Qt can be build with Phonon, the KDE multimedia framework (see http://doc.trolltech.com/phonon-overview.html for an overview). However, the Phonon API provides only a limited amount of functionality, which may be too limited for some purposes.

In contrast, this class provides a way of embedding a full-fledged movie player within an application. This means you can use all of MPlayer's features, but also that you will need to ship a MPlayer binary with your application if you can't make sure that it is already installed on a user system.

For more information about MPlayer, please visit http://www.mplayerhq.hu/ .

Usage information

Including QMPwidget in your project

Please note that in the following, it is assumed you are already using QMake to manage your build system.

As a library

In order to include QMPwidget as a library, your build system needs to be set up using the subdirs template.
Copy the src directory of the source distribution to your project tree. You might want to rename it, e.g. to qmpwidget. Afterwards, rename src.pro to match your directory name, e.g. qmpwidget.pro, and adjust it to your needs. Finally, add the directory to your existing SUBDIRS defintion of the parent directory's project file.

By default, QMPwidget will be built as a single static library located in the parent directory. Therefore, the parts of the program using the widget need to link against it. Furthermore, the directory containing the QMPwidget source should be included in the respective INCLUDEPATH definitions.

As a class

You can also simply add the following files to your project:

qmpwidget.h QMPwidget class definition
qmpwidget.cpp QMPwidget class implementation and related helper classes
qmpyuvreader.h Optional: Needs to be included for pipe mode

Using QMPwidget

You can use QMPwidget just like any other QWidget. First, you should make sure that the MPlayer path used is correct (QMPwidget::mplayerPath()). Next, you can start the MPlayer process using QMPwidget::start(). Finally, load and play a media file or url with QMPwidget::load().

Please refer to the QMPwidget class documentation for detailed usage information.

Video playback modes

Normally, embedding MPlayer into a GUI application is done by attaching the process to an existing window. Unfortunately, this doesn't work on Mac OS X at all, so QMPwidget provides an additional "pipe mode" for running MPlayer on this operating system. Although this mode works on all operating systems, the standard mode should perform significantly better in terms of CPU usage and audio / video synchronization.

The pipe mode is included if the QMake configuration variable pipemode is set.

Keyboard control

The following keyboard shortcuts are implemented. However, you can reimplement QMPwidget::keyPressEvent() and extend this list, of course.

Qt::Key_P, Qt::Key_Space Toggle pause
Qt::Key_F Toggle fullscreen
Qt::Key_Q, Qt::Key_Escape Close the widget
Qt::Key_Plus, Qt::Key_Minus Adjust audio delay by +/- 0.1 seconds
Qt::Key_Left, Qt::Key_Right Seek backward/forward 10 seconds
Qt::Key_Down, Qt::Key_Up Seek backward/forward 1 minute
Qt::Key_PageDown, Qt::Key_PageUp Seek backward/forward 10 minutes
Qt::Key_Asterisk, Qt::Key_Slash Increase or decrease PCM volume
Qt::Key_X, Qt::Key_Z Adjust subtitle delay by +/- 0.1 seconds

A table listing the corresponding key codes can be found at the Qt documentation.


qmpwidget - A Qt widget for embedding MPlayer
Copyright (C) 2010 by Jonas Gehring

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.


QMPwidget uses the YCbCr to RGB conversion routines from mjpegtools (http://mjpeg.sourceforge.net/).

 All Classes Functions Enumerations