This demo shows how you can stream encoded frames from the device to the host and save them directly into a video container. depthai-python examples like RGB Encoding will save encoded stream into .h264
or .mjpeg
file and require that user runs a ffmpeg
command to convert raw encoded stream into a video container. Video is encoded on the device itself before it's sent to the host computer.
This demo uses PyAV library, which is just a binding library for the FFmpeg library.
This demo will use H265
codec by default. Note that some video players (eg. Quicktime) might not supprot this codec. We suggest using VLC.
As you can see, the video.mp4
uses the codec of the stream being saved, so there's no decoding/encoding (or converting) happening on the host computer and host CPU/GPU/RAM usage is minimal.
Besides ffmpeg and .mp4
video container (which is patent encumbered), you could also use the mkvmerge
(see MKVToolNix for GUI usage) and .mkv
video container to mux encoded stream into video file that is supported by all major video players (eg. VLC)
mkvmerge -o vid.mkv video.h265
python3 -m pip install -r requirements.txt
Usage: python3 main.py [codec]
Example: python3 main.py h264
codec can be either 'h264', 'h265', or 'mjpeg'.