how to get media file information.
-
@Diracsbracket
yes .
but don't know how to use that . -
@saber said in how to get media file information.:
but don't know how to use that
This is a minimal example you can try out:
(based on: http://qt.shoutwiki.com/wiki/Using_Qt_Mobility_to_get_metadata_from_media_files)- Define player as a class member:
private: QMediaPlayer *m_player;
- In your code:
m_player = new QMediaPlayer(this); connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged(QMediaPlayer::MediaStatus))); m_player->setMedia(QUrl::fromLocalFile("C:\\yourMovie.avi"));
- Define the
onMediaStatusChanged
slot e.g. as follows:
void MainWindow::onMediaStatusChanged(QMediaPlayer::MediaStatus status) { if (status == QMediaPlayer::LoadedMedia) GetMetaData(m_player); }
- The
GetMetaData()
method lists all available metadata:
void MainWindow::GetMetaData(QMediaPlayer *player) { // Get the list of keys there is metadata available for QStringList metadatalist = player->availableMetaData(); // Get the size of the list int list_size = metadatalist.size(); //qDebug() << player->isMetaDataAvailable() << list_size; // Define variables to store metadata key and value QString metadata_key; QVariant var_data; for (int indx = 0; indx < list_size; indx++) { // Get the key from the list metadata_key = metadatalist.at(indx); // Get the value for the key var_data = player->metaData(metadata_key); qDebug() << metadata_key << var_data.toString(); } }
The output on a sample .avi movie on my system is:
"AudioBitRate" "128000" "AudioCodec" "MPEG Audio Layer-3 (MP3)" "ChannelCount" "2" "Copyright" "SaM" "Duration" "5069876" "PixelAspectRatio" "" "Resolution" "" "SampleRate" "48000" "VideoBitRate" "1028056" "VideoCodec" "MPEG-4 part 2 Video (MP4V)" "VideoFrameRate" "24"
-
@Diracsbracket
thank you very much.some questions
why we not getting Resolution,PixelAspectRatio ??and we ONLY get the metadata what is Available??
-
@saber said in how to get media file information.:
Resolution,PixelAspectRatio
Probably because this info is not available in the AVI header (maybe not part of the AVI specs?).
@saber said in how to get media file information.:
and we ONLY get the metadata what is Available
You could probably use the
metaData()
method to query by key all the possible/relevant
keys defined in theQMediaMetaData
namespace, and check if it returns something valid?QVariant metaData(const QString &key) const;
Also keep in mind that Qt's Multimedia framework is not as complete as some of the specialized libraries out there.
-
@Diracsbracket thanks.
this way can i get image info??
if yes , how to get that?some of the specialized libraries out there.
please give me some suggestion.
-
@saber said in how to get media file information.:
this way can i get image info
It doesn't seem to work for images (as tested from the minimal example I posted above...)
But, from searching on this forum (or on Google), the answer for pictures is given here:
https://forum.qt.io/topic/83259/get-metadata-date-taken-location-from-photo-jpeg/2
https://github.com/mayanklahiri/easyexif@saber said in how to get media file information.:
please give me some suggestion
Have a look at:
http://en.cppreference.com/w/cpp/links/libs -
@Diracsbracket
hi .
i found a library called mediainfo .here is the github
it has a example made by qt.
but i don't understand how to build it or use it as a lib.
can you help?and i tried this but not getting the duration.
m_player->metaData(QMediaMetaData::Duration).toString();
just giving me this "QVariant(Invalid)"
-
@saber said in how to get media file information.:
can you help?
As @SGaist suggested, I'm affraid that you will have to ask the authors of that library, as I haven't tried that one yet :-(.
@saber said in how to get media file information.:
just giving me this "QVariant(Invalid)"
Since
QMediaMetaData::Duration
is aqint64
as per http://doc.qt.io/qt-5/qmediametadata.html, maybe try as follows:QString::number(m_player->metaData(QMediaMetaData::Duration))
-
This post is deleted!
-
@Diracsbracket
Thanks, mediainfo builds fine in my linux system.
i want it as a lib(exclude all the gui and extra pieces) so it will be easer to include it in my project.
i wanted to make a function that will take the file path >> send it to that lib >>lib will give the all the mediainfo.
but i have no idea or programming skills to do that .so if you want the same ,please modify the mideainfo to a library.
thanks -
@saber said in how to get media file information.:
i want it as a lib
MediaInfoLib
IS the lib. I thought this would have been clear enough...
MediaInfo
is just an application using it. Study that example to learn how to use it. -
oh!ok.
can you show me the lib folder?
and how to include it in .pro .
an example will be great!! -
@saber said in how to get media file information.:
can you show me the lib folder?
and how to include it in .pro .
an example will be great!!As I wrote. Study the example. You said
MediaInfo
builds correctly on your system, so you have access to all the info you need, since it builds perfectly in Qt Creator. Don't expect everything to be done for you...
Good luck!