Coder Social home page Coder Social logo

nixnodes / ffpyplayer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matham/ffpyplayer

0.0 2.0 0.0 25.81 MB

A cython implementation of an ffmpeg based player.

License: GNU Lesser General Public License v3.0

Shell 1.72% Makefile 0.06% Python 95.99% C 2.23%

ffpyplayer's Introduction

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

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

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

TravisCI status

Appveyor status

Supported Python versions

Latest Version on PyPI

Warning

Although the ffpyplayer source code is licensed under the LGPL, the ffpyplayer wheels for Windows and linux on PYPI are distributed under the GPL because the included FFmpeg binaries were compiled with GPL options.

If you want to use it under the LGPL you need to compile FFmpeg yourself with the correct options.

Similarly, the wheels bundle openssl for online camera support. However, releases are not made for every openssl release, so it is recommended that you compile ffpyplayer yourself if security is a issue.

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]

ffpyplayer's People

Contributors

charrea6 avatar germn avatar jeroenpeters1986 avatar matham avatar tigarmo avatar tito avatar tmiller02 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.