Skip to main content

No project description provided

Project description

ffmpeg-media-type

ffmpeg-media-type is a Python library that utilizes FFmpeg to detect various media file information, such as duration, width, and height. This library provides an easy-to-use interface for extracting essential details from media files by leveraging the powerful capabilities of FFmpeg.

CI Coverage Status pypi downloads versions license Checked with mypy Code style: black Imports: isort

Installation

You can install ffmpeg-media-type via pip:

pip install ffmpeg-media-type

Note: FFmpeg must be installed on your system for this library to function correctly. Make sure you have FFmpeg installed and added to your system's PATH.

Usage

To use ffmpeg-media-type, first import the library:

import ffmpeg_media_type

Detecting Media File Information

To detect media file information, use the detect function, providing the path to the media file as a parameter:

media_info = ffmpeg_media_type.info.detect('/path/to/media/file.mp4')

The detect function returns a model containing the following information:

  • type: The type of media file (e.g. video, audio, image, etc.).
  • duration: The duration of the media file in seconds.
  • width: The width of the media file in pixels.
  • height: The height of the media file in pixels.
  • format: The format of the media file (e.g. mp4, mp3, png, etc.).
  • size: The size of the media file in bytes.
  • suggest_ext: The suggested file extension for the media file (e.g. mp4, mp3, png, etc.).

Here's an example of how to access these details:

duration = media_info.duration
width = media_info.width
height = media_info.height

Example

import ffmpeg_media_type

# Specify the path to the media file
file_path = '/path/to/media/file.mp4'

# Detect media file information
media_info = ffmpeg_media_type.info.detect(file_path)

# Extract information from the media_info dictionary
duration = media_info.duration
width = media_info.width
height = media_info.height

# Print the extracted information
print(f"Duration: {duration} seconds")
print(f"Width: {width} pixels")
print(f"Height: {height} pixels")

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. If you would like to contribute code, please fork the repository and submit a pull request.

Before submitting a pull request, make sure to run the tests using the following command:

poetry install --with test
py.test src

Please ensure that your code follows the established coding style and passes all tests.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffmpeg_media_type-0.0.4.tar.gz (61.1 kB view hashes)

Uploaded Source

Built Distribution

ffmpeg_media_type-0.0.4-py3-none-any.whl (69.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page