Video Overview

Video Features

Qt Multimedia offers both high and low level C++ classes for playing and manipulating video data, and QML types for playback and control. Some of these classes also overlap with both camera and audio classes, which can be useful.

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 = new QMediaPlayer;

 playlist = new QMediaPlaylist(player);
 playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
 playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));

 videoWidget = new QVideoWidget;
 player->setVideoOutput(videoWidget);

 videoWidget->show();
 playlist->setCurrentIndex(1);
 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->setMedia(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 transformed or acted upon by shaders (as the QML Video Shader Effects Example shows), while all media decoding and playback control is handled by the MediaPlayer or CaptureSession.

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

You can use the QMediaRecorder class as a simple way to record video to disk. For more advances use cases QMediaCaptureSession provides a more flexible API.

Examples

There are both C++ and QML examples available.

C++ Examples

QML Examples

Reference Documentation

C++ Classes

QVideoFrame

Represents a frame of video data

QVideoFrameFormat

Specifies the stream format of a video presentation surface

QML Types

MediaPlayer

Add media playback to a scene

Playlist

For specifying a list of media to be played

PlaylistItem

Defines an item in a Playlist

Video

A convenience type for showing a specified video

VideoOutput

Render video or camera viewfinder