No project description provided
Project description
pymediainfo-tensoraws
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pymediainfo_tensoraws-6.1.0-py3-none-win_amd64.whl
.
File metadata
- Download URL: pymediainfo_tensoraws-6.1.0-py3-none-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b80ca918a995c5b61274ee1bf49a0aaec32f6c84f70fcabd428307c115b9ef1b |
|
MD5 | b7136ef8342490292074e092a7131f56 |
|
BLAKE2b-256 | de772f04c53d7a9e24080545a0c782457d5e5975e097995525b612812c59a3c4 |
File details
Details for the file pymediainfo_tensoraws-6.1.0-py3-none-manylinux1_x86_64.whl
.
File metadata
- Download URL: pymediainfo_tensoraws-6.1.0-py3-none-manylinux1_x86_64.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063fb2d12ff4a03fd4a1f928aff6c07fad7d7c7616aa56e3643b3f98d054181c |
|
MD5 | d942141ff5983c5c8fa070bdaad5ebea |
|
BLAKE2b-256 | 558c76d033d4a0a80120e7e2cf0be86562cb6c747f31b3c7b3653f6e4faec9fd |
File details
Details for the file pymediainfo_tensoraws-6.1.0-py3-none-macosx_11_0_universal2.whl
.
File metadata
- Download URL: pymediainfo_tensoraws-6.1.0-py3-none-macosx_11_0_universal2.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 3, macOS 11.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7295df7ad2c9c66557921261348270db7f93d25751ade6fd9859f42c1bb81b37 |
|
MD5 | b39688c06930611a21e59f57bb624d49 |
|
BLAKE2b-256 | 80ddb6655309ab392e0f440e66e75b8f958595d31ecf1f5b15e9aa1fe145225e |