Name | pymediainfo JSON |
Version |
7.0.1
JSON |
| download |
home_page | None |
Summary | A Python wrapper for the MediaInfo library. |
upload_time | 2025-02-12 14:33:15 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pymediainfo
[](https://pypi.org/project/pymediainfo)
[](https://pypi.org/project/pymediainfo)
[](https://repology.org/project/python%3Apymediainfo/versions)
[](https://github.com/sbraz/pymediainfo)
[](https://ci.appveyor.com/project/sbraz/pymediainfo)
pymediainfo is a wrapper for [the MediaInfo library](https://mediaarea.net/en/MediaInfo). It makes it easy to
extract detailed information from multimedia files.
## Compatibility
pymediainfo is compatible with the following:
* **Platforms**: **Linux**, **macOS** and **Windows**.
* **Python Versions**: Tested with Python **3.9** (the minimum required version) to **3.13**, as well as **PyPy3**.
## Installation
Please note that, without [the MediaInfo library](https://mediaarea.net/en/MediaInfo), pymediainfo
**cannot parse media files**. This severely limits its functionality, allowing it to process
only pre-generated XML output from MediaInfo.
### Linux distribution Packages
Packages are available for [most major Linux distributions](https://repology.org/project/python%3Apymediainfo/versions).
They often depend on the MediaInfo library and are the preferred way to
install pymediainfo on Linux, as they allow for independent updates to pymediainfo and the MediaInfo library itself.
### PyPI on Linux, macOS and Windows
If pymediainfo is not available for your Linux distribution, or if you're running macOS or Windows,
you can install it from PyPI:
```
python -m pip install pymediainfo
```
**Wheels** containing a bundled version of the MediaInfo library are available for:
* Linux x86-64 and ARM64.
* macOS x86-64 and ARM64.
* Windows x86-64 and x86.
If you do not want to use the wheels (for instance if you want to use the system-wide
MediaInfo library instead of the bundled one):
```
python -m pip install pymediainfo --no-binary pymediainfo
```
## Usage
Here are a few examples demonstrating how to use pymediainfo.
### Getting information from an image
The `MediaInfo` class provides a `parse()` method which takes paths as input and returns `MediaInfo` objects.
#### Example snippet
```py
from pymediainfo import MediaInfo
media_info = MediaInfo.parse("/home/user/image.jpg")
# Tracks can be accessed using the 'tracks' attribute or through shorthands
# such as 'image_tracks', 'audio_tracks', 'video_tracks', etc.
general_track = media_info.general_tracks[0]
image_track = media_info.image_tracks[0]
print(
f"{image_track.format} of {image_track.width}×{image_track.height} pixels"
f" and {general_track.file_size} bytes."
)
```
#### Example output
```text
JPEG of 828×828 pixels and 19098 bytes.
```
### Getting information from a video
In this example, we take advantage of the `to_data()` method, which returns a `dict` containing all
attributes from a `MediaInfo` or `Track` object. This makes it
easier to inspect tracks even when their attributes are unknown.
#### Example snippet
```py
from pprint import pprint
from pymediainfo import MediaInfo
media_info = MediaInfo.parse("my_video_file.mp4")
for track in media_info.tracks:
if track.track_type == "Video":
print(f"Bit rate: {track.bit_rate}, Frame rate: {track.frame_rate}, Format: {track.format}")
print("Duration (raw value):", track.duration)
print("Duration (other values:")
pprint(track.other_duration)
elif track.track_type == "Audio":
print("Track data:")
pprint(track.to_data())
```
#### Example output
```text
Bit rate: 3117597, Frame rate: 23.976, Format: AVC
Duration (raw value): 958
Duration (other values):
['958 ms',
'958 ms',
'958 ms',
'00:00:00.958',
'00:00:00;23',
'00:00:00.958 (00:00:00;23)']
Track data:
{'bit_rate': 236392,
'bit_rate_mode': 'VBR',
'channel_layout': 'L R',
'channel_positions': 'Front: L R',
'channel_s': 2,
'codec_id': 'mp4a-40-2',
'commercial_name': 'AAC',
'compression_mode': 'Lossy',
…
}
```
### Accessing Track attributes
Since the attributes from a `Track` are dynamically created during parsing, there isn't a firm definition
of what will be available at runtime.
In order to make consuming objects easier, the `__getattribute__` method from `Track` objects
has been overridden to return `None` when a non-existent attribute is accessed, instead of raising `AttributeError`.
#### Example snippet
```py
from pymediainfo import MediaInfo
media_info = MediaInfo.parse("my_video_file.mp4")
for track in media_info.tracks:
if track.bit_rate is None:
print(f"{track.track_type} tracks do not have a bit rate associated with them")
else:
print(f"Track {track.track_id} of type {track.track_type} has a bit rate of {track.bit_rate} b/s")
```
#### Example output
```text
General tracks do not have a bit rate associated with them
Track 1 of type Video has a bit rate of 4398075 b/s
Track 2 of type Audio has a bit rate of 131413 b/s
Menu tracks do not have a bit rate associated with them
```
### Parsing pre-generated MediaInfo XML output
pymediainfo relies on MediaInfo's `OLDXML` output to create `MediaInfo` objects.
It is possible to create a `MediaInfo` object from an existing XML string. For
instance if someone sent you the output of `mediainfo --output=OLDXML`, you can
call the `MediaInfo` constructor directly.
#### Example snippet
```py
from pymediainfo import MediaInfo
raw_xml_string = """<?xml version="1.0" encoding="UTF-8"?>
<Mediainfo version="24.11">
<File>
<track type="General">
<Complete_name>binary_file</Complete_name>
<File_size>1.00 Byte</File_size>
</track>
</File>
</Mediainfo>"""
media_info = MediaInfo(raw_xml_string)
print(f"File name is: {media_info.general_tracks[0].complete_name}")
```
#### Example output
```text
File name is: binary_file
```
### Text output (à la `mediainfo`)
If you want a text report, similar to what `mediainfo my_video_file.mp4` outputs,
use the `output="text"` argument with the `parse()` method. In this case, it
will return a string, not a `MediaInfo` object.
#### Example snippet
```py
from pymediainfo import MediaInfo
# To mirror a simple call to "mediainfo" without the "--Full" or "-f" option, we
# set "full=False". Leaving it at the default of "full=True" would result in
# more verbose output.
print(MediaInfo.parse("my_video_file.mp4", output="text", full=False))
```
#### Example output
```text
General
Complete name : my_video_file.mp4
Format : MPEG-4
Format profile : Base Media
[…]
```
## Documentation
For more detailed information, please refer to the reference documentation
available at <https://pymediainfo.readthedocs.io/>.
## Issues and Questions
For feature requests and bug reports, please use the GitHub issue tracker at
<https://github.com/sbraz/pymediainfo/issues>.
If you have any questions, feel free to ask in the discussions at
<https://github.com/sbraz/pymediainfo/discussions>.
Raw data
{
"_id": null,
"home_page": null,
"name": "pymediainfo",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Louis Sautier <sautier.louis@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4d/80/80a6fb21005b81e30f6193d45cba13857df09f5d483e0551fa6fbb3aaeed/pymediainfo-7.0.1.tar.gz",
"platform": null,
"description": "# pymediainfo\n\n[](https://pypi.org/project/pymediainfo)\n[](https://pypi.org/project/pymediainfo)\n[](https://repology.org/project/python%3Apymediainfo/versions)\n[](https://github.com/sbraz/pymediainfo)\n[](https://ci.appveyor.com/project/sbraz/pymediainfo)\n\npymediainfo is a wrapper for [the MediaInfo library](https://mediaarea.net/en/MediaInfo). It makes it easy to\nextract detailed information from multimedia files.\n\n## Compatibility\n\npymediainfo is compatible with the following:\n\n* **Platforms**: **Linux**, **macOS** and **Windows**.\n* **Python Versions**: Tested with Python **3.9** (the minimum required version) to **3.13**, as well as **PyPy3**.\n\n## Installation\n\nPlease note that, without [the MediaInfo library](https://mediaarea.net/en/MediaInfo), pymediainfo\n**cannot parse media files**. This severely limits its functionality, allowing it to process\nonly pre-generated XML output from MediaInfo.\n\n### Linux distribution Packages\n\nPackages are available for [most major Linux distributions](https://repology.org/project/python%3Apymediainfo/versions).\nThey often depend on the MediaInfo library and are the preferred way to\ninstall pymediainfo on Linux, as they allow for independent updates to pymediainfo and the MediaInfo library itself.\n\n### PyPI on Linux, macOS and Windows\n\nIf pymediainfo is not available for your Linux distribution, or if you're running macOS or Windows,\nyou can install it from PyPI:\n```\npython -m pip install pymediainfo\n```\n\n**Wheels** containing a bundled version of the MediaInfo library are available for:\n\n* Linux x86-64 and ARM64.\n* macOS x86-64 and ARM64.\n* Windows x86-64 and x86.\n\nIf you do not want to use the wheels (for instance if you want to use the system-wide\nMediaInfo library instead of the bundled one):\n```\npython -m pip install pymediainfo --no-binary pymediainfo\n```\n\n## Usage\n\nHere are a few examples demonstrating how to use pymediainfo.\n### Getting information from an image\nThe `MediaInfo` class provides a `parse()` method which takes paths as input and returns `MediaInfo` objects.\n#### Example snippet\n\n```py\nfrom pymediainfo import MediaInfo\n\nmedia_info = MediaInfo.parse(\"/home/user/image.jpg\")\n# Tracks can be accessed using the 'tracks' attribute or through shorthands\n# such as 'image_tracks', 'audio_tracks', 'video_tracks', etc.\ngeneral_track = media_info.general_tracks[0]\nimage_track = media_info.image_tracks[0]\nprint(\n f\"{image_track.format} of {image_track.width}\u00d7{image_track.height} pixels\"\n f\" and {general_track.file_size} bytes.\"\n)\n```\n\n#### Example output\n\n```text\nJPEG of 828\u00d7828 pixels and 19098 bytes.\n```\n\n### Getting information from a video\n\nIn this example, we take advantage of the `to_data()` method, which returns a `dict` containing all\nattributes from a `MediaInfo` or `Track` object. This makes it\neasier to inspect tracks even when their attributes are unknown.\n\n#### Example snippet\n\n```py\nfrom pprint import pprint\nfrom pymediainfo import MediaInfo\n\nmedia_info = MediaInfo.parse(\"my_video_file.mp4\")\nfor track in media_info.tracks:\n if track.track_type == \"Video\":\n print(f\"Bit rate: {track.bit_rate}, Frame rate: {track.frame_rate}, Format: {track.format}\")\n print(\"Duration (raw value):\", track.duration)\n print(\"Duration (other values:\")\n pprint(track.other_duration)\n elif track.track_type == \"Audio\":\n print(\"Track data:\")\n pprint(track.to_data())\n```\n\n#### Example output\n\n```text\nBit rate: 3117597, Frame rate: 23.976, Format: AVC\nDuration (raw value): 958\nDuration (other values):\n['958 ms',\n'958 ms',\n'958 ms',\n'00:00:00.958',\n'00:00:00;23',\n'00:00:00.958 (00:00:00;23)']\nTrack data:\n{'bit_rate': 236392,\n'bit_rate_mode': 'VBR',\n'channel_layout': 'L R',\n'channel_positions': 'Front: L R',\n'channel_s': 2,\n'codec_id': 'mp4a-40-2',\n'commercial_name': 'AAC',\n'compression_mode': 'Lossy',\n\u2026\n}\n```\n\n### Accessing Track attributes\n\nSince the attributes from a `Track` are dynamically created during parsing, there isn't a firm definition\nof what will be available at runtime.\n\nIn order to make consuming objects easier, the `__getattribute__` method from `Track` objects\nhas been overridden to return `None` when a non-existent attribute is accessed, instead of raising `AttributeError`.\n\n#### Example snippet\n```py\nfrom pymediainfo import MediaInfo\n\nmedia_info = MediaInfo.parse(\"my_video_file.mp4\")\nfor track in media_info.tracks:\n if track.bit_rate is None:\n print(f\"{track.track_type} tracks do not have a bit rate associated with them\")\n else:\n print(f\"Track {track.track_id} of type {track.track_type} has a bit rate of {track.bit_rate} b/s\")\n```\n\n#### Example output\n\n```text\nGeneral tracks do not have a bit rate associated with them\nTrack 1 of type Video has a bit rate of 4398075 b/s\nTrack 2 of type Audio has a bit rate of 131413 b/s\nMenu tracks do not have a bit rate associated with them\n```\n\n\n### Parsing pre-generated MediaInfo XML output\npymediainfo relies on MediaInfo's `OLDXML` output to create `MediaInfo` objects.\n\nIt is possible to create a `MediaInfo` object from an existing XML string. For\ninstance if someone sent you the output of `mediainfo --output=OLDXML`, you can\ncall the `MediaInfo` constructor directly.\n\n#### Example snippet\n```py\nfrom pymediainfo import MediaInfo\n\nraw_xml_string = \"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Mediainfo version=\"24.11\">\n<File>\n<track type=\"General\">\n<Complete_name>binary_file</Complete_name>\n<File_size>1.00 Byte</File_size>\n</track>\n</File>\n</Mediainfo>\"\"\"\nmedia_info = MediaInfo(raw_xml_string)\nprint(f\"File name is: {media_info.general_tracks[0].complete_name}\")\n```\n\n#### Example output\n```text\nFile name is: binary_file\n```\n\n### Text output (\u00e0 la `mediainfo`)\n\nIf you want a text report, similar to what `mediainfo my_video_file.mp4` outputs,\nuse the `output=\"text\"` argument with the `parse()` method. In this case, it\nwill return a string, not a `MediaInfo` object.\n\n#### Example snippet\n```py\nfrom pymediainfo import MediaInfo\n\n# To mirror a simple call to \"mediainfo\" without the \"--Full\" or \"-f\" option, we\n# set \"full=False\". Leaving it at the default of \"full=True\" would result in\n# more verbose output.\nprint(MediaInfo.parse(\"my_video_file.mp4\", output=\"text\", full=False))\n```\n\n#### Example output\n```text\nGeneral\nComplete name : my_video_file.mp4\nFormat : MPEG-4\nFormat profile : Base Media\n[\u2026]\n```\n\n## Documentation\n\nFor more detailed information, please refer to the reference documentation\navailable at <https://pymediainfo.readthedocs.io/>.\n\n## Issues and Questions\nFor feature requests and bug reports, please use the GitHub issue tracker at\n<https://github.com/sbraz/pymediainfo/issues>.\n\nIf you have any questions, feel free to ask in the discussions at\n<https://github.com/sbraz/pymediainfo/discussions>.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python wrapper for the MediaInfo library.",
"version": "7.0.1",
"project_urls": {
"Bugs": "https://github.com/sbraz/pymediainfo/issues",
"Documentation": "https://pymediainfo.readthedocs.io/",
"Homepage": "https://github.com/sbraz/pymediainfo"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a64ad895646df3d3ff617b54d7f06a02ed9d6f5b86673030a543927310e0f7ed",
"md5": "a439e74d8eb95141727fd22501f74dea",
"sha256": "286f3bf6299be0997093254e0f371855bc5cf2aaf8641d19455a011e3ee3a84d"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1-py3-none-macosx_10_10_universal2.whl",
"has_sig": false,
"md5_digest": "a439e74d8eb95141727fd22501f74dea",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6983332,
"upload_time": "2025-02-12T14:42:47",
"upload_time_iso_8601": "2025-02-12T14:42:47.412186Z",
"url": "https://files.pythonhosted.org/packages/a6/4a/d895646df3d3ff617b54d7f06a02ed9d6f5b86673030a543927310e0f7ed/pymediainfo-7.0.1-py3-none-macosx_10_10_universal2.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "77dfbc6b5a08e908c64a81f6ff169716d408ce7380ceff44e1eceb095f49e0dc",
"md5": "0001a0bd1e82afc686174cb19c5c6443",
"sha256": "3648e2379fa67bd02433d1e28c707df3a53834dd480680615a9fefd2266f1182"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1-py3-none-manylinux_2_27_aarch64.whl",
"has_sig": false,
"md5_digest": "0001a0bd1e82afc686174cb19c5c6443",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5768082,
"upload_time": "2025-02-12T14:33:10",
"upload_time_iso_8601": "2025-02-12T14:33:10.543992Z",
"url": "https://files.pythonhosted.org/packages/77/df/bc6b5a08e908c64a81f6ff169716d408ce7380ceff44e1eceb095f49e0dc/pymediainfo-7.0.1-py3-none-manylinux_2_27_aarch64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0210a9bc1446a48d3a15940eb1af79a71978f368f27e2cc86f9ec3ec2d206a20",
"md5": "229aa73253ace15fdb4765fadd9e1a52",
"sha256": "cde98112f1ce486589b17a12e5da42085faea996224f7c67fa45b8c1dca719c6"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1-py3-none-manylinux_2_27_x86_64.whl",
"has_sig": false,
"md5_digest": "229aa73253ace15fdb4765fadd9e1a52",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6001553,
"upload_time": "2025-02-12T14:33:12",
"upload_time_iso_8601": "2025-02-12T14:33:12.663997Z",
"url": "https://files.pythonhosted.org/packages/02/10/a9bc1446a48d3a15940eb1af79a71978f368f27e2cc86f9ec3ec2d206a20/pymediainfo-7.0.1-py3-none-manylinux_2_27_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ed7fc48f8514cb60c9ff9be81b6f383e73e66c7461ef854a1b62628e3c823f13",
"md5": "2c62d1f68831c34073715dcdd6fc1ff1",
"sha256": "01bcaf82b72cefbf4b96f13b2547e1b2e0e734bab7173d7c33f7f01acc07c98b"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1-py3-none-win32.whl",
"has_sig": false,
"md5_digest": "2c62d1f68831c34073715dcdd6fc1ff1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 3125046,
"upload_time": "2025-02-12T15:04:39",
"upload_time_iso_8601": "2025-02-12T15:04:39.890478Z",
"url": "https://files.pythonhosted.org/packages/ed/7f/c48f8514cb60c9ff9be81b6f383e73e66c7461ef854a1b62628e3c823f13/pymediainfo-7.0.1-py3-none-win32.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e7269d50c2a330541bc36c0ea7ce29eeff5b0c35c2624139660df8bcfa9ae3ce",
"md5": "e41c0678eacde21aa82a1692fbf55894",
"sha256": "13224fa7590e198763b8baf072e704ea81d334e71aa32a469091460e243893c7"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1-py3-none-win_amd64.whl",
"has_sig": false,
"md5_digest": "e41c0678eacde21aa82a1692fbf55894",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 3271232,
"upload_time": "2025-02-12T15:07:13",
"upload_time_iso_8601": "2025-02-12T15:07:13.672147Z",
"url": "https://files.pythonhosted.org/packages/e7/26/9d50c2a330541bc36c0ea7ce29eeff5b0c35c2624139660df8bcfa9ae3ce/pymediainfo-7.0.1-py3-none-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4d8080a6fb21005b81e30f6193d45cba13857df09f5d483e0551fa6fbb3aaeed",
"md5": "9c17d48af6221a7cd305c6731f42c567",
"sha256": "0d5df59ecc615e24c56f303b8f651579c6accab7265715e5d429186d7ba21514"
},
"downloads": -1,
"filename": "pymediainfo-7.0.1.tar.gz",
"has_sig": false,
"md5_digest": "9c17d48af6221a7cd305c6731f42c567",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 441563,
"upload_time": "2025-02-12T14:33:15",
"upload_time_iso_8601": "2025-02-12T14:33:15.038300Z",
"url": "https://files.pythonhosted.org/packages/4d/80/80a6fb21005b81e30f6193d45cba13857df09f5d483e0551fa6fbb3aaeed/pymediainfo-7.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-12 14:33:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sbraz",
"github_project": "pymediainfo",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"appveyor": true,
"tox": true,
"lcname": "pymediainfo"
}