-2

i have an encrypted video file, i want to decrypt this file into memory and then use this data play video. but qt mediaplayer class is to pass a file name in, i need to have any good way?

this is my code

#!/usr/bin/env python

from PyQt5.QtCore import QFile, QFileInfo, QIODevice, QUrl, QDataStream
from PyQt5.QtWidgets import QApplication
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidget

if __name__ == '__main__':

import sys
app = QApplication(sys.argv)
player = QMediaPlayer()

file = QFile('mymusic.avi')
stream = QDataStream(file)
# this is where i want read form stream? how can i read from stream?
player.setMedia(QMediaContent(QUrl.fromLocalFile('mymusic.avi')))

videoWidget = QVideoWidget()
player.setVideoOutput(videoWidget)
videoWidget.show()

player.play()
sys.exit(app.exec_())

look, param is filename,but i want to read from a binary data,how can i do?

xiao ta
  • 11
  • 3

1 Answers1

1

i have solved this problem, and the solutions are as follows code

#!/usr/bin/env python

from PyQt5.QtCore import QFile, QFileInfo, QIODevice, QUrl, QDataStream, QBuffer, QByteArray
from PyQt5.QtWidgets import QApplication
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidget

if __name__ == '__main__':

import sys
app = QApplication(sys.argv)
player = QMediaPlayer()

file = QFile('mymusic-encrypt.avi')

isOpen = file.open(QIODevice.ReadOnly)

buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)

player.setMedia(QMediaContent(), buffer)

if isOpen:
    while not file.atEnd():
        temp = file.readLine()
        # temp = QByteArray.fromBase64(temp)
        buffer.write(temp)

videoWidget = QVideoWidget()
player.setVideoOutput(videoWidget)
videoWidget.show()

player.play()
sys.exit(app.exec_())

i need carefully read api, thanks everyone.

xiao ta
  • 11
  • 3