Skip to main content

A python binding for FFmpeg which provides sync and async APIs

Project description

python-ffmpeg

A python binding for FFmpeg which provides sync and async APIs

Help

See documentation for more details.

Install

To install python-ffmpeg, simply use pip:

$ pip install python-ffmpeg

Examples

You can find more examples in the documentation.

Transcoding

Synchronous API

from ffmpeg import FFmpeg, Progress


def main():
    ffmpeg = (
        FFmpeg()
        .option("y")
        .input("input.mp4")
        .output(
            "ouptut.mp4",
            {"codec:v": "libx264"},
            vf="scale=1280:-1",
            preset="veryslow",
            crf=24,
        )
    )

    ffmpeg.execute()


if __name__ == "__main__":
    main()

Asynchronous API

import asyncio

from ffmpeg import Progress
from ffmpeg.asyncio import FFmpeg


async def main():
    ffmpeg = (
        FFmpeg()
        .option("y")
        .input("input.mp4")
        .output(
            "ouptut.mp4",
            {"codec:v": "libx264"},
            vf="scale=1280:-1",
            preset="veryslow",
            crf=24,
        )
    )

    await ffmpeg.execute()


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

Recording

Synchronous API

from ffmpeg import FFmpeg, Progress


def main():
    ffmpeg = (
        FFmpeg()
        .option("y")
        .input(
            "rtsp://username:password@127.0.0.1/cam",
            rtsp_transport="tcp",
            rtsp_flags="prefer_tcp",
        )
        .output("output.mp4", vcodec="copy")
    )

    @ffmpeg.on("progress")
    def time_to_terminate(progress: Progress):
        if progress.frame > 200:
            ffmpeg.terminate()

    ffmpeg.execute()


if __name__ == "__main__":
    main()

Asynchronous API

import asyncio

from ffmpeg import Progress
from ffmpeg.asyncio import FFmpeg


async def main():
    ffmpeg = (
        FFmpeg()
        .option("y")
        .input(
            "rtsp://username:password@127.0.0.1/cam",
            rtsp_transport="tcp",
            rtsp_flags="prefer_tcp",
        )
        .output("output.mp4", vcodec="copy")
    )

    @ffmpeg.on("progress")
    def time_to_terminate(progress: Progress):
        if progress.frame > 200:
            ffmpeg.terminate()

    await ffmpeg.execute()


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

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

python-ffmpeg-2.0.2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

python_ffmpeg-2.0.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file python-ffmpeg-2.0.2.tar.gz.

File metadata

  • Download URL: python-ffmpeg-2.0.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for python-ffmpeg-2.0.2.tar.gz
Algorithm Hash digest
SHA256 56929580b3a2f4b55cd6f1a6928e9e689d525e0198b5194185c144b58e2de06a
MD5 210dacbc0bb8468f3afedf6d60b953d9
BLAKE2b-256 39000d8ba92cade682fee3c2f21adf960665df1b038a1cb576918bbf3345a139

See more details on using hashes here.

File details

Details for the file python_ffmpeg-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_ffmpeg-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7528eba0d8dfcb511bab08946fc14a90bd0fa41c456b4621768392295d45ba2
MD5 80935bcf74b75b4343a015b598acf18f
BLAKE2b-256 1c5612f3811b3dc0c7eef9d5a614f7fa55c8ec4b38d0cc030e707ef1df9fdebd

See more details on using hashes here.

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