Video Streams
视频流
The VideoOutput
element is not limited to be used in combination with a MediaPlayer
element. It can also be used with various video sources to display video streams.
VideoOutput元素类型不限于与MediaPlayer元素结合使用。它还可以与各种视频源一起使用,以显示视频流。
For instance, we can use the VideoOutput
to display the live video stream of the user's Camera
. To do so, we will combine it with two components: Camera
and CaptureSession
.
例如,我们可以使用VideoOutput来显示用户相机的实时视频流。为此,我们将把它与两个组件结合起来:Camera
和CaptureSession。
import QtQuick
import QtMultimedia
Window {
width: 1024
height: 768
visible: true
CaptureSession {
id: captureSession
camera: Camera {}
videoOutput: output
}
VideoOutput {
id: output
anchors.fill: parent
}
Component.onCompleted: captureSession.camera.start()
}
The CaptureSession
component provides a simple way to read a camera stream, capture still images or record videos.
CaptureSession组件提供了一种读取相机流、捕获静止图像或录制视频的简单方法。
As the MediaPlayer
component, the CaptureSession
element provides a videoOuput
attribute. We can thus use this attribute to configure our own visual component.
作为MediaPlayer组件,CaptureSession元素提供了VideoOutput特性。因此,我们可以使用这个特性来配置我们自己的视觉组件。
Finally, when the application is loaded, we can start the camera recording:
最后,当应用程序加载时,我们可以开始摄像机录制:
Component.onCompleted: captureSession.camera.start()
TIP
注
Depending on your operating system, this application may require sensitive access permission(s). If you run this sample application using the
qml
binary, those permissions will be requested automatically.根据您的操作系统,此应用程序可能需要敏感访问权限。如果使用qml二进制文件运行此示例应用程序,将自动请求这些权限。
However, if you run it as an independant program you may need to request those permissions first (e.g.: under MacOS, you would need a dedicated .plist file bundled with your application).
但是,如果您将其作为独立程序运行,则可能需要首先请求这些权限(例如:在MacOS下,您需要一个与应用程序捆绑在一起的专用.plist文件)。
示例源码下载