Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
video.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
/* Video related snippets */
5
#
include
"qvideorenderercontrol.h"
6
#
include
"qmediaplayer.h"
7
#
include
"qvideosink.h"
8
#
include
"qvideowindowcontrol.h"
9
#
include
"qgraphicsvideoitem.h"
10
#
include
"qvideoframeformat.h"
11
12
#
include
<
QFormLayout
>
13
#
include
<
QGraphicsView
>
14
15
//! [Video producer]
16
class
MyVideoProducer
:
public
QObject
17
{
18
Q_OBJECT
19
Q_PROPERTY(QVideoSink *videoSink READ videoSink WRITE setVideoSink)
20
21
public
:
22
QVideoSink
*
videoSink
()
const
{
return
m_sink
; }
23
24
void
setVideoSink
(
QVideoSink
*
sink
)
25
{
26
m_sink
=
sink
;
27
}
28
29
// ...
30
31
public
slots
:
32
void
onNewVideoContentReceived
(
const
QVideoFrame
&
frame
)
33
{
34
if
(
m_sink
)
35
m_sink
->
setVideoFrame
(
frame
);
36
}
37
38
private
:
39
QVideoSink
*
m_sink
;
40
};
41
42
//! [Video producer]
43
44
45
class
VideoExample
:
public
QObject
{
46
Q_OBJECT
47
public
:
48
void
VideoGraphicsItem
();
49
void
VideoWidget
();
50
void
VideoWindowControl
();
51
void
VideoWidgetControl
();
52
void
VideoSurface
();
53
54
private
:
55
// Common naming
56
QVideoWidget *videoWidget;
57
QWidget *widget;
58
QFormLayout *layout;
59
QVideoSink *myVideoSink;
60
QMediaPlayer *player;
61
QMediaContent video;
62
QGraphicsView *graphicsView;
63
};
64
65
void
VideoExample
::
VideoWidget
()
66
{
67
//! [Video widget]
68
player =
new
QMediaPlayer;
69
player->setSource(QUrl(
"http://example.com/myclip1.mp4"
));
70
71
videoWidget =
new
QVideoWidget;
72
player->setVideoOutput(videoWidget);
73
74
videoWidget->show();
75
player->play();
76
//! [Video widget]
77
78
player->stop();
79
80
//! [Setting surface in player]
81
player->setVideoOutput(myVideoSink);
82
//! [Setting surface in player]
83
}
84
85
void
VideoExample
::
VideoSurface
()
86
{
87
//! [Widget Surface]
88
QImage img = QImage(
"images/qt-logo.png"
).convertToFormat(QImage::Format_ARGB32);
89
QVideoFrameFormat format(img.size(), QVideoFrameFormat::Format_ARGB8888);
90
videoWidget =
new
QVideoWidget;
91
videoWidget->videoSurface()->start(format);
92
videoWidget->videoSurface()->present(img);
93
videoWidget->show();
94
//! [Widget Surface]
95
96
//! [GraphicsVideoItem Surface]
97
QGraphicsVideoItem *item =
new
QGraphicsVideoItem;
98
graphicsView->scene()->addItem(item);
99
graphicsView->show();
100
QImage img = QImage(
"images/qt-logo.png"
).convertToFormat(QImage::Format_ARGB32);
101
item->videoSink()->setVideoFrame(QVideoFrame(img));
102
//! [GraphicsVideoItem Surface]
103
}
104
105
void
VideoExample
::VideoGraphicsItem()
106
{
107
//! [Video graphics item]
108
player =
new
QMediaPlayer(
this
);
109
110
QGraphicsVideoItem *item =
new
QGraphicsVideoItem;
111
player->setVideoOutput(item);
112
graphicsView->scene()->addItem(item);
113
graphicsView->show();
114
115
player->setSource(QUrl(
"http://example.com/myclip4.ogv"
));
116
player->play();
117
//! [Video graphics item]
118
}
MyVideoProducer
[Video producer]
Definition
video.cpp:17
VideoExample
[Video producer]
Definition
video.cpp:45
VideoExample::VideoWindowControl
void VideoWindowControl()
VideoExample::VideoWidgetControl
void VideoWidgetControl()
VideoExample::VideoSurface
void VideoSurface()
Definition
video.cpp:85
VideoExample::VideoWidget
void VideoWidget()
Definition
video.cpp:65
qtmultimedia
src
multimedia
doc
snippets
multimedia-snippets
video.cpp
Generated on
for Qt by
1.18.0