Skip to content

Commit

Permalink
Converted video-streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
eunoia-cl committed Sep 18, 2021
1 parent 6691e03 commit 7810df0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
46 changes: 12 additions & 34 deletions docs/ch11-multimedia/src/video-stream/main.qml
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
/*
* Copyright (c) 2013, Juergen Bocklage-Ryannel, Johan Thelin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the editors nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import QtQuick 6.2
import QtQuick
import QtMultimedia

Item {
Window {
width: 1024
height: 600
height: 768
visible: true

CaptureSession {
id: captureSession
camera: Camera {}
videoOutput: output
}

VideoOutput {
id: output
anchors.fill: parent
source: camera
}

Camera {
id: camera
}
Component.onCompleted: captureSession.camera.start()
}
46 changes: 38 additions & 8 deletions docs/ch11-multimedia/video-streams.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
# Video Streams

The `VideoOutput` element is not limited to usage in combination with `MediaPlayer` elements. It can also be used directly with video sources to show a live video stream. Using a `Camera` element as `source` and the application is complete. The video stream from a `Camera` can be used to provide a live stream to the user. This stream works as the search view when capturing photos.
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.

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`.

```qml
import QtQuick 6.2
import QtQuick
import QtMultimedia
Item {
Window {
width: 1024
height: 600
height: 768
visible: true
CaptureSession {
id: captureSession
camera: Camera {}
videoOutput: output
}
VideoOutput {
id: output
anchors.fill: parent
source: camera
}
Camera {
id: camera
}
Component.onCompleted: captureSession.camera.start()
}
```

The `CaptureSession` component provides a simple way to read a camera stream, capture still images or record videos.

```qml
CaptureSession {
id: captureSession
camera: Camera {}
videoOutput: output
}
```

As the `MediaPlayer` component, the `CaptureSession` element provides a `videoOuput` attribute. We can thus use this attribute to configure our own visual component.

Finally, when the application is loaded, we can start the camera recording:

```qml
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.

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).
:::

0 comments on commit 7810df0

Please sign in to comment.