如何使用pyqt5从内存中读取视频数据 [英] how to read video data from memory use pyqt5
本文介绍了如何使用pyqt5从内存中读取视频数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个加密的视频文件,我想将此文件解密到内存中,然后使用此数据播放视频.但是qt mediaplayer类是传入文件名的,需要有什么好办法吗?
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?
这是我的代码
#!/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?
推荐答案
我已经解决了这个问题,解决方案如下代码
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_())
我需要仔细阅读api,谢谢大家.
i need carefully read api, thanks everyone.
这篇关于如何使用pyqt5从内存中读取视频数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文