[vlc-devel] [PATCH] QtPlayer example: Add 360 video panning

Ayush Sinha ayush.sinha09 at gmail.com
Tue May 19 18:45:48 CEST 2020


Hi,

360 video panning in the Qt sample player since vlc supports 360 videos. It
might be a good starting point.

From: Ayush Sinha <ayush.sinha09 at gmail.com>

    QtPlayer example: Add 360 video panning

diff --git a/doc/libvlc/QtPlayer/QtVLC.pro b/doc/libvlc/QtPlayer/QtVLC.pro
index c050c97126..e358b3b055 100644
--- a/doc/libvlc/QtPlayer/QtVLC.pro
+++ b/doc/libvlc/QtPlayer/QtVLC.pro
@@ -3,6 +3,7 @@ TARGET = qtvlc
 DEPENDPATH += .
 INCLUDEPATH += .
 LIBS += -lvlc -lX11
+QT += widgets

 # Input
 HEADERS += player.h
diff --git a/doc/libvlc/QtPlayer/player.cpp b/doc/libvlc/QtPlayer/player.cpp
index 6a25564c62..e98e05262c 100644
--- a/doc/libvlc/QtPlayer/player.cpp
+++ b/doc/libvlc/QtPlayer/player.cpp
@@ -11,6 +11,12 @@
 #define qtu( i ) ((i).toUtf8().constData())

 #include <QtGui>
+#include <QMessageBox>
+#include <QMenuBar>
+#include <QAction>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QFileDialog>

 Mwindow::Mwindow() {
     vlcPlayer = NULL;
@@ -89,7 +95,7 @@ void Mwindow::initUI() {

     /* Central Widgets */
     QWidget* centralWidget = new QWidget;
-    videoWidget = new QWidget;
+    videoWidget = new VideoWidget();

     videoWidget->setAutoFillBackground( true );
     QPalette plt = palette();
@@ -133,6 +139,14 @@ void Mwindow::openFile() {
     /* Create a new libvlc player */
     vlcPlayer = libvlc_media_player_new_from_media (vlcMedia);

+    /* Mouse/keyboard input disable so video widget can receive mouse
events */
+    libvlc_video_set_mouse_input(vlcPlayer, 0);
+    libvlc_video_set_key_input(vlcPlayer, 0);
+
+    /* Set the media player instance in VideoWidget */
+    if(vlcPlayer)
+        videoWidget->setVlcMediaPlayer(vlcPlayer);
+
     /* Release the media */
     libvlc_media_release(vlcMedia);

@@ -250,3 +264,43 @@ void Mwindow::closeEvent(QCloseEvent *event) {
     stop();
     event->accept();
 }
+
+/* ##################################################
+ * VideoWidget
+ * ##################################################
+ */
+
+void VideoWidget::setVlcMediaPlayer(libvlc_media_player_t *mp) {
+    mVlcPlayer = mp;
+    currentViewpoint = libvlc_video_new_viewpoint();
+    libvlc_video_update_viewpoint(mVlcPlayer, currentViewpoint, true);
+}
+
+void VideoWidget::mousePressEvent(QMouseEvent *event) {
+    currentX = event->x();
+    currentY = event->y();
+}
+
+void VideoWidget::mouseReleaseEvent(QMouseEvent *event) {
+    currentX = -1;
+    currentY = -1;
+}
+
+void VideoWidget::mouseMoveEvent(QMouseEvent *event) {
+    dx = event->x() - currentX;
+    dy = event->y() - currentY;
+    currentX = event->x();
+    currentY = event->y();
+
+    float yaw = -1 * moveSensitivity * dx;
+    float pitch = -1 * moveSensitivity * dy;
+
+    currentViewpoint->f_yaw = yaw;
+    currentViewpoint->f_pitch = pitch;
+    currentViewpoint->f_roll = currentViewpoint->f_field_of_view = 0;
+
+    if(mVlcPlayer != nullptr)
+        libvlc_video_update_viewpoint(mVlcPlayer, currentViewpoint, false);
+    else
+        qDebug() << "media player is null";
+}
diff --git a/doc/libvlc/QtPlayer/player.h b/doc/libvlc/QtPlayer/player.h
index 495ea95311..551d017926 100644
--- a/doc/libvlc/QtPlayer/player.h
+++ b/doc/libvlc/QtPlayer/player.h
@@ -9,8 +9,35 @@
 #define PLAYER

 #include <QtGui>
+#include <QMainWindow>
+#include <QPushButton>
+#include <QSlider>
+#include <QWidget>
 #include <vlc/vlc.h>

+
+class VideoWidget:public QWidget
+{
+    public:
+        VideoWidget () {}
+        ~VideoWidget () {}
+        void setVlcMediaPlayer(libvlc_media_player_t *mp);
+
+    protected:
+        virtual void mousePressEvent(QMouseEvent *event);
+        virtual void mouseReleaseEvent(QMouseEvent *event);
+        virtual void mouseMoveEvent(QMouseEvent *event);
+
+    private:
+        libvlc_media_player_t *mVlcPlayer = nullptr;
+        libvlc_video_viewpoint_t* currentViewpoint;
+        float dx = 0;
+        float dy = 0;
+        float moveSensitivity = 0.5;
+        int currentX = -1;
+        int currentY = -1;
+};
+
 class Mwindow : public QMainWindow {

     Q_OBJECT
@@ -38,7 +65,7 @@ class Mwindow : public QMainWindow {
                QPushButton *playBut;
                QSlider *volumeSlider;
                QSlider *slider;
-               QWidget *videoWidget;
+               VideoWidget *videoWidget;

                libvlc_instance_t *vlcInstance;
                libvlc_media_player_t *vlcPlayer;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200519/75800d9a/attachment.html>


More information about the vlc-devel mailing list