deffcode

deffcode

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

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

DeFFcodeFFmpeg视频帧解码跨平台PythonGithub开源项目
<!-- DeFFcode library source-code is deployed under the Apache 2.0 License: Copyright (c) 2021 Abhishek Thakur(@abhiTronix) <abhi.una12@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================== --> <div align="center">

DeFFcode DeFFcode

</div> <div align="center">

[![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


</div> <div align="center">

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

</div>

<ins>Highly Adaptive</ins> - 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.

<ins>Highly Flexible</ins> - 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.

<ins>Highly Convenient</ins> - 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.
<!-- - [x] Lossless Transcoding support with [WriteGear](https://abhitronix.github.io/deffcode/latest/gears/writegear/introduction/). #TODO -->

 

 

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.

<br> <br>

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.

<br> <div align="center"> <a href="https://abhitronix.github.io/deffcode/latest/recipes/basic/transcode-live-frames-simplegraphs/#transcoding-trimmed-and-reversed-video"><img src="https://user-images.githubusercontent.com/34266896/211499038-46cc246d-843b-4c89-8e9a-5536395da9e7.gif" title="Click to view source code" width="70%" /> </a> <br> <sub><i>Big Buck Bunny Reversed using Live Simple Filtergraph</i></sub> </div> <br> <details open> <summary><b>Basic Decoding Recipes</b></summary>
  • [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]
</details> <details open> <summary><b>Basic Transcoding Recipes</b></summary>
  • [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]
</details> <details open> <summary><b>Basic Metadata Recipes</b></summary>
  • [Extracting video metadata using Sourcer API][extracting-video-metadata-using-sourcer-api]
  • [Extracting video metadata using FFdecoder API][extracting-video-metadata-using-ffdecoder-api]
</details> <br>

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

<br> <p align="center"> <a href="https://abhitronix.github.io/deffcode/latest/recipes/advanced/decode-live-virtual-sources/#generate-and-decode-frames-from-mandelbrot-test-pattern-with-vectorscope-waveforms"><img src="https://user-images.githubusercontent.com/34266896/211498819-13fe0487-e843-4315-b4f3-c881de6c8c4a.gif" alt="mandelbrot test pattern" title="Click to view source code" width="70%" /></a> <br> <sub><i>Live Mandelbrot pattern with a Vectorscope & two Waveforms</i></sub> </p> <br> <details open> <summary><b>Advanced Decoding Recipes</b></summary>
  • [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]
</details> <details open> <summary><b>Advanced Transcoding Recipes</b></summary>
  • [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]
</details> <details open> <summary><b>Advanced Metadata Recipes</b></summary>
  • [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]
</details> <br> <br>

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))
<details> <summary><b>The resultant Terminal Output will look something as following on Windows machine</b></summary>
{ "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 }
</details>

 

 

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

<div align="center"> <img src="https://abhitronix.github.io/deffcode/latest/assets/images/help_us.png" alt="Donation" width="50%" /> <p><i>DeFFcode is free and open source and will always remain so. ❤️</i></p> </div>

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 🙂

<a href='https://ko-fi.com/W7W8WTYO' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=4' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

 

 

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].

<!-- CI Badges -->

[appveyor]:

编辑推荐精选

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

下拉加载更多