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 攝像頭概述 and 音頻概述 .
可以使用 QMediaPlayer 類解碼視頻文件,和顯示它使用 QVideoWidget , QGraphicsVideoItem ,或自定義類。
此處範例,使用 QVideoWidget :
player = new QMediaPlayer; player->setSource(QUrl("http://example.com/myclip1.mp4")); videoWidget = new QVideoWidget; player->setVideoOutput(videoWidget); videoWidget->show(); player->play();
和範例采用 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();
可以使用 VideoOutput 渲染的內容提供通過 MediaPlayer 或 Camera 。 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 。 Video element has been provided for convenience. It combines MediaPlayer , VideoOutput and AudioOutput elements in one item.
Qt Multimedia 提供瞭許多低級類以使處理視頻幀變得更容易一些。這些類首要用於編寫處理視頻或攝像頭幀的代碼 (例如:檢測條碼或應用花哨暈影效果),或需要以其它不受支持的特殊方式顯示視頻。
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 允許接收這些幀從 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.
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 supported media formats for this information.
On Linux this is about installing the correct GStreamer 插件。
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.
存在 C++ 和 QML 兩種可用範例。
| 攝像頭範例 | Shows how to capture a still image or record video. or video. |
| 媒體播放器範例 | 播放音頻和視頻。 |
| QML Media Player Example | Playing audio and video using Qt Quick. |
| QML Video Recorder | Recording audio and video using Qt Quick. |
| QMediaCaptureSession | Allows capturing of audio and video content |
| QMediaPlayer | Allows the playing of a media files |
| QMediaRecorder | Used for encoding and recording a capture session |
| QScreenCapture | Used for capturing a screen |
| QVideoFrame | 錶示視頻數據幀 |
| QVideoFrameFormat | 指定視頻呈現錶麵的流格式 |
| QVideoSink | Represents a generic sink for video data |
| QVideoWidget | 呈現媒體對象産生視頻的小部件 |
| CaptureSession | Allows capturing of audio and video content |
| MediaPlayer | Adds media playback to a scene |
| MediaRecorder | For encoding and recording media generated in a CaptureSession |
| ScreenCapture | Type is used for capturing a screen |
| Video | 展示指定視頻的方便類型 |
| VideoOutput | 渲染視頻或攝像頭取景器 |
| cameraDevice | Describes a camera device |
| cameraFormat | Describes a video format supported by a camera device |
| mediaMetaData | Provides meta-data for media files |