简体   繁体   English

QVideoWidget黑色窗口

[英]QVideoWidget black window

I have added QVideoWidget as a child to QWidget, and I am trying to play local avi file, but without success. 我已将QVideoWidget作为子级添加到QWidget,并且我试图播放本地avi文件,但未成功。 Here is the code: 这是代码:

#include "widget.h"
#include <QApplication>
#include <QtWidgets>
#include <QtMultimediaWidgets>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget window;
    window.resize(320, 240);
    window.setWindowTitle(QApplication::translate("childwidget", "Child widget"));
    window.show();

    QMediaPlayer *player = new QMediaPlayer;

    QMediaPlaylist *playlist = new QMediaPlaylist(player);
    playlist->addMedia(QUrl::fromLocalFile("/home/designer/Desktop/drop.avi"));

    QVideoWidget *videoWidget = new QVideoWidget(&window);
    player->setVideoOutput(videoWidget);

    videoWidget->resize(320, 240);
    videoWidget->show();
    playlist->setCurrentIndex(1);
    player->play();

    return a.exec();
}

I included multimedia, multimediawidgets and widgets in my .pro file. 我在.pro文件中包含了多媒体,multimediawidgets和小部件。

Also gstreamer packages are installed with sudo apt-get install gstreamer* libgstreamer* and version is 0.10. gstreamer软件包也与sudo apt-get install gstreamer * libgstreamer *一起安装,版本为0.10。

I am running Debian Wheezy on VMWare and trying to build that code for i386 Desktop machine. 我在VMWare上运行Debian Wheezy,并尝试为i386台式机构建该代码。

Am I missing something important so this code won't work? 我是否错过了一些重要的内容,因此此代码无法正常工作? Only I get is black QVideoWidget window inside parrent QWidget. 我唯一得到的是位于QWidget内部的黑色QVideoWidget窗口。

我认为您忘记了为播放器设置播放列表:

player->setPlaylist(playlist);

This was a bit much for a comment, so I made it an answer. 这需要多加评论,所以我做了一个答复。 But what happens if you use a video that you know works? 但是,如果您使用知道有效的视频会怎样?

Also I have tested the following minimal snippet (see the question about it here ). 我还测试了以下最小片段(请参阅此处的问题)。 Maybe after getting that to work, integrating the playlist can be done easily after. 也许在将其工作后,可以轻松地集成播放列表。

int main( int argc, char **argv ){
    QApplication app(argc, argv);
    QMediaPlayer *media=new QMediaPlayer(0);
    QVideoWidget *video=new QVideoWidget(0); //new QGLWidget()
    media->setVideoOutput(video);
    media->setMedia(QUrl::fromLocalFile("/tmp/avatar.mp4"));
    media->play();
    video->show();
    return app.exec();
}

Your issue seem to be GStreamer-related. 您的问题似乎与GStreamer有关。 Please install a gst123 player (which is pure gstreamer-based player) and make sure it plays the file without printing errors. 请安装一个gst123播放器(这是纯粹的基于gstreamer的播放器),并确保它播放文件时不会出现打印错误。 If it does not, QMediaPlayer will not play it either. 如果没有,QMediaPlayer也将不会播放。

If gst123 does not work, it is either of: 如果gst123不起作用,则为以下之一:

  1. You do not have all necessary GStreamer plugins installed to play this file. 您尚未安装所有必需的GStreamer插件才能播放此文件。 From my experience you need at least the following: 根据我的经验,您至少需要满足以下条件:
 gstreamer-plugins-good gstreamer-plugins-base gstreamer-plugins-ugly gstreamer-plugins-bad-orig-addon gstreamer-plugins-qt5 gstreamer-plugins-bad gstreamer-plugins-good-extra gstreamer-plugins-ugly-orig-addon gstreamer-plugins-libav 

Make sure you install plugins for proper versions (if your machine has gstreamer_0.10 and gstreamer 1.x for example). 确保安装了正确版本的插件(例如,如果您的计算机具有gstreamer_0.10和gstreamer 1.x)。 Qt uses GStreamer 1.x Qt使用GStreamer 1.x

  1. If you're using OpenSuSE, your GStreamer installation is crippled to be practically useless. 如果您使用的是OpenSuSE,则GStreamer的安装将被认为实际上是无用的。 You need to add Packman repository and reinstall all installed GStreamer packages with "vendor change". 您需要添加Packman存储库,然后使用“供应商更改”重新安装所有已安装的 GStreamer软件包。

  2. For some videos the VDPAU driver breaks it in QMediaPlayer (while playing fine with gst123) - try to removing the gstreamer VDPAU plugin to check it. 对于某些视频,VDPAU驱动程序在QMediaPlayer中将其破坏(同时与gst123一起正常播放)-尝试删除gstreamer VDPAU插件进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM