Qt Load and Save media with QDataStream
-
Hello,
I would like to load images, videos, and sounds into my QListWidget.
But I wanted to load them into memory, like this if I want to save it in file with the QDataStream and use it in another computer no need to bring the source files back, just the .project file.Do you have an idea or an example?
-
Hi,
So you want to store some random files in an archive to then reload that archive on another computer with your application ?
-
No what i want for example when i open dialog file and i select sound.mp3 the application load the sound in variable like mysound and save it in file "myproject.dat" by using the QDataStream. in this way i dont need an archive, just load my file "myproject.dat".
-
No what i want for example when i open dialog file and i select sound.mp3 the application load the sound in variable like mysound and save it in file "myproject.dat" by using the QDataStream. in this way i dont need an archive, just load my file "myproject.dat".
@GeminiMan
Hi why not use an external resource file to store the sounds and movies in ?
https://doc.qt.io/qt-5/resources.htmlQt can load files directly from such at runtime.
-
-
No this is not what is required in the work, what they want is selection of media from Filedialog and stored in memory or saved in the project file as in the editing software, it is enough just to reload the project file and you have all the project.
@GeminiMan
Hi
Well you can use QDataStream to store all other files into one big fat binary .dat file but
to use them again, will be hell as QListWidget won't take it directly from some
big file. you would have to very carefully read it back to its original types for Qt to be able to use it.So basically you want to develop sort of your on big media file format where one files stores
other files ?Just trying to understand what the goal is as it seems kinda odd.
-
Hi
Well that should be possible to do with QDataStream but for
sound and movies, you will need
to include a header pr item telling size so you know how much to read pr item for reading them back.
You can write any binary with
https://doc.qt.io/qt-5/qdatastream.html#writeRawDataHowever, Im not sure how easy it will be to actually play the data back as
it not 100% sure Qt Multimedia will allow to directly play from a binary file of custom format.
So you might need to write them back to a temporary file to play it. -
@GeminiMan
Well im not sure its possible even it does accept a buffer
https://stackoverflow.com/questions/42168280/qmediaplayer-play-a-sound-loaded-into-memoryBut maybe the new gst-pipeline: appsrc will allow it
https://doc.qt.io/qt-5/qmediaplayer.html#setMediaBut its not something i have experience with.
-
Get them from what ?
The model view system does not provide special handling for every possible datatypes. Images are a special case because of the decoration role that allows to show them but that 's nice coincidence. It seems you try to reinvent something like HDF5 or Qt's resource system.
You are trying to completely mix the model and the data themselves. if you want to have a view on top of your custom data file, then you will have to implement a model yourself that is able to parse your custom file and provide it's content in that memory only representation you want. But even so, if you want to show your user some video, you'll have to put in disk somewhere as not all platform multimedia backends may support playing from memory.
-
you are off topic @SGaist.
QListWidget is here just to display the name and icon of the media loading, thank you @mrjj this is what I was looking for play a sound or video loaded into memory is QMediaPlayer and QBuffer. QBuffer you used into QDataStream to save.