• Stars
    star
    274
  • Rank 150,274 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A python binding for FFmpeg which provides sync and async APIs

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


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.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:[email protected]/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:[email protected]/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())

More Repositories

1

python-mecab-ko

A python binding for mecab-ko
Python
89
star
2

python-switchbot

A Python library to control SwitchBot devices connected to SwitchBot Hub
Python
34
star
3

hangul-jamo

A library to compose and decompose Hangul syllables using Hangul jamo characters
Python
27
star
4

namu-wiki-extractor

A library to extract plaintexts from the JSON dump file of namu wiki
Python
24
star
5

joblib-progress

A contextmanager to track progress of joblib execution
Python
16
star
6

overwatch-stats

A Python library to query a player's overwatch stats from Battle.net
Python
12
star
7

python-chzzk

An unofficial Python library for CHZZK
Python
12
star
8

dockerfiles

Dockerfile
10
star
9

docker-ikev2-vpn

Dockerized IKEv2 VPN server
Shell
7
star
10

xts-aes-256

XTS-AES-256
Python
4
star
11

open-korean-text-python

Python interface to Open Korean Text Processor inspired by KoNLPy
Python
4
star
12

python-parsekit

A parser combinator for Python
Python
3
star
13

fastapi-query-conditions

Python
3
star
14

python-stopwatch

A simple stopwatch for measuring code performance
Python
3
star
15

griffe-generics

A Griffe extension that resolves generic type parameters as bound types in subclasses
Python
3
star
16

UIAlertView-Block

UIAlertView category to replace UIAletViewDelegate by block
Objective-C
2
star
17

scriptable

JavaScript
2
star
18

UIActionSheet-Block

UIActionSheet category to replace UIUIActionSheetDelegate by block
Objective-C
2
star
19

griffe-modernized-annotations

A Griffe extension that modernizes type annotations by adopting PEP 585 and PEP 604
Python
2
star
20

docker-casperjs

Dockerfile
1
star
21

dict-logic

Python
1
star
22

gpugpu

gpugpu shows current statistics of GPUs and memory usage by running containers.
Python
1
star
23

image-hash

Python
1
star
24

datasets

Python
1
star
25

gpugpu-exporter

Prometheus Exporter for GPU memory usage metrics of docker containers
Python
1
star
26

python-namumark

Python
1
star
27

mecab-ko

C++
1
star
28

snippets

Python
1
star
29

python-notification

A Python library to send notifications
Python
1
star