Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Video Overview

Video playback

Video Features

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 .

Video Implementation Details

Playing Video in C++

You can use the QMediaPlayer class to decode a video file, and display it using QVideoWidget , QGraphicsVideoItem , or a custom class.

Here’s an example of using QVideoWidget :

player = QMediaPlayer()
player.setSource(QUrl("http://example.com/myclip1.mp4"))
videoWidget = QVideoWidget()
player.setVideoOutput(videoWidget)
videoWidget.show()
player.play()

And an example with QGraphicsVideoItem :

player = QMediaPlayer(self)
item = QGraphicsVideoItem()
player.setVideoOutput(item)
graphicsView.scene().addItem(item)
graphicsView.show()
player.setSource(QUrl("http://example.com/myclip4.ogv"))
player.play()

Playing Video in QML

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.

Working with Low Level Video Frames

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 .

Recording Video

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.

Supported Media Formats

What media formats are supported ultimately depends on the configuration of the target system.

Windows

By default what is available on a MS Windows target depends on the version of Windows Media Player that was packaged with the OS. See the Windows Media Player documentation for official information.

Independent of Windows Media Player, there are of course numerous codec packs that could be installed. See the codec guide site for some examples.

Android

See Android supported media formats for this information.

Linux

On Linux this is about installing the correct GStreamer plugins.

Minimum Required GStreamer Plugins

  • gstreamer1.0-plugins-base

  • gstreamer1.0-plugins-good

  • gstreamer1.0-plugins-pulseaudio

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.

Determining Supported Media Formats at Runtime

You can determine what formats are available on a target system at runtime using the static QMediaFormat API.

Examples

There are both C++ and QML examples available.

C++ Examples

Camera-Example

Shows how to capture a still image or record video.

Media-Player-Example

Playing audio and video.

QML Examples

QML-Media-Player-Example

Playing audio and video using the QML MediaPlayer type.

QML-Video-Recorder

Recording audio and video using Qt Quick.

Reference Documentation

C++ Classes

PySide6.QtMultimedia.QMediaPlayer

The QMediaPlayer class allows the playing of a media files.

PySide6.QtMultimedia.QCapturableWindow

Used for getting the basic information of a capturable window.

PySide6.QtMultimedia.QMediaCaptureSession

The QMediaCaptureSession class allows capturing of audio and video content.

PySide6.QtMultimedia.QMediaRecorder

The QMediaRecorder class is used for encoding and recording a capture session.

PySide6.QtMultimedia.QScreenCapture

This class is used for capturing a screen.

PySide6.QtMultimedia.QVideoFrameInput

The QVideoFrameInput class is used for providing custom video frames to QMediaRecorder or a video output through QMediaCaptureSession.

PySide6.QtMultimedia.QWindowCapture

This class is used for capturing a window.

PySide6.QtMultimedia.QAbstractVideoBuffer

The QAbstractVideoBuffer class is an abstraction for video data.

QAbstractVideoBuffer.MapData

The QAbstractVideoBuffer::MapData structure describes the mapped plane layout.

PySide6.QtMultimedia.QVideoFrame

The QVideoFrame class represents a frame of video data.

PySide6.QtMultimedia.QVideoFrameFormat

The QVideoFrameFormat class specifies the stream format of a video presentation surface.

PySide6.QtMultimedia.QVideoSink

The QVideoSink class represents a generic sink for video data.

PySide6.QtMultimediaWidgets.QVideoWidget

The QVideoWidget class provides a widget which presents video produced by a media object.

QML Types

qml-cameraformat.html

Describes a video format supported by a camera device.

qml-cameradevice.html

Describes a camera device.

qml-qtmultimedia-mediaplayer.html

Adds media playback to a scene.

qml-mediametadata.html

Provides meta-data for media files.

qml-capturablewindow.html

The CapturableWindow type is used getting basic of a window that is available for capturing via WindowCapture.

qml-qtmultimedia-capturesession.html

Allows capturing of audio and video content.

qml-qtmultimedia-mediarecorder.html

For encoding and recording media generated in a CaptureSession.

qml-qtmultimedia-screencapture.html

This type is used for capturing a screen.

qml-qtmultimedia-windowcapture.html

This type is used for capturing a window.

Defines an item in a Playlist.

qml-qtmultimedia-videooutput.html

Render video or camera viewfinder.

qml-qtmultimedia-video.html

A convenience type for showing a specified video.