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.
⭐️
Release files for deffcode 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deffcode-0.1.0.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deffcode-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.6 kB
Release files / deffcode-0.1.0.tar.gz
| Download URL | deffcode-0.1.0.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7a8cb1dfa2428568d2af732f9ef903ed9cf27a3579d47adb1bdbfc0b5466770
|
|
BLAKE2b-256 checksum How to use checksums |
87daced7b13492da250aab3f7d8bb94e174fa1ea6543a25a77b84e83d3ec7d19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / deffcode-0.1.0-py3-none-any.whl
| Download URL | deffcode-0.1.0-py3-none-any.whl |
|---|---|
| Size | 23.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b84d9ff21e90e8b910ef98f88e91716085b8c317779f4995be620936611d4fe
|
|
BLAKE2b-256 checksum How to use checksums |
eb4239601ea991759b278ab428b77caf4c780e310bff69c838dc6819aa8e57b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|