1# AVMetadataExtractor 2 3 4## Overview 5 6The AVMetadataExtractor module provides the APIs for extracting metadata from media assets. 7 8**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 9 10**Since**: 18 11 12 13## Summary 14 15 16### Files 17 18| Name| Description| 19| -------- | -------- | 20| [avmetadata_extractor.h](avmetadata__extractor_8h.md) | Declares the AVMetadataExtractor APIs. With these native APIs, you can obtain metadata from media assets. | 21| [avmetadata_extractor_base.h](avmetadata__extractor__base_8h.md) | Declares the constants used by the AVMetadataExtractor. | 22 23 24### Types 25 26| Name| Description| 27| -------- | -------- | 28| typedef struct [OH_AVMetadataExtractor](#oh_avmetadataextractor) [OH_AVMetadataExtractor](#oh_avmetadataextractor) | Defines a struct for the OH_AVMetadataExtractor. | 29 30 31### Functions 32 33| Name| Description| 34| -------- | -------- | 35| [OH_AVMetadataExtractor](#oh_avmetadataextractor) \* [OH_AVMetadataExtractor_Create](#oh_avmetadataextractor_create) (void) | Creates an **OH_AVMetadataExtractor** instance. | 36| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVMetadataExtractor_SetFDSource](#oh_avmetadataextractor_setfdsource) ([OH_AVMetadataExtractor](#oh_avmetadataextractor) \*extractor, int32_t fd, int64_t offset, int64_t size) | Sets a data source based on the media file descriptor. | 37| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVMetadataExtractor_FetchMetadata](#oh_avmetadataextractor_fetchmetadata) ([OH_AVMetadataExtractor](#oh_avmetadataextractor) \*extractor, OH_AVFormat \*avMetadata) | Obtains metadata from a media asset. This function must be called after [SetFDSource](#oh_avmetadataextractor_setfdsource).| 38| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVMetadataExtractor_FetchAlbumCover](#oh_avmetadataextractor_fetchalbumcover) ([OH_AVMetadataExtractor](#oh_avmetadataextractor) \*extractor, OH_PixelmapNative \*\*pixelMap) | Obtains the cover of an audio album. This function must be called after [SetFDSource](#oh_avmetadataextractor_setfdsource).| 39| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVMetadataExtractor_Release](#oh_avmetadataextractor_release) ([OH_AVMetadataExtractor](#oh_avmetadataextractor) \*extractor) | Releases the resources used by the **OH_AVMetadataExtractor** instance and destroys the instance. | 40 41 42### Variables 43 44| Name| Description| 45| -------- | -------- | 46| static const char\* [OH_AVMETADATA_EXTRACTOR_ALBUM](#oh_avmetadata_extractor_album) = "album" | Pointer to the key for obtaining the title of the album. The value type is const char\*. | 47| static const char\* [OH_AVMETADATA_EXTRACTOR_ALBUM_ARTIST](#oh_avmetadata_extractor_album_artist) = "albumArtist" | Pointer to the key for obtaining the artist of the album. The value type is const char\*. | 48| static const char\* [OH_AVMETADATA_EXTRACTOR_ARTIST](#oh_avmetadata_extractor_artist) = "artist" | Pointer to the key for obtaining the artist of the media asset. The value type is const char\*. | 49| static const char\* [OH_AVMETADATA_EXTRACTOR_AUTHOR](#oh_avmetadata_extractor_author) = "author" | Pointer to the key for obtaining the author of the media asset. The value type is const char\*. | 50| static const char\* [OH_AVMETADATA_EXTRACTOR_DATE_TIME](#oh_avmetadata_extractor_date_time) = "dateTime" | Pointer to the key for obtaining the creation time of the media asset. The value type is const char\*. | 51| static const char\* [OH_AVMETADATA_EXTRACTOR_DATE_TIME_FORMAT](#oh_avmetadata_extractor_date_time_format) = "dateTimeFormat" | Pointer to the key for obtaining the creation time of the media asset. The value type is const char\* and the output format is YYYY-MM-DD HH:mm:ss. | 52| static const char\* [OH_AVMETADATA_EXTRACTOR_COMPOSER](#oh_avmetadata_extractor_composer) = "composer" | Pointer to the key for obtaining the composer of the media asset. The value type is const char\*. | 53| static const char\* [OH_AVMETADATA_EXTRACTOR_DURATION](#oh_avmetadata_extractor_duration) = "duration" | Pointer to the key for obtaining the duration of the media asset, in ms. The value type is int64_t. | 54| static const char\* [OH_AVMETADATA_EXTRACTOR_GENRE](#oh_avmetadata_extractor_genre) = "genre" | Pointer to the key for obtaining the type or genre of the media asset. The value type is const char\*. | 55| static const char\* [OH_AVMETADATA_EXTRACTOR_HAS_AUDIO](#oh_avmetadata_extractor_has_audio) = "hasAudio" | Pointer to the key for obtaining the flag indicating whether the media asset contains audio. The value type is int32_t. | 56| static const char\* [OH_AVMETADATA_EXTRACTOR_HAS_VIDEO](#oh_avmetadata_extractor_has_video) = "hasVideo" | Pointer to the key for obtaining the flag indicating whether the media asset contains video. The value type is int32_t. | 57| static const char\* [OH_AVMETADATA_EXTRACTOR_MIME_TYPE](#oh_avmetadata_extractor_mime_type) = "mimeType" | Pointer to the key for obtaining the MIME type of the media asset. The value type is const char\*, for example, video/mp4, audio/mp4, and audio/amr wb. | 58| static const char\* [OH_AVMETADATA_EXTRACTOR_TRACK_COUNT](#oh_avmetadata_extractor_track_count) = "trackCount" | Pointer to the key for obtaining the number of tracks of the media asset. The value type is int32_t. | 59| static const char\* [OH_AVMETADATA_EXTRACTOR_SAMPLE_RATE](#oh_avmetadata_extractor_sample_rate) = "sampleRate" | Pointer to the key for obtaining the audio sampling rate, in Hz. The value type is int32_t. | 60| static const char\* [OH_AVMETADATA_EXTRACTOR_TITLE](#oh_avmetadata_extractor_title) = "title" | Pointer to the key for obtaining the title of the media asset. The value type is const char\*. | 61| static const char\* [OH_AVMETADATA_EXTRACTOR_VIDEO_HEIGHT](#oh_avmetadata_extractor_video_height) = "videoHeight" | Pointer to the key for obtaining the video height, in px. The value type is int32_t. | 62| static const char\* [OH_AVMETADATA_EXTRACTOR_VIDEO_WIDTH](#oh_avmetadata_extractor_video_width) = "videoWidth" | Pointer to the key for obtaining the video weight, in px. The value type is int32_t. | 63| static const char\* [OH_AVMETADATA_EXTRACTOR_VIDEO_ORIENTATION](#oh_avmetadata_extractor_video_orientation) = "videoOrientation" | Pointer to the key for obtaining the video rotation direction, in degrees (°). The value type is int32_t. | 64| static const char\* [OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID](#oh_avmetadata_extractor_video_is_hdr_vivid) = "hdrType" | Pointer to the key for obtaining the flag indicating whether the video is an HDR Vivid video. The value type is int32_t. For details, see the definition of [OH_Core_HdrType](../apis-avcodec-kit/_core.md#oh_core_hdrtype) in [media_types.h](../apis-avcodec-kit/media__types_8h.md). | 65| static const char\* [OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE](#oh_avmetadata_extractor_location_latitude) = "latitude" | Pointer to the key for obtaining the latitude in the geographical location. The value type is float. | 66| static const char\* [OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE](#oh_avmetadata_extractor_location_longitude) = "longitude" | Pointer to the key for obtaining the longitude in the geographical location. The value type is float. | 67 68 69## Type Description 70 71 72### OH_AVMetadataExtractor 73 74``` 75typedef struct OH_AVMetadataExtractor OH_AVMetadataExtractor 76``` 77**Description** 78 79Defines a struct for the OH_AVMetadataExtractor. 80 81**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 82 83**Since**: 18 84 85 86## Function Description 87 88 89### OH_AVMetadataExtractor_Create() 90 91``` 92OH_AVMetadataExtractor* OH_AVMetadataExtractor_Create(void) 93``` 94**Description** 95 96Creates an **OH_AVMetadataExtractor** instance. 97 98**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 99 100**Since**: 18 101 102**Returns** 103 104Returns the pointer to the **OH_AVMetadataExtractor** instance created if the operation is successful; returns a null pointer otherwise. 105 106Possible cause of failures: **HstEngineFactory::CreateAVMetadataHelperEngine** fails to run. 107 108 109### OH_AVMetadataExtractor_FetchAlbumCover() 110 111``` 112OH_AVErrCode OH_AVMetadataExtractor_FetchAlbumCover(OH_AVMetadataExtractor* extractor, OH_PixelmapNative** pixelMap) 113``` 114**Description** 115 116Obtains the cover of an audio album. This function must be called after [SetFDSource](#oh_avmetadataextractor_setfdsource). 117 118**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 119 120**Since**: 18 121 122**Parameters** 123 124| Name| Description| 125| -------- | -------- | 126| extractor | Pointer to an **OH_AVMetadataExtractor** instance. | 127| pixelMap | Double pointer to the album cover obtained. For details, see **OH_PixelmapNative**. | 128 129**Returns** 130 131Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 132 133**AV_ERR_OK**: The operation is successful. 134 135**AV_ERR_INVALID_VAL**: The input parameter **extractor** is a null pointer or an input parameter is invalid. 136 137**AV_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. 138 139**AV_ERR_UNSUPPORTED_FORMAT**: The format is not supported. 140 141**AV_ERR_NO_MEMORY**: Internal memory allocation failed. 142 143 144### OH_AVMetadataExtractor_FetchMetadata() 145 146``` 147OH_AVErrCode OH_AVMetadataExtractor_FetchMetadata(OH_AVMetadataExtractor* extractor, OH_AVFormat* avMetadata) 148``` 149**Description** 150 151Obtains metadata from a media asset. This function must be called after [SetFDSource](#oh_avmetadataextractor_setfdsource). 152 153**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 154 155**Since**: 18 156 157**Parameters** 158 159| Name| Description| 160| -------- | -------- | 161| extractor | Pointer to an **OH_AVMetadataExtractor** instance. | 162| avMetadata | Pointer to an **OH_AVFormat** instance, which contains the obtained metadata. | 163 164**Returns** 165 166Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 167 168**AV_ERR_OK**: The operation is successful. 169 170**AV_ERR_INVALID_VAL**: The input parameter **extractor** is a null pointer or an input parameter is invalid. 171 172**AV_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. 173 174**AV_ERR_UNSUPPORTED_FORMAT**: The format is not supported. 175 176**AV_ERR_NO_MEMORY**: Internal memory allocation failed. 177 178 179### OH_AVMetadataExtractor_Release() 180 181``` 182OH_AVErrCode OH_AVMetadataExtractor_Release(OH_AVMetadataExtractor* extractor) 183``` 184**Description** 185 186Releases the resources used by the **OH_AVMetadataExtractor** instance and destroys the instance. 187 188**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 189 190**Since**: 18 191 192**Parameters** 193 194| Name| Description| 195| -------- | -------- | 196| extractor | Pointer to an **OH_AVMetadataExtractor** instance. | 197 198**Returns** 199 200Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 201 202**AV_ERR_OK**: The operation is successful. 203 204**AV_ERR_INVALID_VAL**: The input parameter **extractor** is a null pointer or an input parameter is invalid. 205 206 207### OH_AVMetadataExtractor_SetFDSource() 208 209``` 210OH_AVErrCode OH_AVMetadataExtractor_SetFDSource(OH_AVMetadataExtractor* extractor, int32_t fd, int64_t offset, int64_t size) 211``` 212**Description** 213 214Sets a data source based on the media file descriptor. 215 216**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 217 218**Since**: 18 219 220**Parameters** 221 222| Name| Description| 223| -------- | -------- | 224| extractor | Pointer to an **OH_AVMetadataExtractor** instance. | 225| fd | File descriptor of the media source. | 226| offset | Offset of the media source in the file descriptor. | 227| size | Size of the media source. | 228 229**Returns** 230 231Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 232 233**AV_ERR_OK**: The operation is successful. 234 235**AV_ERR_INVALID_VAL**: The input parameter **extractor** is a null pointer or an input parameter is invalid. 236 237**AV_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. 238 239**AV_ERR_NO_MEMORY**: Internal memory allocation failed. 240 241 242## Variable Description 243 244 245### OH_AVMETADATA_EXTRACTOR_ALBUM 246 247``` 248static const char* OH_AVMETADATA_EXTRACTOR_ALBUM = "album" 249``` 250**Description** 251 252Pointer to the key for obtaining the title of the album. The value type is const char\*. 253 254**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 255 256**Since**: 18 257 258 259### OH_AVMETADATA_EXTRACTOR_ALBUM_ARTIST 260 261``` 262static const char* OH_AVMETADATA_EXTRACTOR_ALBUM_ARTIST = "albumArtist" 263``` 264**Description** 265 266Pointer to the key for obtaining the artist of the album. The value type is const char\*. 267 268**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 269 270**Since**: 18 271 272 273### OH_AVMETADATA_EXTRACTOR_ARTIST 274 275``` 276static const char* OH_AVMETADATA_EXTRACTOR_ARTIST = "artist" 277``` 278**Description** 279 280Pointer to the key for obtaining the artist of the media asset. The value type is const char\*. 281 282**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 283 284**Since**: 18 285 286 287### OH_AVMETADATA_EXTRACTOR_AUTHOR 288 289``` 290static const char* OH_AVMETADATA_EXTRACTOR_AUTHOR = "author" 291``` 292**Description** 293 294Pointer to the key for obtaining the author of the media asset. The value type is const char\*. 295 296**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 297 298**Since**: 18 299 300 301### OH_AVMETADATA_EXTRACTOR_COMPOSER 302 303``` 304static const char* OH_AVMETADATA_EXTRACTOR_COMPOSER = "composer" 305``` 306**Description** 307 308Pointer to the key for obtaining the composer of the media asset. The value type is const char\*. 309 310**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 311 312**Since**: 18 313 314 315### OH_AVMETADATA_EXTRACTOR_DATE_TIME 316 317``` 318static const char* OH_AVMETADATA_EXTRACTOR_DATE_TIME = "dateTime" 319``` 320**Description** 321 322Pointer to the key for obtaining the creation time of the media asset. The value type is const char\*. 323 324**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 325 326**Since**: 18 327 328 329### OH_AVMETADATA_EXTRACTOR_DATE_TIME_FORMAT 330 331``` 332static const char* OH_AVMETADATA_EXTRACTOR_DATE_TIME_FORMAT = "dateTimeFormat" 333``` 334**Description** 335 336Pointer to the key for obtaining the creation time of the media asset. The value type is const char\* and the output format is YYYY-MM-DD HH:mm:ss. 337 338**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 339 340**Since**: 18 341 342 343### OH_AVMETADATA_EXTRACTOR_DURATION 344 345``` 346static const char* OH_AVMETADATA_EXTRACTOR_DURATION = "duration" 347``` 348**Description** 349 350Pointer to the key for obtaining the duration of the media asset, in ms. The value type is int64_t. 351 352**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 353 354**Since**: 18 355 356 357### OH_AVMETADATA_EXTRACTOR_GENRE 358 359``` 360static const char* OH_AVMETADATA_EXTRACTOR_GENRE = "genre" 361``` 362**Description** 363 364Pointer to the key for obtaining the type or genre of the media asset. The value type is const char\*. 365 366**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 367 368**Since**: 18 369 370 371### OH_AVMETADATA_EXTRACTOR_HAS_AUDIO 372 373``` 374static const char* OH_AVMETADATA_EXTRACTOR_HAS_AUDIO = "hasAudio" 375``` 376**Description** 377 378Pointer to the key for obtaining the flag indicating whether the media asset contains audio. The value type is int32_t. 379 380**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 381 382**Since**: 18 383 384 385### OH_AVMETADATA_EXTRACTOR_HAS_VIDEO 386 387``` 388static const char* OH_AVMETADATA_EXTRACTOR_HAS_VIDEO = "hasVideo" 389``` 390**Description** 391 392Pointer to the key for obtaining the flag indicating whether the media asset contains video. The value type is int32_t. 393 394**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 395 396**Since**: 18 397 398 399### OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE 400 401``` 402static const char* OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE = "latitude" 403``` 404**Description** 405 406Pointer to the key for obtaining the latitude in the geographical location. The value type is float. 407 408**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 409 410**Since**: 18 411 412 413### OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE 414 415``` 416static const char* OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE = "longitude" 417``` 418**Description** 419 420Pointer to the key for obtaining the longitude in the geographical location. The value type is float. 421 422**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 423 424**Since**: 18 425 426 427### OH_AVMETADATA_EXTRACTOR_MIME_TYPE 428 429``` 430static const char* OH_AVMETADATA_EXTRACTOR_MIME_TYPE = "mimeType" 431``` 432**Description** 433 434Pointer to the key for obtaining the MIME type of the media asset. The value type is const char\*, for example, video/mp4, audio/mp4, and audio/amr wb. 435 436**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 437 438**Since**: 18 439 440 441### OH_AVMETADATA_EXTRACTOR_SAMPLE_RATE 442 443``` 444static const char* OH_AVMETADATA_EXTRACTOR_SAMPLE_RATE = "sampleRate" 445``` 446**Description** 447 448Pointer to the key for obtaining the audio sampling rate, in Hz. The value type is int32_t. 449 450**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 451 452**Since**: 18 453 454 455### OH_AVMETADATA_EXTRACTOR_TITLE 456 457``` 458static const char* OH_AVMETADATA_EXTRACTOR_TITLE = "title" 459``` 460**Description** 461 462Pointer to the key for obtaining the title of the media asset. The value type is const char\*. 463 464**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 465 466**Since**: 18 467 468 469### OH_AVMETADATA_EXTRACTOR_TRACK_COUNT 470 471``` 472static const char* OH_AVMETADATA_EXTRACTOR_TRACK_COUNT = "trackCount" 473``` 474**Description** 475 476Pointer to the key for obtaining the number of tracks of the media asset. The value type is int32_t. 477 478**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 479 480**Since**: 18 481 482 483### OH_AVMETADATA_EXTRACTOR_VIDEO_HEIGHT 484 485``` 486static const char* OH_AVMETADATA_EXTRACTOR_VIDEO_HEIGHT = "videoHeight" 487``` 488**Description** 489 490Pointer to the key for obtaining the video height, in px. The value type is int32_t. 491 492**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 493 494**Since**: 18 495 496 497### OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID 498 499``` 500static const char* OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID = "hdrType" 501``` 502**Description** 503 504Pointer to the key for obtaining the flag indicating whether the video is an HDR Vivid video. The value type is int32_t. For details, see the definition of [OH_Core_HdrType](../apis-avcodec-kit/_core.md#oh_core_hdrtype) in [media_types.h](../apis-avcodec-kit/media__types_8h.md). 505 506**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 507 508**Since**: 18 509 510 511### OH_AVMETADATA_EXTRACTOR_VIDEO_ORIENTATION 512 513``` 514static const char* OH_AVMETADATA_EXTRACTOR_VIDEO_ORIENTATION = "videoOrientation" 515``` 516**Description** 517 518Pointer to the key for obtaining the video rotation direction, in degrees (°). The value type is int32_t. 519 520**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 521 522**Since**: 18 523 524 525### OH_AVMETADATA_EXTRACTOR_VIDEO_WIDTH 526 527``` 528static const char* OH_AVMETADATA_EXTRACTOR_VIDEO_WIDTH = "videoWidth" 529``` 530**Description** 531 532Pointer to the key for obtaining the video weight, in px. The value type is int32_t. 533 534**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 535 536**Since**: 18 537