Skip to main content

Performant Pythonic FFmpeg Decoder with easy to adapt flexible API.

Project description

deFFcode

Performant ⚡️ Pythonic FFmpeg Decoder with easy to adapt flexible API 🐍.

 

deffcode is a Performant and Robust FFmpeg Pythonic Wrapper that aimed at decoding any stream that you throw at it. Requiring minimal efforts, deffcode provides an easy-to-adapt flexible API to read a wide range of streams, and can ingest video using any decoder(even hardware ones) into any pixel format ffmpeg supports. It also provides pin-point accurate seeking for extracting only a specific part of your input as required.

It is cross-platform, runs on Python 3.7+, and is easy to install.

 

Examples

Basic Example

# import the necessary packages
from deffcode import FFdecoder

# initialize and formulate the decoder
decoder = FFdecoder("foo.mp4").formulate()

# grab the RGB24(default) frame from 
# the decoder(generator)
for frame in decoder.generateFrame():
	print(frame.shape)

# terminate the decoder
decoder.terminate()

The output:

(720, 1280, 3)
(720, 1280, 3)
     ...
     ...
     ...
(720, 1280, 3)

Basic OpenCV Example

# import the necessary packages
from deffcode import FFdecoder
import cv2

# initialize and formulate the decoder for BGR24 output
decoder = FFdecoder("foo.mp4", frame_format="bgr24").formulate()

# loop over frames
while True:
    # grab the BGR24 frame from the decoder
    frame = next(decoder.generateFrame(), None)

    # check if frame is None
    if frame is None:
        break
    
    # Show output window
    cv2.imshow("Output", frame)

    # check for 'q' key if pressed
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

# close output window
cv2.destroyAllWindows()
# terminate the decoder
decoder.terminate()

Basic PIL Example

# import the necessary packages
from deffcode import FFdecoder
from PIL import Image

# define the FFmpeg parameter to seek 
# to 00:00:01 in time and get one single frame
extraparams = {"-ss": "00:00:01", "-frames:v":1}

# initialize and formulate the decode
decoder = FFdecoder("foo.mp4", **extraparams).formulate()

# grab the RGB24(default) frame from the decoder
frame = next(decoder.generateFrame(), None)

# check if frame is None
if not(frame is None)
    # Convert and Show output window
    im = Image.fromarray(frame)
    im.show()

# terminate the decoder
decoder.terminate()

Basic Matplotlib Example

# import the necessary packages
from deffcode import FFdecoder
import matplotlib.pyplot as plt

# define the FFmpeg parameter to seek 
# to 00:00:02.01 in time and get one single frame
extraparams = {"-ss": "00:00:02.01", "-frames:v":1}

# initialize and formulate the decode for Grayscale output
decoder = FFdecoder("foo.mp4", frame_format="gray", **extraparams).formulate()

# grab single Grayscale frame from the decoder
frame = next(decoder.generateFrame(), None)

# Show output window
plt.imshow(frame, cmap='gray', vmin=0, vmax=255)
plt.show()

# terminate the decoder
decoder.terminate()

 

Dependencies

Minimal requirements:

  • Python 3.7+
  • FFmpeg (See this for its installation)
  • NumPy >=1.20.0
  • requests
  • colorlog
  • tqdm

:bulb: These requirements are installed automatically(except FFmpeg).

 

Installation

# Install latest stable release
pip install -U deffcode

And if you prefer to install deffcode directly from the repository:

# Install latest stable release
pip install git+git://github.com/abhiTronix/deffcode@master#egg=deffcode

Or you can also download its wheel (.whl) package from our repository's releases section, and thereby can be installed as follows:

# Install latest stable release
pip install deffcode-0.1.0-py3-none-any.whl

 


deffcode is Apache 2.0 Licensed code.
Designed & crafted with care.

⭐️

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

deffcode-0.1.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

deffcode-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file deffcode-0.1.0.tar.gz.

File metadata

  • Download URL: deffcode-0.1.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/26.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.0.1 keyring/21.4.0 rfc3986/1.4.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for deffcode-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7a8cb1dfa2428568d2af732f9ef903ed9cf27a3579d47adb1bdbfc0b5466770
MD5 744de1f897413488eb89fb24e4a64ee5
BLAKE2b-256 87daced7b13492da250aab3f7d8bb94e174fa1ea6543a25a77b84e83d3ec7d19

See more details on using hashes here.

File details

Details for the file deffcode-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: deffcode-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/26.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.0.1 keyring/21.4.0 rfc3986/1.4.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for deffcode-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b84d9ff21e90e8b910ef98f88e91716085b8c317779f4995be620936611d4fe
MD5 ed577169a750d38ae522b37a7908ee72
BLAKE2b-256 eb4239601ea991759b278ab428b77caf4c780e310bff69c838dc6819aa8e57b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page