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

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 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?