简体   繁体   English

无法在 QML 中播放视频

[英]Unable to play video in QML

I am working on ubuntu 14.04 with Qt 5.8 and trying to play video in my application using Qt multimedia module.我正在使用 ZE8801102A40AD89DDCFDCAEBF008D25Z 5.8 开发 ubuntu 14.04,并尝试使用 Qt 多媒体模块在我的应用程序中播放视频。 I put "QT += quick multimedia" in ".pro".我把“QT +=快速多媒体”放在“.pro”中。

ContentVideo.qml内容视频.qml

import QtQuick 2.1
import QtMultimedia 5.0

Rectangle {
    width: 400
    height: 400
    color:"black"

    MediaPlayer {
        id: mediaPlayer
        autoPlay: true
        autoLoad: true
        source:"/home/macos/Desktop/FroggerHighway.mp4"
    }

    VideoOutput {
        id:videoOutput
        source:mediaPlayer
        anchors.fill: parent
    }
}

main.qml main.qml

import QtQuick 2.1
import QtQuick.Window 2.1

Window {
    id: root
    color: "black"
    width: 400
    height: 400
    visible: true
    ContentVideo {
        anchors.fill: parent
    }
}

My video is not running and I am getting black screen without any error.我的视频没有运行,我得到黑屏,没有任何错误。 QT QML EXAMPLES video is working on my PC. QT QML 示例视频正在我的电脑上运行。 Any help will appreciated, Thank you.任何帮助将不胜感激,谢谢。

MediaPlayer.source is a URI and I don't think the value you are specifying is a valid URI. MediaPlayer.source 是一个 URI,我认为您指定的值不是有效的 URI。 Try adding "file://" in front of the path the the mp4 file.尝试在 mp4 文件的路径前添加“file://”。

I had just met the same issue as yours, it seems that QtMultimedia will looking for decoders from gstreamer in system at run time, so I install video codec package:我刚遇到和你一样的问题,似乎 QtMultimedia 会在运行时从系统中的 gstreamer 中寻找解码器,所以我安装了视频编解码器包:

sudo apt-get install gstreamer1.0-libav gstreamer1.0-vaapi

Then qml video player works correctly now然后 qml 视频播放器现在可以正常工作

If the QML video examples work without any issues it's probably a problem that comes from the lack of codecs to encode your video.如果 QML 视频示例正常工作,则可能是由于缺少用于对视频进行编码的编解码器造成的问题。 Check if you have all the Multimedia Dependencies .检查您是否拥有所有多媒体依赖项 My guess is that the provided video samples are encoded in a open format the support for which is provided by default by your distro.我的猜测是提供的视频样本以开放格式编码,您的发行版默认提供支持。

QT+= multimedia添加到您的.pro文件中。

I faced the same problem on Arch and Debian.我在 Arch 和 Debian 上遇到了同样的问题。 After installing the following packages, everything works fine.安装以下软件包后,一切正常。

ARCH:拱:

  • extra/gstreamer额外/gstreamer
  • aur/gstreamer0.10 aur/gstreamer0.10
  • extra/gst-plugins-base-libs额外/gst-plugins-base-libs
  • extra/gst-plugins-good额外/gst-plugins-good
  • extra/gst-libav额外/gst-libav
  • extra/qt5-tools额外/qt5-工具

Installed with yay :yay安装:

yay -S gstreamer gstreamer0.10 gst-plugins-base-libs gst-plugins-good gst-libav qt5-tools

Debian: Debian:

  • libqt5multimedia5-plugins libqt5multimedia5-plugins
  • gstreamer1.0-plugins-good gstreamer1.0-plugins-good
  • gstreamer1.0-libav gstreamer1.0-libav
  • libqt5multimediagsttools5 libqt5multimediagsttools5

Installed with apt :apt安装:

apt install libqt5multimedia5-plugins 

.mp4 doesn't work on qtMediaplayer! .mp4在qtMediaplayer上不起作用! Try QT-VLC 试试QT-VLC

Since qt6 prefers cmake instead of qmake so in case you want to add multimedia files to your cmake list you could perfrom the steps given below (the solution below worked on a mac (apple silicon))由于 qt6 更喜欢 cmake 而不是 qmake,因此如果您想将多媒体文件添加到 cmake 列表中,您可以执行下面给出的步骤(下面的解决方案适用于 mac(苹果硅))

  1. First download the multimedia package from the qt maintenance tool (QtMultimedia)首先从qt维护工具(QtMultimedia)下载多媒体package 在此处输入图像描述
  1. Add it to the cmake project list by including the following lines通过包含以下行将其添加到 cmake 项目列表中

     find_package(Qt6 6.2 COMPONENTS Multimedia REQUIRED)
  2. Also update the target_link_libraries同时更新 target_link_libraries

     target_link_libraries(yourprojectname, PRIVATE Qt6::Multimedia)
  3. Also set autorcc on同时设置 autocc on

     set(CMAKE_AUTORCC ON)
  4. Save your cmake file保存您的 cmake 文件

  5. Regarding the qml file the following code worked for me without errors关于 qml 文件,以下代码对我有用,没有错误

     import QtQuick import QtQuick.Controls import QtMultimedia ApplicationWindow { width:640 height: 480 visible: true title: "audio player" MediaPlayer { id: player source: "give your path to source file " audioOutput: AudioOutput{} Component.onCompleted:{ player.play(); } } }

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

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