H264 Decoder Python Module
==========================
The aim of this project is to provide a simple decoder for video
captured by a Raspberry Pi camera. At the time of this writing I only
need H264 decoding, since a H264 stream is what the RPi software
delivers. Furthermore flexibility to incorporate the decoder in larger
python programs in various ways is desirable.
The code might also serve as example for libav and pybind11 usage.
Examples
--------
You can do something like this
```python
import h264decoder
import numpy as np
f = open(thefile, 'rb')
decoder = h264decoder.H264Decoder()
while 1:
data_in = f.read(1024)
if not data_in:
break
framedatas = decoder.decode(data_in)
for framedata in framedatas:
(frame, w, h, ls) = framedata
if frame is not None:
#print('frame size %i bytes, w %i, h %i, linesize %i' % (len(frame), w, h, ls))
frame = np.frombuffer(frame, dtype=np.ubyte, count=len(frame))
frame = frame.reshape((h, ls//3, 3))
frame = frame[:,:w,:]
# At this point `frame` references your usual height x width x rgb channels numpy array of unsigned bytes.
```
There are simple demo programs in the ```examples``` folder. ```display_frames.py``` is probably the one you want to take a look at.
Requirements
------------
* Python 3
* cmake for building
* libav / ffmpeg (swscale, avutil and avcodec)
* pybind11 (will be automatically downloaded from github if not found)
For the example scripts
* matplotlib
* numpy
I tested it on
* Ubuntu 18, gcc 9, Anaconda environment with Python 3.7, Libav from Ubuntu repo.
* Windows 10, Visual Studio Community 2017, Anaconda environment with Python 3.7, FFMPEG from vcpkg.
Building and Installing
-----------------------
### Windows
The suggested way to obtain ffmpeg is through [vcpkg](https://github.com/microsoft/vcpkg). Assuming all the setup including VC integration has been done, we can install the x64 libraries with
```cmd
vcpkg.exe install ffmpeg:x64-windows
```
We can build the extension module with setuptools almost normally. However cmake is used internally and we have to let it know the search paths to our libs. Hence the additional ```--cmake-args``` argument with the toolchain file as per vcpkg instructions.
```bash
python setup.py build_ext --cmake-args="-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake"
pip install -e .
```
The ```-e``` option installs symlinks to the build directory. Useful for development. Leave it out otherwise.
----------------------------------------------
Alternatively one can build the extension module manually with cmake.
From the project directory:
```cmd
mkdir [build dir name]
cd [build dir name]
cmake -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake -A x64 ..
cmake --build .
```
### Linux
Should be a matter of installing the libav or ffmpeg libraries. On Debian or Ubuntu:
```bash
sudo apt install libswscale-dev libavcodec-dev libavutil-dev
```
And then running
```bash
pip install .
```
in the project directory.
History
-------
### v2
For Python 3. Switch to PyBind11. Module renamed from libh264decoder to h264decoder! Support installation via setuptools.
### v1
For Python 2.7. Depends on Boost Python. Project/Build file generation with CMake.
Credits
-------
* [Michael Welter](https://github.com/DaWelter). Original author.
* [Martin Valgur](https://github.com/valgur). Switch to pybind11, nice build configuration and more.
License
-------
The code is published under the Mozilla Public License v. 2.0.

Fl4me
- 粉丝: 48
最新资源
- 大数据视野下易筋养生术的运用及推广.docx
- 绘制球体的SphereSceneNode类.doc
- 分布式核心DevOps平台概要设计.docx
- WEB的管理开题.doc
- 塔架监造检验项目管理及检验方法.doc
- 移动通信技术的发展及热点分析.doc
- XX物业项目管理的整体设计与构思.doc
- CentOS-Docker安装指南.doc
- 议网络信息技术在教学中的应用.docx
- 课堂讲义同步系列高中数学北师大版必修三课件:第二章算法初步(22)变量与赋值.ppt
- 济职设备自动化人才培养方案.doc
- plc自动售货机大学设计.doc
- 互联网+教育背景下的初中英语教学策略.docx
- 网站策划方案参考.docx
- 物料分拣控制系统的设计(PLC).docx
- 计算机工程写作指导.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0