Skip to main content

A collection of Python utilities for handling media files.

Project description

image-utils

When I am dealing pics,mp3,mp4. I always want a media utils to help me work, that's why this project start

mp4处理

  • 转png/jpg等
  • 转mp3
  • 转gif
  • 转竖屏
  • 其他格式视频转mp4

mp3处理

  • 转文字
  • 转srt
  • mp3裁剪
  • mp3其他格式,eg:flac,WAV,AAC,Ogg,等互相转换

图片png/jpg处理

  • 添加文字
  • 图片文字识别
  • 图片按比例放缩/图片旋转
  • 图片转灰白
  • 图片按比例剪切
  • 图片格式相互转换

install

pip install easy-media-utils
源码安装(点击展开) # pip freeze > requirements.txt

git clone https://github.com/aceliuchanghong/easy-media-utils.git

conda create -n dealMedia python=3.11

conda activate dealMedia

pip install -r requirements.txt

ffmpeg

前往官网,下载对应版本的文件,解压放在本地文件并且配置环境变量,确保可以访问到

ffmpeg -version

项目结构

项目结构生成(点击展开) from tree_utils.struct_tree_out import print_tree

path = r'D:\aprojectPython\pythonProject\easy-media-utils'

print_tree(path)

easy-media-utils/
|
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
├── base_model/
│   ├── MediaHandler.py
│   └── __init__.py
├── image_utils/
│   ├── __init__.py
│   ├── gpt_prompt.md
│   ├── converters/
│   │   ├── __init__.py
│   │   ├── format_converter.py
│   │   ├── image_to_text.py
│   │   └── text_add_to_image.py
│   ├── core/
│   │   ├── __init__.py
│   │   ├── exceptions.py
│   │   └── image_handler.py
│   ├── editors/
│   │   ├── __init__.py
│   │   ├── cropper.py
│   │   └── resizer.py
│   ├── tests/
│   │   ├── __init__.py
│   │   ├── test_converters.py
│   │   ├── test_editors.py
│   │   └── test_utils.py
│   └── utils/
│       ├── __init__.py
│       └── image_utils.py
├── mp3_utils/
│   ├── __init__.py
│   ├── gpt_prompt.md
│   ├── converters/
│   │   ├── __init__.py
│   │   ├── audio_format_converter.py
│   │   └── mp3_to_text.py
│   ├── core/
│   │   ├── __init__.py
│   │   ├── exceptions.py
│   │   └── mp3_handler.py
│   ├── editors/
│   │   ├── __init__.py
│   │   ├── effects.py
│   │   └── trimmer.py
│   ├── tests/
│   │   ├── __init__.py
│   │   ├── test_converters.py
│   │   └── test_editors.py
│   └── utils/
│       ├── __init__.py
│       └── mp3_utils.py
├── mp4_utils/
│   ├── __init__.py
│   ├── gpt_prompt.md
│   ├── converters/
│   │   ├── __init__.py
│   │   ├── mp4_to_gif.py
│   │   ├── mp4_to_mp3.py
│   │   ├── mp4_to_pngs.py
│   │   └── tv_to_mp4.py
│   ├── core/
│   │   ├── __init__.py
│   │   ├── exceptions.py
│   │   └── mp4_handler.py
│   ├── editors/
│   │   ├── __init__.py
│   │   ├── orientation.py
│   │   └── resizer.py
│   ├── tests/
│   │   ├── __init__.py
│   │   ├── test_converters.py
│   │   └── test_editors.py
│   └── utils/
│       ├── __init__.py
│       ├── file_utils.py
│       └── mp4_utils.py
├── testfiles/
└── tree_utils/
    ├── __init__.py
    └── struct_tree_out.py

e.g.

from mp4_utils.converters.mp4_to_gif import MP4ToGIFConverter
from mp4_utils.converters.mp4_to_mp3 import MP4ToMP3Converter
from mp4_utils.converters.mp4_to_pngs import MP4ToPNGsConverter
from mp4_utils.converters.tv_to_mp4 import TVToMP4Converter
from mp4_utils.core.mp4_handler import MP4Handler

def main(converter_type, file_path='../../testfiles/onboard_cover.mp4') -> MP4Handler:
    """
    Convert MP4 each frame.
    :param converter_type:
    :param file_path:
    """
    Converter = {
        "gif": MP4ToGIFConverter,
        "mp3": MP4ToMP3Converter,
        "img": MP4ToPNGsConverter,
        "other": TVToMP4Converter,
    }
    # converter = Converter[converter_type](file_path)
    converter = Converter.get(converter_type)(file_path)
    return converter

if __name__ == "__main__":
    file_path = '../../testfiles/out/onboard_cover.mp4'
    gif_out_path = '../../testfiles/out/output.gif'
    mp3_out_path = '../../testfiles/out/output.mp3'
    pngs_out_path = '../../testfiles/out/pngs_output'
    mp4_out_path = '../../testfiles/out/Sample.mp4'

    conv_file = '../../testfiles/out/Sample.mkv'

    converter_type = "img"
    ans_path = pngs_out_path
    converter = main(converter_type, file_path)
    converter.process(ans_path)
from mp3_utils.converters.audio_format_converter import AudioFormatConverter
from mp3_utils.core.mp3_handler import MP3Handler

def main(converter_type, file_path='../../testfiles/out/output.mp3') -> MP3Handler:
    """
    Convert MP4 each frame.
    :param converter_type:
    :param file_path:
    """
    Converter = {
        "format": AudioFormatConverter,
    }
    converter = Converter.get(converter_type)(file_path)
    return converter

if __name__ == "__main__":
    mp3_path = '../../testfiles/out/output.mp3'
    wav_path = '../../testfiles/out/output.wav'
    flac_path = '../../testfiles/out/output.flac'

    converter_type = "format"
    ans_path = flac_path

    converter = main(converter_type, wav_path)
    converter.process(ans_path, 'flac')
from image_utils.converters.format_converter import FormatConverter

test_image_path = "../../testfiles/out/pngs_output/frame_0001.png"
output_path = "../../testfiles/out/imgs_output"
txt = "你好"

if __name__ == '__main__':
    converter = FormatConverter(test_image_path)
    converter.process(output_path, "png")

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

easy-media-utils-0.1.5.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_media_utils-0.1.5-py3-none-any.whl (47.2 kB view details)

Uploaded Python 3

File details

Details for the file easy-media-utils-0.1.5.tar.gz.

File metadata

  • Download URL: easy-media-utils-0.1.5.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for easy-media-utils-0.1.5.tar.gz
Algorithm Hash digest
SHA256 79aff499620ea24ceb2c303684592c53fc6c4df77d993b745c24c04287d2d0e8
MD5 5d050939da983892980503f22549d125
BLAKE2b-256 705ce9539ef40bdaeb7ab742e68dbdf25e22abcea252dc503f2e59c597b8d4a4

See more details on using hashes here.

File details

Details for the file easy_media_utils-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_media_utils-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 32ed795c1696af6757d36e37206c3be7f3a8e2ec93c68cf7dc7795e9b9b211cf
MD5 3d1d33c5ce76283c76b0d66cac99487e
BLAKE2b-256 de4b8f216ce00412274d1a03f987227e962fd89d43ec276b5696d82c47225674

See more details on using hashes here.

Supported by

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