Skip to main content

A cython implementation of an ffmpeg based player.

Project description

FFPyPlayer is a python binding for the FFmpeg library for playing and writing media files.

For more information: https://matham.github.io/ffpyplayer/index.html

To install: https://matham.github.io/ffpyplayer/installation.html

TravisCI status Appveyor status Supported Python versions Latest Version on PyPI

Usage example

Playing a file:

>>> from ffpyplayer.player import MediaPlayer
>>> import time

>>> player = MediaPlayer(filename)
>>> val = ''
>>> while val != 'eof':
...     frame, val = player.get_frame()
...     if val != 'eof' and frame is not None:
...         img, t = frame
...         # display img

Writing a video file:

>>> from ffpyplayer.writer import MediaWriter
>>> from ffpyplayer.pic import Image

>>> w, h = 640, 480
>>> # write at 5 fps.
>>> out_opts = {'pix_fmt_in':'rgb24', 'width_in':w, 'height_in':h,
...     'codec':'rawvideo', 'frame_rate':(5, 1)}
>>> writer = MediaWriter('output.avi', [out_opts])

>>> # Construct image
>>> size = w * h * 3
>>> buf = bytearray([int(x * 255 / size) for x in range(size)])
>>> img = Image(plane_buffers=[buf], pix_fmt='rgb24', size=(w, h))

>>> for i in range(20):
...     writer.write_frame(img=img, pts=i / 5., stream=0)

Converting images:

>>> from ffpyplayer.pic import Image, SWScale
>>> w, h = 500, 100
>>> size = w * h * 3
>>> buf = bytearray([int(x * 255 / size) for x in range(size)])

>>> img = Image(plane_buffers=[buf], pix_fmt='rgb24', size=(w, h))
>>> sws = SWScale(w, h, img.get_pixel_format(), ofmt='yuv420p')

>>> img2 = sws.scale(img)
>>> img2.get_pixel_format()
'yuv420p'
>>> planes = img2.to_bytearray()
>>> map(len, planes)
[50000, 12500, 12500, 0]

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

ffpyplayer-4.5.1.tar.gz (88.9 kB view hashes)

Uploaded Source

Built Distributions

ffpyplayer-4.5.1-cp312-cp312-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

ffpyplayer-4.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp312-cp312-macosx_11_0_arm64.whl (18.1 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ffpyplayer-4.5.1-cp312-cp312-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

ffpyplayer-4.5.1-cp312-cp312-macosx_10_9_universal2.whl (39.6 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

ffpyplayer-4.5.1-cp311-cp311-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

ffpyplayer-4.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp311-cp311-macosx_11_0_arm64.whl (18.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ffpyplayer-4.5.1-cp311-cp311-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ffpyplayer-4.5.1-cp311-cp311-macosx_10_9_universal2.whl (39.7 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

ffpyplayer-4.5.1-cp310-cp310-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

ffpyplayer-4.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp310-cp310-macosx_11_0_arm64.whl (18.2 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ffpyplayer-4.5.1-cp310-cp310-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ffpyplayer-4.5.1-cp310-cp310-macosx_10_9_universal2.whl (39.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

ffpyplayer-4.5.1-cp39-cp39-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

ffpyplayer-4.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp39-cp39-macosx_11_0_arm64.whl (18.2 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ffpyplayer-4.5.1-cp39-cp39-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ffpyplayer-4.5.1-cp39-cp39-macosx_10_9_universal2.whl (39.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

ffpyplayer-4.5.1-cp38-cp38-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

ffpyplayer-4.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp38-cp38-macosx_11_0_arm64.whl (18.2 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

ffpyplayer-4.5.1-cp38-cp38-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

ffpyplayer-4.5.1-cp38-cp38-macosx_10_9_universal2.whl (39.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

ffpyplayer-4.5.1-cp37-cp37m-win_amd64.whl (60.9 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

ffpyplayer-4.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28.7 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

ffpyplayer-4.5.1-cp37-cp37m-macosx_10_9_x86_64.whl (21.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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