- Notifications
You must be signed in to change notification settings - Fork58
DaWelter/h264decoder
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The aim of this project is to provide a simple decoder for videocaptured by a Raspberry Pi camera. At the time of this writing I onlyneed H264 decoding, since a H264 stream is what the RPi softwaredelivers. Furthermore flexibility to incorporate the decoder in largerpython programs in various ways is desirable.
The code might also serve as example for libav and pybind11 usage.
You can do something like this
importh264decoderimportnumpyasnpf=open(thefile,'rb')decoder=h264decoder.H264Decoder()while1:data_in=f.read(1024)ifnotdata_in:breakframedatas=decoder.decode(data_in)forframedatainframedatas: (frame,w,h,ls)=framedataifframeisnotNone:#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 theexamples folder.display_frames.py is probably the one you want to take a look at.
- 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.
The suggested way to obtain ffmpeg is throughvcpkg. Assuming all the setup including VC integration has been done, we can install the x64 libraries with
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.
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:
mkdir [builddir name]cd [builddir name]cmake -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake -A x64 ..cmake --build .
Should be a matter of installing the libav or ffmpeg libraries. On Debian or Ubuntu:
sudo apt install libswscale-dev libavcodec-dev libavutil-dev
And then running
pip install.in the project directory.
For Python 3. Switch to PyBind11. Module renamed from libh264decoder to h264decoder! Support installation via setuptools.
For Python 2.7. Depends on Boost Python. Project/Build file generation with CMake.
- Michael Welter. Original author.
- Martin Valgur. Switch to pybind11, nice build configuration and more.
The code is published under the Mozilla Public License v. 2.0.
About
h264 decoding module for python based on ffmpeg/libav
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.