Skip to content

Commit

Permalink
Added encoded_frame docs (#998)
Browse files Browse the repository at this point in the history
* Added encoded_frame docs
  • Loading branch information
jakaskerl authored Mar 21, 2024
1 parent cf41a43 commit 777d3a2
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
54 changes: 54 additions & 0 deletions docs/source/components/messages/encoded_frame.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
EncodedFrame
============

The ``EncodedFrame`` message is an output of the :ref:`VideoEncoder` node. This message is used to represent a frame that has been encoded by the VideoEncoder. It provides various properties and methods for interacting with the encoded frame data.

Structure
#########

The ``EncodedFrame`` class inherits from ``Buffer`` and includes several nested classes and methods for accessing and modifying frame properties. Here are the primary components of the ``EncodedFrame`` class:

- ``FrameType``: Enumerates the types of frames that can be encoded (I, P, B, Unknown).
- ``Profile``: Indicates the encoding profile used (AVC, HEVC, JPEG).

FrameType
---------

The ``FrameType`` class identifies the type of the encoded frame. The available types are:

- **B**: Represents a bi-directional predicted frame.
- **I**: Represents an intra-coded frame.
- **P**: Represents a predicted frame.
- **Unknown**: Used when the frame type cannot be determined.

Profile
-------

The ``Profile`` class specifies the encoding profile used for the frame. The supported profiles are:

- **AVC**: H.264/AVC encoding profile.
- **HEVC**: H.265/HEVC encoding profile.
- **JPEG**: JPEG encoding profile.


Reference
#########

.. tabs::

.. tab:: Python

.. autoclass:: depthai.EncodedFrame
:members:
:inherited-members:
:noindex:

.. tab:: C++

.. doxygenclass:: dai::EncodedFrame
:project: depthai-core
:members:
:private-members:
:undoc-members:

.. include:: ../../includes/footer-short.rst
12 changes: 7 additions & 5 deletions docs/source/components/nodes/video_encoder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ Inputs and Outputs
.. code-block::
┌──────────────┐
│ │
input │ │bitstream
─────────►│ VideoEncoder ├────────►
│ │
│ │ bitstream
input │ ├────────►
─────────►│ VideoEncoder |
│ │ out
├────────►
└──────────────┘
**Message types**

- :code:`input` - :ref:`ImgFrame` (NV12/GRAY8)
- :code:`bitstream` - :ref:`ImgFrame`
- :code:`out` - :ref:`EncodedFrame`

Usage
#####
Expand Down Expand Up @@ -101,6 +102,7 @@ Examples of functionality
- :ref:`RGB Encoding`
- :ref:`Encoding Max Limit`
- :ref:`RGB Encoding & MobilenetSSD`
- :ref:`Video Encoded Frame Type`

Reference
#########
Expand Down
39 changes: 39 additions & 0 deletions docs/source/samples/VideoEncoder/encoded_frame_type.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Video Encoded Frame Type
========================

This example showcases how to compress and print the sequence of encoded frame types (I, P, B) encountered during the encoding process.


Example script output
#####################

.. code-block::
~/depthai-python/examples$ python3 video_encoding.py
Press Ctrl+C to stop encoding...
To view the encoded data, convert the stream file (.h265) into a video file (.mp4) using a command below:
ffmpeg -framerate 30 -i video.h265 -c copy video.mp4
1I,29P,1I,29P,1I,29P,1I,29P,1I,29P,1I,29P,1I,29P,1I,29P,1I,29P,1I,18P
This output indicates the script's real-time video encoding process, and it compresses the sequence of frame types encountered. After stopping the script, it provides instructions to convert the raw H.265 stream into a playable MP4 video file. The final line shows a compressed representation of the frame types sequence, indicating the count of consecutive P, B, and I frames.

Setup
#####

.. include:: /includes/install_from_pypi.rst

Source code
###########

.. tabs::

.. tab:: Python

Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/VideoEncoder/rgb_encoding_encodedframe.py>`__

.. literalinclude:: ../../../../examples/VideoEncoder/rgb_encoding_encodedframe.py
:language: python
:linenos:

.. include:: /includes/footer-short.rst
1 change: 1 addition & 0 deletions docs/source/tutorials/code_samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ are presented with code.
- :ref:`RGB & Mono Encoding`- Encodes RGB (1080P, 30FPS) and both mono streams (720P, 30FPS) into :code:`.h265`/:code:`.h264` and saves them on the host
- :ref:`Encoding Max Limit` - Encodes RGB (4k 25FPS) and both mono streams (720P, 25FPS) into :code:`.h265`/:code:`.h264` and saves them on the host
- :ref:`RGB Full Resolution Saver` - Saves full resolution RGB images (4k) on the host (:code:`.jpeg`)
- :ref:`Video Encoded Frame Type` - Demonstrates how to view frame type when using video encoding

.. rubric:: Warp

Expand Down

0 comments on commit 777d3a2

Please sign in to comment.