Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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"
10#include "qvideoframeformat.h"
11
12#include <QFormLayout>
13#include <QGraphicsView>
14
17{
20
21public:
22 QVideoSink* videoSink() const { return m_sink; }
23
25 {
26 m_sink = sink;
27 }
28
29 // ...
30
31public slots:
33 {
34 if (m_sink)
35 m_sink->setVideoFrame(frame);
36 }
37
38private:
39 QVideoSink *m_sink;
40};
41
43
44
45class VideoExample : public QObject {
47public:
48 void VideoGraphicsItem();
49 void VideoWidget();
52 void VideoSurface();
53
54private:
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
66{
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();
77
78 player->stop();
79
81 player->setVideoOutput(myVideoSink);
83}
84
86{
88 QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
90 videoWidget = new QVideoWidget;
91 videoWidget->videoSurface()->start(format);
92 videoWidget->videoSurface()->present(img);
93 videoWidget->show();
95
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));
103}
104
106{
108 player = new QMediaPlayer(this);
109
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();
118}
[Video producer]
Definition video.cpp:17
void setVideoSink(QVideoSink *sink)
Definition video.cpp:24
QVideoSink * videoSink() const
Definition video.cpp:22
void onNewVideoContentReceived(const QVideoFrame &frame)
Definition video.cpp:32
QVideoSink * videoSink
Definition video.cpp:19
The QFormLayout class manages forms of input widgets and their associated labels.
Definition qformlayout.h:18
void addItem(QGraphicsItem *item)
Adds or moves the item and all its children to this scene.
The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaPlayer ...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
QGraphicsScene * scene() const
Returns a pointer to the scene that is currently visualized in the view.
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32
Definition qimage.h:47
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
Definition qimage.h:125
The QMediaPlayer class allows the playing of a media files.
void setSource(const QUrl &source)
\qmlproperty url QtMultimedia::MediaPlayer::source
void setVideoOutput(QObject *)
void stop()
\qmlmethod QtMultimedia::MediaPlayer::stop()
void play()
\qmlmethod QtMultimedia::MediaPlayer::play()
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
Definition qurl.h:94
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:27
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
void setVideoFrame(const QVideoFrame &frame)
Sets the current video frame.
The QVideoWidget class provides a widget which presents video produced by a media object.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
[Video producer]
Definition video.cpp:45
void VideoWindowControl()
void VideoWidgetControl()
void VideoSurface()
Definition video.cpp:85
void VideoGraphicsItem()
Definition video.cpp:105
void VideoWidget()
Definition video.cpp:65
GLint GLsizei GLsizei GLenum format
GLint void * img
Definition qopenglext.h:233
GLsizei GLenum GLboolean sink
#define Q_PROPERTY(...)
#define Q_OBJECT
#define slots
QGraphicsItem * item
QFrame frame
[0]