QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoRecordingsPage.qml
Go to the documentation of this file.
1pragma ComponentBehavior: Bound
2
3import QtQuick
4import QtQuick.Controls
5import QtQuick.Layouts
6import QtMultimedia
7
8import QGroundControl
9import QGroundControl.AnalyzeView
10import QGroundControl.Controls
11
12// Plays the videos QGroundControl recorded, newest first, with the telemetry of their subtitle files drawn over them.
13AnalyzePage {
14 id: root
15
16 pageComponent: recordingsComponent
17 pageDescription: qsTr("Play the videos QGroundControl recorded, with the telemetry recorded alongside them.")
18
19 readonly property real _margin: ScreenTools.defaultFontPixelWidth
20
21 QGCPalette { id: qgcPal; colorGroupEnabled: true }
22
23 VideoRecordingList { id: recordingList }
24
25 function _formatTime(ms) {
26 const totalSeconds = Math.floor(ms / 1000)
27 const seconds = totalSeconds % 60
28 return Math.floor(totalSeconds / 60) + ":" + (seconds < 10 ? "0" : "") + seconds
29 }
30
31 function _formatSize(bytes) {
32 return bytes >= 1024 * 1024 * 1024
33 ? qsTr("%1 GB").arg((bytes / (1024 * 1024 * 1024)).toFixed(1))
34 : qsTr("%1 MB").arg((bytes / (1024 * 1024)).toFixed(1))
35 }
36
37 Component {
38 id: recordingsComponent
39
40 RowLayout {
41 id: page
42
43 /// The path of the recording playing, empty for none.
44 property string selectedPath: ""
45 readonly property var _selected: {
46 const recordings = recordingList.recordings
47 for (let i = 0; i < recordings.length; i++) {
48 if (recordings[i].path === page.selectedPath) {
49 return recordings[i]
50 }
51 }
52 return null
53 }
54 readonly property bool _hasSubtitles: page._selected !== null && page._selected.subtitles.toString() !== ""
55 readonly property int _seekStepMs: 5000
56
57 width: root.availableWidth
58 height: root.availableHeight
59 spacing: root._margin
60 focus: true
61
62 Keys.onSpacePressed: page._togglePlayback()
63 Keys.onLeftPressed: page._seekBy(-page._seekStepMs)
64 Keys.onRightPressed: page._seekBy(page._seekStepMs)
65
66 function _togglePlayback() {
67 if (page.selectedPath === "") {
68 return
69 }
70 if (player.playbackState === MediaPlayer.PlayingState) {
71 player.pause()
72 } else {
73 player.play()
74 }
75 }
76
77 function _seekBy(ms) {
78 if (player.seekable) {
79 player.position = Math.max(0, Math.min(player.duration, player.position + ms))
80 }
81 }
82
83 function _deleteSelected() {
84 const path = page.selectedPath
85 // Releases the file, which some platforms won't delete while it is open.
86 page.selectedPath = ""
87 if (!recordingList.remove(path)) {
88 QGroundControl.showMessageDialog(root, qsTr("Delete Recording"),
89 qsTr("The recording could not be deleted."))
90 }
91 }
92
93 MediaPlayer {
94 id: player
95
96 source: page._selected ? page._selected.url : ""
97 videoOutput: playerOutput
98 audioOutput: AudioOutput { }
99 playbackRate: speedComboBox.currentValue ?? 1
100
101 onSourceChanged: {
102 if (player.source.toString() !== "") {
103 player.play()
104 }
105 }
106 }
107
108 SubtitleTrack {
109 id: subtitles
110
111 source: page._hasSubtitles ? page._selected.subtitles : ""
112 position: player.position
113 }
114
115 QGCListView {
116 id: recordingListView
117
118 model: recordingList.recordings
119 spacing: root._margin / 2
120 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 32
121 Layout.fillHeight: true
122
123 delegate: Rectangle {
124 id: recordingDelegate
125
126 required property var modelData
127
128 width: recordingListView.width
129 height: recordingColumn.height + root._margin
130 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accent : qgcPal.windowCard
131 radius: root._margin / 2
132
133 ColumnLayout {
134 id: recordingColumn
135
136 spacing: 0
137
138 anchors {
139 verticalCenter: parent.verticalCenter
140 left: parent.left
141 right: parent.right
142 margins: root._margin / 2
143 }
144
145 QGCLabel {
146 text: recordingDelegate.modelData.name
147 elide: Text.ElideMiddle
148 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accentText : qgcPal.textPrimary
149 Layout.fillWidth: true
150 }
151
152 QGCLabel {
153 text: root._formatSize(recordingDelegate.modelData.size) + " "
154 + recordingDelegate.modelData.modified.toLocaleString(Qt.locale(), Locale.ShortFormat)
155 font.pointSize: ScreenTools.smallFontPointSize
156 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accentText : qgcPal.textPrimary
157 Layout.fillWidth: true
158 }
159 }
160
161 MouseArea {
162 anchors.fill: parent
163 onClicked: {
164 page.selectedPath = recordingDelegate.modelData.path
165 page.forceActiveFocus()
166 }
167 }
168 }
169
170 QGCLabel {
171 anchors.fill: parent
172 anchors.margins: root._margin
173 visible: recordingListView.count === 0
174 text: qsTr("No recordings in %1").arg(recordingList.directory)
175 wrapMode: Text.WrapAnywhere
176 horizontalAlignment: Text.AlignHCenter
177 }
178 }
179
180 ColumnLayout {
181 spacing: root._margin
182 Layout.fillWidth: true
183 Layout.fillHeight: true
184
185 Rectangle {
186 color: "black"
187 Layout.fillWidth: true
188 Layout.fillHeight: true
189
190 VideoOutput {
191 id: playerOutput
192
193 anchors.fill: parent
194 endOfStreamPolicy: VideoOutput.KeepLastFrame
195 }
196
197 MouseArea {
198 anchors.fill: parent
199 onClicked: {
200 page.forceActiveFocus()
201 page._togglePlayback()
202 }
203 }
204
205 // The subtitle file's coordinates span the video's frame, as shown.
206 Item {
207 id: subtitleArea
208
209 readonly property real _scaleX: subtitleArea.width / subtitles.playResX
210 readonly property real _scaleY: subtitleArea.height / subtitles.playResY
211 // ASS font sizes are line heights, as players (libass) draw them, not em sizes.
212 readonly property real _fontPixelSize: Math.max(1, subtitles.fontSize * subtitleArea._scaleY
213 * subtitleMetrics.font.pixelSize / subtitleMetrics.height)
214
215 x: playerOutput.contentRect.x
216 y: playerOutput.contentRect.y
217 width: playerOutput.contentRect.width
218 height: playerOutput.contentRect.height
219 visible: page._hasSubtitles && telemetryCheckBox.checked
220
221 FontMetrics {
222 id: subtitleMetrics
223
224 font.family: ScreenTools.fixedFontFamily
225 font.pixelSize: 100
226 }
227
228 Repeater {
229 model: subtitles.events
230
231 Text {
232 id: subtitleText
233
234 required property var modelData
235
236 // Alignment as a numeric keypad: the column and row of the text the anchor point is on.
237 readonly property int _column: (subtitleText.modelData.alignment - 1) % 3
238 readonly property int _row: Math.floor((subtitleText.modelData.alignment - 1) / 3)
239
240 x: subtitleText.modelData.x * subtitleArea._scaleX - subtitleText._column * subtitleText.width / 2
241 y: subtitleText.modelData.y * subtitleArea._scaleY - (2 - subtitleText._row) * subtitleText.height / 2
242 text: subtitleText.modelData.text
243 horizontalAlignment: subtitleText._column === 0 ? Text.AlignLeft
244 : (subtitleText._column === 1 ? Text.AlignHCenter : Text.AlignRight)
245 color: "white"
246 style: Text.Outline
247 styleColor: "black"
248 font.family: ScreenTools.fixedFontFamily
249 font.pixelSize: subtitleArea._fontPixelSize
250 }
251 }
252 }
253
254 QGCLabel {
255 anchors.centerIn: parent
256 visible: page.selectedPath === ""
257 text: qsTr("Select a recording to play it")
258 color: "white"
259 }
260
261 QGCLabel {
262 visible: player.error !== MediaPlayer.NoError
263 text: player.errorString
264 color: "white"
265 wrapMode: Text.WordWrap
266
267 anchors {
268 left: parent.left
269 right: parent.right
270 bottom: parent.bottom
271 margins: root._margin
272 }
273 }
274 }
275
276 RowLayout {
277 spacing: root._margin
278 enabled: page.selectedPath !== ""
279 Layout.fillWidth: true
280
281 QGCButton {
282 text: player.playbackState === MediaPlayer.PlayingState ? qsTr("Pause") : qsTr("Play")
283 onClicked: page._togglePlayback()
284 }
285
286 QGCSlider {
287 id: seekSlider
288
289 from: 0
290 to: Math.max(1, player.duration)
291 stepSize: page._seekStepMs
292 enabled: player.seekable
293 Layout.fillWidth: true
294 onMoved: player.position = seekSlider.value
295
296 // Playback must not pull the handle back from under a drag.
297 Binding on value {
298 value: player.position
299 when: !seekSlider.pressed
300 restoreMode: Binding.RestoreNone
301 }
302 }
303
304 QGCLabel {
305 text: root._formatTime(player.position) + " / " + root._formatTime(player.duration)
306 }
307
308 QGCComboBox {
309 id: speedComboBox
310
311 textRole: "text"
312 valueRole: "value"
313 currentIndex: 1
314 sizeToContents: true
315 model: [
316 { text: "0.5x", value: 0.5 },
317 { text: "1x", value: 1.0 },
318 { text: "2x", value: 2.0 }
319 ]
320 }
321
322 QGCCheckBox {
323 id: telemetryCheckBox
324
325 text: qsTr("Telemetry")
326 checked: true
327 visible: page._hasSubtitles
328 }
329
330 QGCButton {
331 text: qsTr("Delete")
332 onClicked: QGroundControl.showMessageDialog(
333 root,
334 qsTr("Delete Recording"),
335 qsTr("%1 and its telemetry will be deleted permanently. Is this really what you want?")
336 .arg(page._selected ? page._selected.name : ""),
337 Dialog.Yes | Dialog.No,
338 function() { page._deleteSelected() })
339 }
340 }
341 }
342 }
343 }
344}