可怕的性能与QMediaPlayer和QVideoWidget [英] Terrible performance with QMediaPlayer and QVideoWidget

查看:6117
本文介绍了可怕的性能与QMediaPlayer和QVideoWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ubuntu 10.10 (Pentium 4)上尝试使用 QtMobility 1.2.0 Qt 4.7.4 播放视频时, 2.80GHz)。

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

有趣的是, totem (也使用gstreamer 作为后端)和 vlc

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

根据顶部,您可以在这台机器上播放这些视频,即使具有更高的分辨率我的应用程序消耗 100%的CPU,而图腾和vlc只消耗〜40%。这很奇怪!所以我共享下面的应用程序的源代码。它使用 QMediaPlayer QVideoWidget 来完成这项工作。

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?

如果有人感兴趣, ffmpeg 会显示我用于测试的视频文件的信息:

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


推荐答案

p>你的代码没有什么问题,你只是把球传给Qt来解码和播放电影。

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

你使用的是Qt没有启用硬件加速,或者您的系统没有适当的硬件Qt加速解码和播放。

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.

这篇关于可怕的性能与QMediaPlayer和QVideoWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆