Skip to main content

基于 FFmpeg 的音视频格式转换工具

Project description

FFmpeg Converter

基于 FFmpeg 的音视频格式转换工具,支持异步操作和进度监控。

CI Status Coverage Python Version PyPI version License: MIT

特性

  • 支持异步操作
  • 实时进度监控
  • 支持音频和视频格式转换
  • 丰富的转换参数配置
  • 类型提示支持

安装

  1. 安装 FFmpeg(必需)

    # Windows (使用 chocolatey)
    choco install ffmpeg
    
    # Linux (Ubuntu/Debian)
    sudo apt-get update && sudo apt-get install ffmpeg
    
  2. 安装 ffmpeg-converter

    pip install ffmpeg-converter
    

快速开始

音频转换

import asyncio
from ffmpeg_converter import AudioConverter

async def main():
    converter = AudioConverter()
    
    def progress_callback(progress, time_remaining, info):
        print(f"进度: {progress:.2f}%, 剩余时间: {time_remaining}")
    
    success = await converter.convert(
        input_file="input.mp3",
        output_file="output",
        output_format="wav",
        sample_rate=44100,
        channels=2,
        progress_callback=progress_callback,
    )
    
    if success:
        print("转换完成")
    else:
        print("转换失败")

if __name__ == "__main__":
    asyncio.run(main())

视频转换

import asyncio
from ffmpeg_converter import VideoConverter

async def main():
    converter = VideoConverter()
    
    def progress_callback(progress, time_remaining, info):
        print(f"进度: {progress:.2f}%, 剩余时间: {time_remaining}")
        if "conversion_speed" in info:
            print(f"转换速度: {info['conversion_speed']}")
    
    success = await converter.convert(
        input_file="input.mp4",
        output_file="output",
        output_format="mkv",
        video_codec="h264",
        video_bitrate="5M",
        resolution="1920x1080",
        fps=30,
        audio_codec="aac",
        audio_bitrate="192k",
        preset="fast",
        crf=23,
        progress_callback=progress_callback,
    )
    
    if success:
        print("转换完成")
    else:
        print("转换失败")

if __name__ == "__main__":
    asyncio.run(main())

开发

  1. 克隆仓库

    git clone https://github.com/ospoon/ffmpeg-converter.git
    cd ffmpeg-converter
    
  2. 安装开发依赖

    pip install uv
    uv venv
    uv sync
    
  3. 运行测试

    uv run pytest
    

贡献指南

欢迎贡献!请遵循以下步骤:

  1. Fork 本仓库
  2. 创建功能分支 ( git checkout -b feature/amazing-feature )
  3. 提交更改 ( git commit -m 'Add amazing feature' )
  4. 推送到分支 ( git push origin feature/amazing-feature )
  5. 开启 Pull Request

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件

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_converter-0.3.7.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

ffmpeg_converter-0.3.7-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file ffmpeg_converter-0.3.7.tar.gz.

File metadata

  • Download URL: ffmpeg_converter-0.3.7.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ffmpeg_converter-0.3.7.tar.gz
Algorithm Hash digest
SHA256 a838ecfdd32f718cef1badb02d35c7c2b025edd54783ff443f9584747458eb5e
MD5 a25a28f675a8762d8cb763b680409d3b
BLAKE2b-256 b21596579a7ae849d28e00617b65d932859217e2d31762d1cdc0a42a0fc4224c

See more details on using hashes here.

File details

Details for the file ffmpeg_converter-0.3.7-py3-none-any.whl.

File metadata

File hashes

Hashes for ffmpeg_converter-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 aeb5fdff726716742f39b05370d2676e31a972dbd7cf48d7994f8616726f1a24
MD5 ef33c029fb4a25672d997ee97502215e
BLAKE2b-256 c004aec709bc6c111dbbba6611e53bef254876dc2fc48a1f6b4959647fdc5065

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