0
from PyQt5 import QtMultimedia, QtMultimediaWidgets
from PyQt5.QtCore import QDir, Qt, QUrl, QSizeF
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer, QMediaPlaylist
from PyQt5.QtMultimediaWidgets import QVideoWidget, QGraphicsVideoItem
from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
                             QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget, QStackedWidget,
                             QStackedLayout, QGraphicsView, QGraphicsScene)
from PyQt5.QtWidgets import QMainWindow,QWidget, QPushButton, QAction
from PyQt5.QtGui import QIcon
import sys, glob

class VerySimpleMediaPlayer(QWidget):
    def __init__(self, parent):
        super().__init__(parent)
        self.media_player = QtMultimedia.QMediaPlayer(self)
        self.media_widget = QtMultimediaWidgets.QVideoWidget(self)
        self.media_player.setVideoOutput(self.media_widget)
        self.media_widget.show()
        self.media_player.setMedia(QMediaContent(QUrl.fromLocalFile('avideo.mp4')))
        self.media_player.mediaStatusChanged.connect(self.look)
        layout = QVBoxLayout()
        self.real = QStackedWidget()
        self.button = QPushButton()
        self.button.setText('Push Me PLS!')
        self.real.addWidget(self.button)
        self.button.clicked.connect(self.clicked)
        self.real.addWidget(self.media_widget)
        layout.addWidget(self.real)
        self.setLayout(layout)
        self.awidget = QWidget()
        bx = QVBoxLayout()
        lbl = QLabel()
        lbl.setText('Video Has Finished!')
        bx.addWidget(lbl)
        self.awidget.setLayout(bx)
        self.real.addWidget(self.awidget)
    def clicked(self):
        self.media_player.play()
        self.real.setCurrentIndex(self.real.currentIndex() + 1)
    def look(self, state):
        if state == 7:
            self.real.setCurrentIndex(self.real.currentIndex() + 1)


app = QApplication(sys.argv)
player = QMainWindow()
player.setCentralWidget(VerySimpleMediaPlayer(player))
player.show()
sys.exit(app.exec_())

It works good but the only problem is that the videos are playing horizontally even if the video is a vertical video like 800 x 1600.

Is there any way to rotate videos either automatically or non-automatically?

musicamante
  • 41,230
  • 6
  • 33
  • 58
pirxwes
  • 11
  • 3
  • Does this answer your question? [How to rotate video in QVideoWidget in PyQt5](https://stackoverflow.com/questions/68840839/how-to-rotate-video-in-qvideowidget-in-pyqt5) – musicamante Feb 02 '22 at 14:29
  • I've seen this before but it seems like it has a different structure so it doesn't at last unfortunately – pirxwes Feb 02 '22 at 14:46
  • That's the easiest way to do it, the only alternative is through subclassing of QAbstractVideoSurface and rotating each QVideoFrame, but doing it from python can really affect performance for high resolution video and introduce other problems unless you know what you're doing it. – musicamante Feb 02 '22 at 15:16
  • Would you share a code to me? @musicamante I mean what must I do right now? Thanks for helping by the way :D – pirxwes Feb 02 '22 at 19:49

0 Answers0