Project Icon

deffcode

基于FFmpeg的跨平台视频帧解码处理库

DeFFcode是一个基于FFmpeg的跨平台视频帧解码库。它可实时生成低延迟的视频帧,支持多种输入源,提供对底层管道的完整控制,并保持与OpenCV兼容的编码语法。DeFFcode支持GPU加速、关键帧提取和元数据提取等功能,适用于计算机视觉应用开发。

DeFFcode DeFFcode

[![Build Status][github-cli]][github-flow] [![Codecov branch][codecov]][code] [![Azure DevOps builds (branch)][azure-badge]][azure-pipeline]

[![Glitter chat][gitter-bagde]][gitter] [![Build Status][appveyor]][app] [![PyPi version][pypi-badge]][pypi]

[![Code Style][black-badge]][black]


[Releases][release]   |   [Recipes][recipes]   |   [Documentation][docs]   |   [Installation][installation-notes]   |   License


DeFFcode - A cross-platform High-performance Video Frames Decoder that flexibly executes
FFmpeg pipeline inside a subprocess pipe for generating real-time, low-overhead,
lightning fast video frames with robust error-handling
in just a few lines of python code ⚡

Highly Adaptive - DeFFcode APIs implements a standalone highly-extensible wrapper around [FFmpeg][ffmpeg] multimedia framework. These APIs supports a wide-ranging media streams as input source such as [live USB/Virtual/IP camera feeds][capturing-and-previewing-frames-from-a-webcam], [regular multimedia files][decoding-video-files], [screen recordings][capturing-and-previewing-frames-from-your-desktop], [image sequences][decoding-image-sequences], [network URL schemes][decoding-network-streams] (such as HTTP(s), RTP/RSTP, etc.), so on and so forth.

Highly Flexible - DeFFcode APIs gains an edge over other FFmpeg Wrappers by providing complete control over the underline pipeline including access to almost any FFmpeg specification thinkable such as specifying framerate, resolution, hardware decoder(s), filtergraph(s), and pixel-format(s) that are readily supported by all well known Computer Vision libraries.

Highly Convenient - FFmpeg has a steep learning curve especially for users unfamiliar with a command line interface. DeFFcode helps users by providing similar to OpenCV, [Index based Camera Device Capturing][decoding-camera-devices-using-indexes] and the same standard OpenCV-Python (Python API for OpenCV) coding syntax for its APIs, thereby making it even easier to learn, create, and develop FFmpeg based apps in Python.

 

Key features of DeFFcode

Here are some key features that stand out:

  • High-performance, low-overhead video frames decoding with robust error-handling.
  • Flexible API with access to almost any FFmpeg specification thinkable.
  • Supports a wide-range of media streams/devices/protocols as input source.
  • Curated list of well-documented recipes ranging from [Basic][basic-recipes] to [Advanced][advanced-recipes] skill levels.
  • Hands down the easiest [Index based Camera Device Capturing][decoding-camera-devices-using-indexes], similar to OpenCV.
  • Easy to code Real-time [Simple][transcoding-live-simple-filtergraphs] & [Complex][transcoding-live-complex-filtergraphs] Filtergraphs. (Yes, You read it correctly "Real-time"!)
  • Lightning fast dedicated GPU-Accelerated Video [Decoding][hardware-accelerated-video-decoding] & [Transcoding][hardware-accelerated-video-transcoding].
  • Enables precise FFmpeg [Key-frame Seeking][extracting-key-frames-as-png-image] with pinpoint accuracy.
  • Effortless [Metadata Extraction][extracting-video-metadata] from all streams available in the source.
  • Maintains the standard easy to learn OpenCV-Python coding syntax.
  • Out-of-the-box support for all prominent Computer Vision libraries.
  • Cross-platform, runs on Python 3.7+, and easy to install.

 

 

Getting Started


📚 Documentation: https://abhitronix.github.io/deffcode


Installation:

If this is your first time using DeFFcode, head straight to the [Installation Notes][installation-notes] to install DeFFcode on your machine.



Recipes a.k.a Examples:

Once you have DeFFcode installed, checkout our Well-Documented [Recipes 🍱][basic-recipes] for usage examples:

Note In case you're run into any problems, consult our [Help section][help].

A. [Basic Recipes 🍰][basic-recipes]: Recipes for beginners of any skill level to get started.



Big Buck Bunny Reversed using Live Simple Filtergraph

Basic Decoding Recipes
  • [Accessing RGB frames from a video file][accessing-rgb-frames-from-a-video-file]
  • [Capturing and Previewing BGR frames from a video file][capturing-and-previewing-bgr-frames-from-a-video-file] (OpenCV Support)
  • [Playing with any other FFmpeg pixel formats][playing-with-any-other-ffmpeg-pixel-formats]
  • [Capturing and Previewing frames from a Looping Video][capturing-and-previewing-frames-from-a-looping-video]
  • [Enumerating all Camera Devices with Indexes][enumerating-all-camera-devices-with-indexes]
  • [Capturing and Previewing frames from a Camera using Indexes][capturing-and-previewing-frames-from-a-camera-using-indexes]
  • [Capturing and Previewing frames from a HTTPs Stream][capturing-and-previewing-frames-from-a-https-stream]
  • [Capturing and Previewing frames from a RTSP/RTP Stream][capturing-and-previewing-frames-from-a-rtsprtp-stream]
  • [Capturing and Previewing frames from Sequence of images][capturing-and-previewing-frames-from-sequence-of-images]
  • [Capturing and Previewing frames from Single looping image][capturing-and-previewing-frames-from-single-looping-image]
Basic Transcoding Recipes
  • [Transcoding video using OpenCV VideoWriter API][transcoding-video-using-opencv-videowriter-api]
  • [Transcoding lossless video using WriteGear API][transcoding-lossless-video-using-writegear-api]
  • [Transcoding Trimmed and Reversed video][transcoding-trimmed-and-reversed-video]
  • [Transcoding Cropped video][transcoding-cropped-video]
  • [Transcoding Rotated video (with rotate filter)][transcoding-rotated-video-with-rotate-filter]
  • [Transcoding Rotated video (with transpose filter)][transcoding-rotated-video-with-transpose-filter]
  • [Transcoding Horizontally flipped and Scaled video][transcoding-horizontally-flipped-and-scaled-video]
  • [Extracting Key-frames as PNG image][extracting-key-frames-as-png-image]
  • [Generating Thumbnail with a Fancy filter][generating-thumbnail-with-a-fancy-filter]
Basic Metadata Recipes
  • [Extracting video metadata using Sourcer API][extracting-video-metadata-using-sourcer-api]
  • [Extracting video metadata using FFdecoder API][extracting-video-metadata-using-ffdecoder-api]

B. [Advanced Recipes 🥐][advanced-recipes]: Recipes to take your skills to the next level.


mandelbrot test pattern
Live Mandelbrot pattern with a Vectorscope & two Waveforms


Advanced Decoding Recipes
  • [Generate and Decode frames from Sierpinski pattern][generate-and-decode-frames-from-sierpinski-pattern]
  • [Generate and Decode frames from Test Source pattern][generate-and-decode-frames-from-test-source-pattern]
  • [Generate and Decode frames from Gradients with custom Text effect][generate-and-decode-frames-from-gradients-with-custom-text-effect]
  • [Generate and Decode frames from Mandelbrot test pattern with vectorscope & waveforms][generate-and-decode-frames-from-mandelbrot-test-pattern-with-vectorscope-waveforms]
  • [Generate and Decode frames from Game of Life Visualization][generate-and-decode-frames-from-game-of-life-visualization]
  • [Capturing and Previewing frames from a Webcam using Custom Demuxer][capturing-and-previewing-frames-from-a-webcam-using-custom-demuxer]
  • [Capturing and Previewing frames from your Desktop][capturing-and-previewing-frames-from-your-desktop] (Screen Recording)
  • [CUVID-accelerated Hardware-based Video Decoding and Previewing][cuvid-accelerated-hardware-based-video-decoding-and-previewing]
  • [CUDA-accelerated Hardware-based Video Decoding and Previewing][cuda-accelerated-hardware-based-video-decoding-and-previewing]
Advanced Transcoding Recipes
  • [Transcoding video with Live Custom watermark image overlay][transcoding-video-with-live-custom-watermark-image-overlay]
  • [Transcoding video from sequence of Images with additional filtering][transcoding-video-from-sequence-of-images-with-additional-filtering]
  • [Transcoding video art with YUV Bitplane Visualization][transcoding-video-art-with-yuv-bitplane-visualization]
  • [Transcoding video art with Jetcolor effect][transcoding-video-art-with-jetcolor-effect]
  • [Transcoding video art with Ghosting effect][transcoding-video-art-with-ghosting-effect]
  • [Transcoding video art with Pixelation effect][transcoding-video-art-with-pixelation-effect]
  • [CUDA-accelerated Video Transcoding with OpenCV's VideoWriter API][cuda-accelerated-video-transcoding-with-opencvs-videowriter-api]
  • [CUDA-NVENC-accelerated Video Transcoding with WriteGear API][cuda-nvenc-accelerated-video-transcoding-with-writegear-api]
  • [CUDA-NVENC-accelerated End-to-end Lossless Video Transcoding with WriteGear API][cuda-nvenc-accelerated-end-to-end-lossless-video-transcoding-with-writegear-api]
Advanced Metadata Recipes
  • [Added new attributes to metadata in FFdecoder API][added-new-attributes-to-metadata-in-ffdecoder-api]
  • [Overriding source video metadata in FFdecoder API][overriding-source-video-metadata-in-ffdecoder-api]


API in a nutshell:

As a user, you just have to remember only two DeFFcode APIs, namely:

A. FFdecoder API

The primary function of [FFdecoder API][ffdecoder-api] is to decode 24-bit RGB video frames from the given source:

Note See [API Reference][ffdecoder-api] for more in-depth information.

# import the necessary packages
from deffcode import FFdecoder

# formulate the decoder with suitable source
decoder = FFdecoder("https://abhitronix.github.io/html/Big_Buck_Bunny_1080_10s_1MB.mp4").formulate()

# grab RGB24(default) 3D frames from decoder
for frame in decoder.generateFrame():

    # lets print its shape
    print(frame.shape) # (1080, 1920, 3)

# terminate the decoder
decoder.terminate()

B. Sourcer API

The primary function of [Sourcer API][sourcer-api] is to gather metadata information from all multimedia streams available in the given source:

# import the necessary packages
from deffcode import Sourcer

# initialize and formulate the decoder using suitable source
sourcer = Sourcer("https://abhitronix.github.io/html/Big_Buck_Bunny_1080_10s_1MB.mp4").probe_stream()

# print metadata as `json.dump`
print(sourcer.retrieve_metadata(pretty_json=True))
The resultant Terminal Output will look something as following on Windows machine
{
  "ffmpeg_binary_path": "C:\\Users\\foo\\AppData\\Local\\Temp\\ffmpeg-static-win64-gpl/bin/ffmpeg.exe",
  "source": "https://abhitronix.github.io/html/Big_Buck_Bunny_1080_10s_1MB.mp4",
  "source_extension": ".mp4",
  "source_video_resolution": [1920, 1080],
  "source_video_framerate": 60.0,
  "source_video_pixfmt": "yuv420p",
  "source_video_decoder": "h264",
  "source_duration_sec": 10.0,
  "approx_video_nframes": 600,
  "source_video_bitrate": "832k",
  "source_audio_bitrate": "",
  "source_audio_samplerate": "",
  "source_has_video": true,
  "source_has_audio": false,
  "source_has_image_sequence": false
}

 

 

Contributions

We're happy to meet new contributors💗

We welcome your contributions to help us improve and extend this project. If you want to get involved with DeFFcode development, checkout the [Contribution Guidelines ▶️][contribute]

We're offering support for DeFFcode on [Gitter Community Channel][gitter]. Come and join the conversation over there!

 

 

Donations

Donation

DeFFcode is free and open source and will always remain so. ❤️

It is something I am doing with my own free time. But so much more needs to be done, and I need your help to do this. For just the price of a cup of coffee, you can make a difference 🙂

Buy Me a Coffee at ko-fi.com

 

 

Citation

Here is a Bibtex entry you can use to cite this project in a publication:

DOI

@software{deffcode,
  author       = {Abhishek Thakur},
  title        = {abhiTronix/deffcode: v0.2.5},
  month        = jan,
  year         = 2023,
  publisher    = {Zenodo},
  version      = {v0.2.5},
  doi          = {10.5281/zenodo.7523792},
  url          = {https://doi.org/10.5281/zenodo.7523792}
}

 

 

Copyright

Copyright © abhiTronix 2021

This library is released under the [Apache 2.0 License][license].

[appveyor]:

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号