Qt Multimedia offers both high and low level C++ classes for playing and manipulating video data, and QML types for playback and recording. Some of the classes presented here overlap with what is presented in the Camera Overview and Audio Overview.
Here's an example of using QVideoWidget:
player = new QMediaPlayer; player->setSource(QUrl("http://example.com/myclip1.mp4")); videoWidget = new QVideoWidget; player->setVideoOutput(videoWidget); videoWidget->show(); player->play();
And an example with QGraphicsVideoItem:
player = new QMediaPlayer(this); QGraphicsVideoItem *item = new QGraphicsVideoItem; player->setVideoOutput(item); graphicsView->scene()->addItem(item); graphicsView->show(); player->setSource(QUrl("http://example.com/myclip4.ogv")); player->play();
You can use VideoOutput to render content that is provided by either a MediaPlayer or a Camera. The VideoOutput is a visual component that can be embedded into a QQuickScene or Window, while all media decoding and playback control is handled by the MediaPlayer or CaptureSession. A Video element has been provided for convenience. It combines MediaPlayer, VideoOutput and AudioOutput elements in one item.
Qt Multimedia offers a number of low level classes to make handling video frames a bit easier. These classes are primarily used when writing code that processes video or camera frames (for example, detecting barcodes, or applying a fancy vignette effect), or needs to display video in a special way that is otherwise unsupported.
The QVideoFrame class encapsulates a video frame and allows the contents to be mapped into system memory for manipulation or processing. Using your own QVideoSink allows you to receive these frames from QMediaPlayer and QCamera.
The central class for any type of capturing or recording of audio and video is QMediaCaptureSession (or the CaptureSession QML type). You can connect a QCamera (Camera in QML) and a QMediaRecorder (MediaRecorder)to the session and then ask the media recorder to start recording.
What media formats are supported ultimately depends on the configuration of the target system.
Independent of Windows Media Player, there are of course numerous codec packs that could be installed. See the codec guide site for some examples.
See Android supported media formats for this information.
On Linux this is about installing the correct GStreamer plugins.
For a Linux desktop target, it is strongly recommended to have
gstreamer1.0-libav for good codec coverage and
gstreamer1.0-vaapi to get hardware acceleration.
On embedded Linux, the required set of plugins could be somewhat different.
You can determine what formats are available on a target system at runtime using the static QMediaFormat API.
- Use QMediaFormat::isSupported() on a QMediaFormat::ConversionMode to query a specific format.
- Use QMediaFormat::supportedFileFormats() on a default constructed QMediaFormat to get all the supported file formats.
There are both C++ and QML examples available.
Shows how to capture a still image or record video.
Playing audio and video.
Playing audio and video using Qt Quick
Playing audio and video using Qt Quick.
Recording audio and video using Qt Quick.
Used for getting the basic information of a capturable window
Allows capturing of audio and video content
Allows the playing of a media files
Used for encoding and recording a capture session
This class is used for capturing a screen
Represents a frame of video data
Specifies the stream format of a video presentation surface
Represents a generic sink for video data
Widget which presents video produced by a media object
This class is used for capturing a window
Type is used getting basic of a window that is available for capturing via WindowCapture
Allows capturing of audio and video content
Adds media playback to a scene
For encoding and recording media generated in a CaptureSession
This type is used for capturing a screen
A convenience type for showing a specified video
Render video or camera viewfinder
This type is used for capturing a window
Describes a camera device
Describes a video format supported by a camera device
Provides meta-data for media files
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.