how to read video data from memory use pyqt5

2024/9/20 10:51:26

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 pythonfrom PyQt5.QtCore import QFile, QFileInfo, QIODevice, QUrl, QDataStream
from PyQt5.QtWidgets import QApplication
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidgetif __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?

Answer

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

#!/usr/bin/env pythonfrom 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 QVideoWidgetif __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.

https://en.xdnf.cn/q/119772.html

Related Q&A

Pandas apply custom function to DF

I would like to create a brand new data frame by replacing values of a DF using a custom function. I keep getting the following error "ValueError: The truth value of a Series is ambiguous. Use a.e…

Economy Bot Daily Streak

I have a Discord.py economy bot that includes a daily command It gives everyone each day $50, but there is also a streak system. The first time they claim their daily, the bot gives them $50, day 2 is …

Normalise JSON with Python

Prompt me, please, how to normalize this JSON file using Python? This question is related to the previous The current JSON contains: {"total_stats": [{"domain": "domain.com&qu…

How to change decimal separator?

I have an Excel spreadsheet (an extract from SAP). I turn this into a DataFrame, do calculations and save it to an SQLite database. The Excel spreadsheet has comma as decimal separator. The SQLite data…

Unable to scrape the name from the inner page of each result using requests

Ive created a script in python making use of post http requests to get the search results from a webpage. To populate the results, it is necessary to click on the fields sequentially shown here. Now a …

Python Integer and String Using [duplicate]

This question already has an answer here:How can I concatenate str and int objects?(1 answer)Closed 7 years ago.for size in [1, 2, 3, 4]:result = 0print("size=" + str(size))for element in ra…

Beginner to python: Lists, Tuples, Dictionaries, Sets [duplicate]

This question already has an answer here:What is the difference between lists,tuples,sets and dictionaries? [closed](1 answer)Closed 3 years ago.I have been trying to understand what the difference is…

TypeError: NoneType object is not iterable in Python in csv

I am new to python, and trying to create a program which opens a csv file. The user is supposed to enter a barcode , then the program finds that product and the cost of the product. However I got an er…

No such Element Exception using selenium in python

from selenium import webdriver from selenium.webdriver.common.keys import Keys chrome_path=r"C:\Users\Priyanshu\Downloads\Compressed\chromedriver_win32\chromedriver.exe" driver=webdriver.Chro…

Web scraping, cant get the href of a tag

Im trying to scrape this Page https://rarity.tools/thecryptodads Using Selenium in python. At the top of the right of each card below, theres the owner name that contains a link once pressed, it takes …