Skip to main content

python-ffmpeg

A python interface for FFmpeg using asyncio

Requirements

  • Python 3.5+
  • pyee

Installation

pip install python-ffmpeg

Usage

import asyncio
from ffmpeg import FFmpeg

ffmpeg = FFmpeg().option('y').input(
    'rtsp://example.com/cam',
    # Specify file options using kwargs
    rtsp_transport='tcp',
    rtsp_flags='prefer_tcp',
).output(
    'output.ts',
    # Use a dictionary when an option name contains special characters
    {'codec:v': 'copy'},
    f='mpegts',
)

@ffmpeg.on('start')
def on_start(arguments):
    print('Arguments:', arguments)

@ffmpeg.on('stderr')
def on_stderr(line):
    print('stderr:', line)

@ffmpeg.on('progress')
def on_progress(progress):
    print(progress)

@ffmpeg.on('progress')
def time_to_terminate(progress):
    # Gracefully terminate when more than 200 frames are processed
    if progress.frame > 200:
        ffmpeg.terminate()

@ffmpeg.on('completed')
def on_completed():
    print('Completed')

@ffmpeg.on('terminated')
def on_terminated():
    print('Terminated')

@ffmpeg.on('error')
def on_error(code):
    print('Error:', code)

loop = asyncio.get_event_loop()
loop.run_until_complete(ffmpeg.execute())
loop.close()

API

FFmpeg

init(executable='ffmpeg')

  • executable: the path to the ffmpeg executable

Initializes the FFmpeg instance.

option(key, value=None)

  • key
  • value

Specifies a global option -key or -key value

input(url, options=None, **kwargs)

  • url
  • options
  • kwargs

Specifies an input file. An arbitrary number of input files can be specified by calling this method multiple times.

output(url, options=None, **kwargs)

  • url
  • options
  • kwargs

Specifies an output file. An arbitrary number of output files can be specified by calling this method multiple times.

execute()

Executes FFmpeg using specified options and files.

terminate()

Gracefully terminates the running FFmpeg process.

on(event, listener=None)

  • event: the name of the event
  • listener: the callback function

Registers the listener to the event. This method can be used as a decorator.

Event: 'start'

  • arguments: a sequence of arguments to execute FFmpeg

The 'start' event is emitted just before FFmpeg is executed.

Event: 'stderr'

  • line

The 'stderr' event is emitted when FFmpeg writes a line to stderr.

Event: 'progress'

  • progress: a namedtuple with frame, fps, size, time, bitrate, speed fields

The 'progress' event is emitted when FFmpeg reports progress.

Event: 'completed'

The 'completed' event is emitted when FFmpeg is successfully exited.

Event: 'terminated'

The 'terminated' event is emitted when FFmpeg is terminated by calling FFmpeg.terminate().

Event: 'error'

  • code: a return code of the FFmpeg process

The 'error' event is emitted when FFmpeg is exited with a non-zero return code

Metadata

Release files for python-ffmpeg 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-ffmpeg 1.0.11
File Size Uploaded Provenance Actions
python-ffmpeg-1.0.11.tar.gz 4.3 kB Without provenance Details for python-ffmpeg-1.0.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-ffmpeg 1.0.11
File Interpreter ABI Platform Actions
python_ffmpeg-1.0.11-py3-none-any.whl Python 3 none any Details for python_ffmpeg-1.0.11-py3-none-any.whl

Total release size: 9.8 kB

Release files / python-ffmpeg-1.0.11.tar.gz

Download URL python-ffmpeg-1.0.11.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bdf38ba5052f7128241a217a4411664e1047afa959416b30f133a3a349428e4c
BLAKE2b-256 checksum
How to use checksums
269aff292f5e50eacc5c6110c02e65025671fb813a219bfe1f86b824bc5061bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Release files / python_ffmpeg-1.0.11-py3-none-any.whl

Download URL python_ffmpeg-1.0.11-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4eb946e7457ff5db9ce1cbe138ecdbe53e7bfe4a15a78b39051fba6b64919f36
BLAKE2b-256 checksum
How to use checksums
7e94fefef2b3aa3805cf36fe4ac3b7b9cf24f20e8d46df56385fdacb1fc69542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

Security for python-ffmpeg 1.0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page