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 |