Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmediametadata.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qcoreapplication.h>
7#include <QtCore/qdatetime.h>
8#include <QtCore/qobject.h>
9#include <QtCore/qsize.h>
10#include <QtCore/qurl.h>
11#include <QtCore/qvariant.h>
12#include <QtGui/qimage.h>
13#include <QtMultimedia/qmediaformat.h>
14#include <QtMultimedia/private/qmediametadata_p.h>
15
16QT_BEGIN_NAMESPACE
17
18static_assert(QMediaMetaData::Key::CoverArtImage == 25);
19static_assert(QMediaMetaData::NumMetaData == 29);
20
21/*!
22 \class QMediaMetaData
23 \inmodule QtMultimedia
24
25 \brief Provides meta-data for media files.
26
27 \note Not all identifiers are supported on all platforms.
28
29 \table 60%
30 \header \li {3,1}
31 Common attributes
32 \header \li Value \li Description \li Type
33 \row \li Title \li The title of the media. \li QString
34 \row \li Author \li The authors of the media. \li QStringList
35 \row \li Comment \li A user comment about the media. \li QString
36 \row \li Description \li A description of the media. \li QString
37 \row \li Genre \li The genre of the media. \li QStringList
38 \row \li Date \li The recording datetime of the media file, or the encoding datetime of the media stream. \li QDateTime.
39 \row \li Language \li The language of media. \li QLocale::Language
40
41 \row \li Publisher \li The publisher of the media. \li QString
42 \row \li Copyright \li The media's copyright notice. \li QString
43 \row \li Url \li A Url pointing to the origin of the media. \li QUrl
44
45 \header \li {3,1}
46 Media attributes
47 \row \li MediaType \li The type of the media (audio, video, etc). \li QString
48 \row \li FileFormat \li The file format of the media. \li QMediaFormat::FileFormat
49 \row \li Duration \li The duration in milliseconds of the media. \li qint64
50
51 \header \li {3,1}
52 Audio attributes
53 \row \li AudioBitRate \li The bit rate of the media's audio stream in bits per second. \li int
54 \row \li AudioCodec \li The codec of the media's audio stream. \li QMediaFormat::AudioCodec
55
56 \header \li {3,1}
57 Video attributes
58 \row \li VideoFrameRate \li The frame rate of the media's video stream. \li qreal
59 \row \li VideoBitRate \li The bit rate of the media's video stream in bits per second. \li int
60 \row \li VideoCodec \li The codec of the media's video stream. \li QMediaFormat::VideoCodec
61 \row \li HasHdrContent \li True if video is intended for HDR display (FFmpeg and Darwin media backends only). \li bool
62
63 \header \li {3,1}
64 Music attributes
65 \row \li AlbumTitle \li The title of the album the media belongs to. \li QString
66 \row \li AlbumArtist \li The principal artist of the album the media belongs to. \li QString
67 \row \li ContributingArtist \li The artists contributing to the media. \li QStringList
68 \row \li TrackNumber \li The track number of the media. \li int
69 \row \li Composer \li The composer of the media. \li QStringList
70 \row \li LeadPerformer \li The lead performer in the media. \li QStringList
71
72 \row \li CoverArtImage \li An embedded cover art image. \li QImage
73 \row \li ThumbnailImage \li An embedded thumbnail image. (deprecated since 6.12, use CoverArtImage instead) \li QImage
74
75 \header \li {3,1}
76 Image and video attributes
77 \row \li Orientation \li The rotation angle of an image or video. \li int
78 \row \li Resolution \li The dimensions of an image or video. \li QSize
79
80 \endtable
81*/
82
83
84/*!
85 Returns the meta type used to store data for Key \a key.
86*/
87QMetaType QMediaMetaData::keyType(Key key)
88{
89 switch (key) {
90 case Title:
91 case Comment:
92 case Description:
93 case Publisher:
94 case Copyright:
95 case MediaType:
96 case AlbumTitle:
97 case AlbumArtist:
98 return QMetaType::fromType<QString>();
99 case Genre:
100 case Author:
101 case ContributingArtist:
102 case Composer:
103 case LeadPerformer:
104 return QMetaType::fromType<QStringList>();
105
106 case Date:
107 return QMetaType::fromType<QDateTime>();
108
109 case Language:
110 return QMetaType::fromType<QLocale::Language>();
111 case Url:
112 return QMetaType::fromType<QUrl>();
113
114 case Duration:
115 return QMetaType::fromType<qint64>();
116 case FileFormat:
117 return QMetaType::fromType<QMediaFormat::FileFormat>();
118
119 case AudioBitRate:
120 case VideoBitRate:
121 case TrackNumber:
122 case Orientation:
123 return QMetaType::fromType<int>();
124 case AudioCodec:
125 return QMetaType::fromType<QMediaFormat::AudioCodec>();
126 case VideoCodec:
127 return QMetaType::fromType<QMediaFormat::VideoCodec>();
128 case VideoFrameRate:
129 return QMetaType::fromType<qreal>();
130
131
132#if QT_DEPRECATED_SINCE(6, 12)
133 case QtMultimediaPrivate::deprecatedThumbnailImage:
134#endif
135 case CoverArtImage:
136 return QMetaType::fromType<QImage>();
137
138 case Resolution:
139 return QMetaType::fromType<QSize>();
140
141 case HasHdrContent:
142 return QMetaType::fromType<bool>();
143
144 default:
145 return QMetaType::fromType<void>();
146 }
147}
148
149/*!
150 \qmlvaluetype mediaMetaData
151 \ingroup qmlvaluetypes
152 \inqmlmodule QtMultimedia
153 \since 6.2
154 //! \nativetype QMediaMetaData
155 \brief Provides meta-data for media files.
156 \ingroup multimedia_qml
157 \ingroup multimedia_audio_qml
158 \ingroup multimedia_video_qml
159
160 Meta-data is supplementary data describing media.
161 See QMediaMetaData for available meta data attributes.
162*/
163
164/*
165 Some potential attributes to add if we can properly support them.
166 Might require that we add EXIF support to Qt Multimedia
167
168 \header \li {3,1}
169 Photo attributes.
170 \row \li CameraManufacturer \li The manufacturer of the camera used to capture the media. \li QString
171 \row \li CameraModel \li The model of the camera used to capture the media. \li QString
172 \row \li Event \li The event during which the media was captured. \li QString
173 \row \li Subject \li The subject of the media. \li QString
174 \row \li ExposureTime \li Exposure time, given in seconds. \li qreal
175 \row \li FNumber \li The F Number. \li int
176 \row \li ExposureProgram
177 \li The class of the program used by the camera to set exposure when the picture is taken. \li QString
178 \row \li ISOSpeedRatings
179 \li Indicates the ISO Speed and ISO Latitude of the camera or input device as specified in ISO 12232. \li qreal
180 \row \li ExposureBiasValue
181 \li The exposure bias.
182 The unit is the APEX (Additive System of Photographic Exposure) setting. \li qreal
183 \row \li DateTimeOriginal \li The date and time when the original image data was generated. \li QDateTime
184 \row \li DateTimeDigitized \li The date and time when the image was stored as digital data. \li QDateTime
185 \row \li SubjectDistance \li The distance to the subject, given in meters. \li qreal
186 \row \li LightSource
187 \li The kind of light source. \li QString
188 \row \li Flash
189 \li Status of flash when the image was shot. \li QCamera::FlashMode
190 \row \li FocalLength
191 \li The actual focal length of the lens, in mm. \li qreal
192 \row \li ExposureMode
193 \li Indicates the exposure mode set when the image was shot. \li QCamera::ExposureMode
194 \row \li WhiteBalance
195 \li Indicates the white balance mode set when the image was shot. \li QCamera::WhiteBalanceMode
196 \row \li DigitalZoomRatio
197 \li Indicates the digital zoom ratio when the image was shot. \li qreal
198 \row \li FocalLengthIn35mmFilm
199 \li Indicates the equivalent focal length assuming a 35mm film camera, in mm. \li qreal
200 \row \li SceneCaptureType
201 \li Indicates the type of scene that was shot.
202 It can also be used to record the mode in which the image was shot. \li QString
203 \row \li GainControl
204 \li Indicates the degree of overall image gain adjustment. \li qreal
205 \row \li Contrast
206 \li Indicates the direction of contrast processing applied by the camera when the image was shot. \li qreal
207 \row \li Saturation
208 \li Indicates the direction of saturation processing applied by the camera when the image was shot. \li qreal
209 \row \li Sharpness
210 \li Indicates the direction of sharpness processing applied by the camera when the image was shot. \li qreal
211 \row \li DeviceSettingDescription
212 \li Exif tag, indicates information on the picture-taking conditions of a particular camera model. \li QString
213
214 \row \li GPSLatitude
215 \li Latitude value of the geographical position (decimal degrees).
216 A positive latitude indicates the Northern Hemisphere,
217 and a negative latitude indicates the Southern Hemisphere. \li double
218 \row \li GPSLongitude
219 \li Longitude value of the geographical position (decimal degrees).
220 A positive longitude indicates the Eastern Hemisphere,
221 and a negative longitude indicates the Western Hemisphere. \li double
222 \row \li GPSAltitude
223 \li The value of altitude in meters above sea level. \li double
224 \row \li GPSTimeStamp
225 \li Time stamp of GPS data. \li QDateTime
226 \row \li GPSSatellites
227 \li GPS satellites used for measurements. \li QString
228 \row \li GPSStatus
229 \li Status of GPS receiver at image creation time. \li QString
230 \row \li GPSDOP
231 \li Degree of precision for GPS data. \li qreal
232 \row \li GPSSpeed
233 \li Speed of GPS receiver movement in kilometers per hour. \li qreal
234 \row \li GPSTrack
235 \li Direction of GPS receiver movement.
236 The range of values is [0.0, 360),
237 with 0 direction pointing on either true or magnetic north,
238 depending on GPSTrackRef. \li qreal
239 \row \li GPSTrackRef
240 \li Reference for movement direction. \li QChar.
241 'T' means true direction and 'M' is magnetic direction.
242 \row \li GPSImgDirection
243 \li Direction of image when captured. \li qreal
244 The range of values is [0.0, 360).
245 \row \li GPSImgDirectionRef
246 \li Reference for image direction. \li QChar.
247 'T' means true direction and 'M' is magnetic direction.
248 \row \li GPSMapDatum
249 \li Geodetic survey data used by the GPS receiver. \li QString
250 \row \li GPSProcessingMethod
251 \li The name of the method used for location finding. \li QString
252 \row \li GPSAreaInformation
253 \li The name of the GPS area. \li QString
254
255 \endtable
256*/
257
258/*!
259 \enum QMediaMetaData::Key
260
261 The following meta data keys can be used:
262
263 \value Title Media title
264 \value Author Media author
265 \value Comment Comment
266 \value Description Brief desripttion
267 \value Genre Genre the media belongs to
268 \value Date Creation date
269 \value Language Media language
270 \value Publisher Media publisher info.
271 \value Copyright Media copyright info.
272 \value Url Publisher's website URL
273 \value Duration Media playback duration
274 \value MediaType Type of the media
275 \value FileFormat File format
276 \value AudioBitRate
277 \value AudioCodec
278 \value VideoBitRate
279 \value VideoCodec
280 \value VideoFrameRate
281 \value AlbumTitle Album's title
282 \value AlbumArtist Artist's info.
283 \value ContributingArtist
284 \value TrackNumber
285 \value Composer Media composer's info.
286 \value LeadPerformer
287 \value ThumbnailImage Media thumbnail image (deprecated since 6.12, identical to CoverArtImage for backwards compatibility)
288 \value CoverArtImage Media cover art
289 \value Orientation
290 \value Resolution
291 \value [since 6.8] HasHdrContent Video may have HDR content (read only, FFmpeg and Darwin media backends only)
292*/
293
294/*!
295 \variable QMediaMetaData::NumMetaData
296 \internal
297*/
298
299/*!
300 \qmlmethod variant QtMultimedia::mediaMetaData::value(Key key)
301
302 Returns the meta data value for Key \a key, or a null QVariant if no
303 meta-data for the key is available.
304*/
305
306/*!
307 \fn QVariant QMediaMetaData::value(QMediaMetaData::Key key) const
308
309 Returns the meta data value for Key \a key, or a null QVariant if no
310 meta data for the key is available.
311*/
312
313/*!
314 \qmlmethod bool QtMultimedia::mediaMetaData::isEmpty()
315 Returns \c true if the meta data contains no items: otherwise returns \c{false}.
316*/
317
318/*!
319 \fn bool QMediaMetaData::isEmpty() const
320 Returns \c true if the meta data contains no items: otherwise returns \c{false}.
321*/
322
323/*!
324 \qmlmethod void QtMultimedia::mediaMetaData::clear()
325 Removes all data from the MediaMetaData object.
326*/
327
328/*!
329 \fn void QMediaMetaData::clear()
330 Removes all data from the meta data object.
331*/
332
333/*!
334 \qmlmethod void QtMultimedia::mediaMetaData::insert(Key k, variant value)
335 Inserts a \a value into a Key: \a{k}.
336*/
337
338/*!
339 \fn void QMediaMetaData::insert(QMediaMetaData::Key k, const QVariant &value)
340 Inserts a \a value into a Key: \a{k}.
341*/
342/*!
343 \qmlmethod void QtMultimedia::mediaMetaData::remove(Key k)
344 Removes meta data from a Key: \a{k}.
345*/
346
347/*!
348 \fn void QMediaMetaData::remove(QMediaMetaData::Key k)
349 Removes meta data from a Key: \a{k}.
350*/
351
352/*!
353 \qmlmethod list<Key> QtMultimedia::mediaMetaData::keys()
354 Returns a list of MediaMetaData.Keys.
355*/
356
357/*!
358 \fn QMediaMetaData::keys() const
359 Returns a QList of QMediaMetaData::Keys.
360*/
361
362/*!
363 \qmlmethod string QtMultimedia::mediaMetaData::stringValue(Key key)
364 Returns the meta data for key \a key as a QString.
365
366 This is mainly meant to simplify presenting the meta data to a user.
367*/
368/*!
369 Returns the meta data for key \a key as a QString.
370
371 This is mainly meant to simplify presenting the meta data to a user.
372*/
373QString QMediaMetaData::stringValue(QMediaMetaData::Key key) const
374{
375 QVariant value = data.value(key);
376 if (value.isNull())
377 return QString();
378
379 switch (key) {
380 // string based or convertible to string
381 case Title:
382 case Author:
383 case Comment:
384 case Description:
385 case Genre:
386 case Publisher:
387 case Copyright:
388 case Date:
389 case Url:
390 case MediaType:
391 case AudioBitRate:
392 case VideoBitRate:
393 case VideoFrameRate:
394 case AlbumTitle:
395 case AlbumArtist:
396 case ContributingArtist:
397 case TrackNumber:
398 case Composer:
399 case Orientation:
400 case LeadPerformer:
401 case HasHdrContent:
402 return value.toString();
403 case Language: {
404 auto l = value.value<QLocale::Language>();
405 return QLocale::languageToString(l);
406 }
407 case Duration: {
408 QTime time = QTime::fromMSecsSinceStartOfDay(value.toInt());
409 return time.toString();
410 }
411 case FileFormat:
412 return QMediaFormat::fileFormatName(value.value<QMediaFormat::FileFormat>());
413 case AudioCodec:
414 return QMediaFormat::audioCodecName(value.value<QMediaFormat::AudioCodec>());
415 case VideoCodec:
416 return QMediaFormat::videoCodecName(value.value<QMediaFormat::VideoCodec>());
417 case Resolution: {
418 QSize size = value.toSize();
419 return QStringLiteral("%1 x %2").arg(size.width()).arg(size.height());
420 }
421#if QT_DEPRECATED_SINCE(6, 12)
422 case QtMultimediaPrivate::deprecatedThumbnailImage:
423#endif
424 case CoverArtImage:
425 break;
426 }
427 return QString();
428}
429/*!
430 \qmlmethod string QtMultimedia::mediaMetaData::metaDataKeyToString(Key key)
431 returns a string representation of \a key that can be used when presenting
432 meta data to users.
433*/
434
435/*!
436 returns a string representation of \a key that can be used when presenting
437 meta data to users.
438*/
439QString QMediaMetaData::metaDataKeyToString(QMediaMetaData::Key key)
440{
441 switch (key) {
442 case QMediaMetaData::Title:
443 return (QCoreApplication::translate("QMediaMetaData", "Title"));
444 case QMediaMetaData::Author:
445 return (QCoreApplication::translate("QMediaMetaData", "Author"));
446 case QMediaMetaData::Comment:
447 return (QCoreApplication::translate("QMediaMetaData", "Comment"));
448 case QMediaMetaData::Description:
449 return (QCoreApplication::translate("QMediaMetaData", "Description"));
450 case QMediaMetaData::Genre:
451 return (QCoreApplication::translate("QMediaMetaData", "Genre"));
452 case QMediaMetaData::Date:
453 return (QCoreApplication::translate("QMediaMetaData", "Date"));
454 case QMediaMetaData::Language:
455 return (QCoreApplication::translate("QMediaMetaData", "Language"));
456 case QMediaMetaData::Publisher:
457 return (QCoreApplication::translate("QMediaMetaData", "Publisher"));
458 case QMediaMetaData::Copyright:
459 return (QCoreApplication::translate("QMediaMetaData", "Copyright"));
460 case QMediaMetaData::Url:
461 return (QCoreApplication::translate("QMediaMetaData", "Url"));
462 case QMediaMetaData::Duration:
463 return (QCoreApplication::translate("QMediaMetaData", "Duration"));
464 case QMediaMetaData::MediaType:
465 return (QCoreApplication::translate("QMediaMetaData", "Media type"));
466 case QMediaMetaData::FileFormat:
467 return (QCoreApplication::translate("QMediaMetaData", "Container Format"));
468 case QMediaMetaData::AudioBitRate:
469 return (QCoreApplication::translate("QMediaMetaData", "Audio bit rate"));
470 case QMediaMetaData::AudioCodec:
471 return (QCoreApplication::translate("QMediaMetaData", "Audio codec"));
472 case QMediaMetaData::VideoBitRate:
473 return (QCoreApplication::translate("QMediaMetaData", "Video bit rate"));
474 case QMediaMetaData::VideoCodec:
475 return (QCoreApplication::translate("QMediaMetaData", "Video codec"));
476 case QMediaMetaData::VideoFrameRate:
477 return (QCoreApplication::translate("QMediaMetaData", "Video frame rate"));
478 case QMediaMetaData::AlbumTitle:
479 return (QCoreApplication::translate("QMediaMetaData", "Album title"));
480 case QMediaMetaData::AlbumArtist:
481 return (QCoreApplication::translate("QMediaMetaData", "Album artist"));
482 case QMediaMetaData::ContributingArtist:
483 return (QCoreApplication::translate("QMediaMetaData", "Contributing artist"));
484 case QMediaMetaData::TrackNumber:
485 return (QCoreApplication::translate("QMediaMetaData", "Track number"));
486 case QMediaMetaData::Composer:
487 return (QCoreApplication::translate("QMediaMetaData", "Composer"));
488#if QT_DEPRECATED_SINCE(6, 12)
489 case QtMultimediaPrivate::deprecatedThumbnailImage:
490 return (QCoreApplication::translate("QMediaMetaData", "Thumbnail image"));
491#endif
492 case QMediaMetaData::CoverArtImage:
493 return (QCoreApplication::translate("QMediaMetaData", "Cover art image"));
494 case QMediaMetaData::Orientation:
495 return (QCoreApplication::translate("QMediaMetaData", "Orientation"));
496 case QMediaMetaData::Resolution:
497 return (QCoreApplication::translate("QMediaMetaData", "Resolution"));
498 case QMediaMetaData::LeadPerformer:
499 return (QCoreApplication::translate("QMediaMetaData", "Lead performer"));
500 case QMediaMetaData::HasHdrContent:
501 return (QCoreApplication::translate("QMediaMetaData", "Has HDR content"));
502 }
503 return QString();
504}
505
506QDebug operator<<(QDebug dbg, const QMediaMetaData &metaData)
507{
508 QDebugStateSaver sv(dbg);
509 dbg.nospace();
510
511 dbg << "QMediaMetaData{";
512 auto range = metaData.asKeyValueRange();
513 auto begin = std::begin(range);
514
515 for (auto it = begin; it != std::end(range); ++it) {
516 if (it != begin)
517 dbg << ", ";
518 dbg << it->first << ": " << it->second;
519 }
520
521 dbg << "}";
522 return dbg;
523}
524
525// operator documentation
526/*!
527\fn QVariant &QMediaMetaData::operator[](QMediaMetaData::Key k)
528 Returns data stored at the Key \a{k}.
529 \code
530 QMediaMetaData rockBallad1;
531 rockBalad[QMediaMetaData::Genre]="Rock"
532 \endcode
533*/
534
535/*!
536\fn bool QMediaMetaData::operator==(const QMediaMetaData &a, const QMediaMetaData &b)
537 Compares two meta data objects \a a and \a b, and returns
538 \c true if they are identical or \c false if they differ.
539*/
540
541/*!
542\fn bool QMediaMetaData::operator!=(const QMediaMetaData &a, const QMediaMetaData &b)
543 Compares two meta data objects \a a and \a b, and returns
544 \c false if they are identical or \c true if they differ.
545*/
546
547/*!
548 \variable QMediaMetaData::data
549 \brief the meta data.
550 \note this is a \c protected member of its class.
551*/
552
553/*!
554 \fn auto QMediaMetaData::asKeyValueRange() const
555 \since 6.9
556
557 Returns a range object that allows iteration over this hash as key/value pairs.
558*/
559
560QT_END_NAMESPACE
561
562#include "moc_qmediametadata.cpp"
QDebug operator<<(QDebug dbg, const QFileInfo &fi)