Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

pymediainfo-tensoraws

codecov CI-test Release-pypi PyPI version

a modern fork from https://github.com/sbraz/pymediainfo

This small package is a wrapper around the MediaInfo library.

It works on Linux, Mac OS (arm64/x64) and Windows and is tested with Python 3.8 to 3.13 and PyPy3.

See https://pymediainfo.readthedocs.io/ for more information.

Requirements

pip install pymediainfo-tensoraws

On Linux, you will need to install the MediaInfo library. On Debian-based systems, you can do this with:

apt install libmediainfo-dev -y

This is a simple wrapper around the MediaInfo library, which you can find at https://mediaarea.net/en/MediaInfo.

Note:

  • Without the library, this package cannot parse media files, which severely limits its functionality.

  • Binary wheels containing a bundled library version are provided for Windows and Mac OS X.

  • Packages are available for several major Linux distributions. They depend on the library most of the time and are the preferred way to use pymediainfo on Linux unless a specific version of the package is required.

Using MediaInfo

There isn’t much to this library so instead of a lot of documentation it is probably best to just demonstrate how it works:

Getting information from an image:

from pymediainfo import MediaInfo

media_info = MediaInfo.parse("/home/user/image.jpg")
# Tracks can be accessed via the 'tracks' attribute or through shortcuts
# 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."
)

Will return something like:

JPEG of 828×828 pixels and 19098 bytes.

Getting information from a video

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("Bit rate: {t.bit_rate}, Frame rate: {t.frame_rate}, "
              "Format: {t.format}".format(t=track)
        )
        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())

Will return something like:

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',
 …
}

Dumping objects

In order to make debugging easier, pymediainfo.MediaInfo and pymediainfo.Track objects can be converted to dict using pymediainfo.MediaInfo.to_data() and pymediainfo.Track.to_data() respectively. The previous example demonstrates that.

Parsing existing MediaInfo output

If you already have the XML data in a string in memory (e.g. you have previously parsed the file or were sent the dump from mediainfo --output=OLDXML by someone else), you can call the constructor directly:

from pymediainfo import MediaInfo
media_info = MediaInfo(raw_xml_string)

Accessing Track attributes

Since the attributes on the pymediainfo.Track objects are being dynamically added as the XML output from MediaInfo is being parsed, there isn’t a firm definition of what will be available at runtime. In order to make consuming the objects easier so that you can avoid having to use hasattr or try/except blocks, the getattribute method has been overriden and will just return None when and if an attribute is referenced but doesn’t exist.

This will enable you to write consuming code like:

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("""{} tracks do not have bit rate
                 associated with them.""".format(track.track_type))
    else:
        print("{}: {}".format(track.track_type, track.bit_rate))

Output:

General tracks do not have bit rate associated with them.
Video: 46033920
Audio: 1536000
Menu tracks do not have bit rate associated with them.

Metadata

Release files for pymediainfo-tensoraws 6.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pymediainfo-tensoraws 6.1.0
File Interpreter ABI Platform
pymediainfo_tensoraws-6.1.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pymediainfo_tensoraws-6.1.0-py3-none-manylinux1_x86_64.whl Python 3 none Linux glibc 2.5+ x86-64 Details
pymediainfo_tensoraws-6.1.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details

Total release size: 9.7 MB

Release files / pymediainfo_tensoraws-6.1.0-py3-none-win_amd64.whl

Download URL pymediainfo_tensoraws-6.1.0-py3-none-win_amd64.whl
Size 3.0 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
b80ca918a995c5b61274ee1bf49a0aaec32f6c84f70fcabd428307c115b9ef1b
BLAKE2b-256 checksum
How to use checksums
de772f04c53d7a9e24080545a0c782457d5e5975e097995525b612812c59a3c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / pymediainfo_tensoraws-6.1.0-py3-none-manylinux1_x86_64.whl

Download URL pymediainfo_tensoraws-6.1.0-py3-none-manylinux1_x86_64.whl
Size 10.5 kB
Tags Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
063fb2d12ff4a03fd4a1f928aff6c07fad7d7c7616aa56e3643b3f98d054181c
BLAKE2b-256 checksum
How to use checksums
558c76d033d4a0a80120e7e2cf0be86562cb6c747f31b3c7b3653f6e4faec9fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / pymediainfo_tensoraws-6.1.0-py3-none-macosx_11_0_universal2.whl

Download URL pymediainfo_tensoraws-6.1.0-py3-none-macosx_11_0_universal2.whl
Size 6.7 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
7295df7ad2c9c66557921261348270db7f93d25751ade6fd9859f42c1bb81b37
BLAKE2b-256 checksum
How to use checksums
80ddb6655309ab392e0f440e66e75b8f958595d31ecf1f5b15e9aa1fe145225e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

6.1.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page