joe_frank 2017-07-15 15:11 采纳率: 0%
浏览 4871

Qt creator用QMultimedia做视频播放器没图像

如题,我从网上参考了相关教程自己写了一个(原码在最后),是在Deepin环境下,编译是没错的,结果运行时弹出的窗口是全黑的,视频播放不出来,但奇怪的是有声音,即使把窗口关了也还有声音。如果我换到windows环境下,把相关的库和文件都改成windows的,也是没有报错,但直接连黑窗口都弹不出来了。我用的Qt5.9.1,创建工程时用的是QWidget基类(用其他的没写出来)。在百度上找了很长时间,说是没有gstreamer0.10-ffmpeg解码器,我试过了,这个解码器根本就下载不了。截图如下:
图片说明
关于安装这个解码器的问题,百度说直接从官网上找安装包手动下载,我把好多安装包下载完了,结果都提示不能安装:图片说明
又有说是源的问题,我从网上找了好多源,然后挨个换,都不能安装。还有说系统要升级到最新,可是我也升级了啊,也没什么用。不想放弃,希望得到指点,如果能得到任何帮助,我将不胜感激。
原码如下:
图片说明
图片说明
图片说明
图片说明
那个player.ui我只是画了一些按钮,没有去实现,因为在播放这块儿卡住了。
这是.pro文件:
#-------------------------------------------------
#

Project created by QtCreator 2017-07-15T09:24:24

#
#-------------------------------------------------

QT += core gui\
multimedia\
multimediawidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = test5
TEMPLATE = app

The following define makes your compiler emit warnings if you use

any feature of Qt which as been marked as deprecated (the exact warnings

depend on your compiler). Please consult the documentation of the

deprecated API in order to know how to port your code away from it.

DEFINES += QT_DEPRECATED_WARNINGS

You can also make your code fail to compile if you use deprecated APIs.

In order to do so, uncomment the following line.

You can also select to disable deprecated APIs only up to a certain version of Qt.

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
player.cpp
HEADERS += \
player.h

FORMS += \
player.ui

 #ifndef PLAYER_H
#define PLAYER_H

#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>

namespace Ui {
class Player;
}

class Player : public QWidget
{
    Q_OBJECT

public:
    explicit Player(QWidget *parent = 0);
    ~Player();

private:
    Ui::Player *ui;
    QVideoWidget *videow;
    QMediaPlayer *player;
};

#endif // PLAYER_H

```这是main.cpp:
#include "player.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Player w;
    w.show();

    return a.exec();
}


```这是player.cpp:
 #include "player.h"
#include "ui_player.h"

Player::Player(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Player)
{
    ui->setupUi(this);
    videow = new QVideoWidget();
    player = new QMediaPlayer();
    player->setVideoOutput(videow);
    player->setMedia(QUrl::fromLocalFile(QStringLiteral("/home/joe/Videos/U6-1.mpg")));
    videow->show();
    player->play();
}

Player::~Player()
{
    delete ui;
}

  • 写回答

3条回答

  • threenewbee 2017-07-16 02:00
    关注

    有声音没有图像往往是视频编码器缺少或者格式问题。
    用格式工厂这个软件(在windows下运行)转换下视频编码,再试试看

    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题