PyQt5 -- loading serialized videos for playback
-
Hi,
I was wondering if it were possible to load serialized video files in QMediaPlayer a la using 'QPixmap().loadFromData()' ?
I'm loading in serialized video files from mongodb.Thanks!
-
Currently looking at QDataStream...might have the answer.
-
Hi,
What do you mean by serialized videos ?
-
Binary data
-
I'm afraid that's a bit vague.
What format ?
What container ? -
Sorry, I'm still a bit new to doing this but the format is mp4. Not sure what you mean by container but the file was serialized through pymongo using gridfs.
I used the same process to serialize jpeg images and I am able to view them with PyQt using QPixmap().loadFromData().
I was just hoping there was an equivalent with QMediaPlayer for videos.Thanks!
-
AFAIK, no.
However you can copy the data to a temporary file and open it with QMediaPlayer.
-
Ah, that's unfortunate. I was hoping to avoid creating temp files and the like.
Thanks!
-
It's something that is pretty easy with Qt, look at QTemporaryFile
-
I've been reading up on QIODevice and streaming the video but I've been getting errors:
here's the code
a = QByteArray(video_from_binary) b = QBuffer(a) self.mediaPlayer.setMedia(QMediaContent(b))
where self.mediaPlayer is my media player attribute.
I've also seen where a 'QUrl.fromLocalFile()' is passed to setMedia.
I tried 'QUrl.fromEncoded(b)' assuming this might read binary data but to no avail. It still didn't work.If anyone has gotten videos to stream, would you be so kind as to share how you did it? I tried calling the actual video I converted to binary from and it works fine (an .avi) but no such luck for the binary version.
-
AFAIK, there's no support for "in-memory files" like that. Remember that QtMultimedia uses the platform's multimedia framework which don't handle Qt types. If you take for example the handling of Qt's resource system when dealing with multimedia files, a temporary file is created so that the multimedia framework can access it.
If you want something lower level to avoid the temporary file, you'll have to implement it yourself.