| 1 |
.. SPDX-FileCopyrightText: 2019-2020 Intel Corporation |
| 2 |
.. |
| 3 |
.. SPDX-License-Identifier: CC-BY-4.0 |
| 4 |
|
| 5 |
========================= |
| 6 |
Multiple-segment Encoding |
| 7 |
========================= |
| 8 |
|
| 9 |
Multiple-segment encoding is useful in video editing applications during |
| 10 |
production, for example when the encoder encodes multiple video clips according |
| 11 |
to their time line. In general, one can define multiple-segment encoding as |
| 12 |
dividing an input sequence of frames into segments and encoding them in different |
| 13 |
encoding sessions with the same or different parameter sets. For example: |
| 14 |
|
| 15 |
======================= =================== ===================== |
| 16 |
Segment Already Encoded Segment in Encoding Segment to be Encoded |
| 17 |
======================= =================== ===================== |
| 18 |
0s 200s 500s |
| 19 |
======================= =================== ===================== |
| 20 |
|
| 21 |
.. note:: Different encoders can also be used. |
| 22 |
|
| 23 |
The application must be able to: |
| 24 |
|
| 25 |
- Extract encoding parameters from the bitstream of previously encoded segment. |
| 26 |
- Import these encoding parameters to configure the encoder. |
| 27 |
|
| 28 |
Encoding can then continue on the current segment using either the same or |
| 29 |
similar encoding parameters. |
| 30 |
|
| 31 |
Extracting the header that contains the encoding parameter set from the encoded |
| 32 |
bitstream is usually the task of a format splitter (de-multiplexer). Alternatively, |
| 33 |
the :cpp:func:`MFXVideoDECODE_DecodeHeader` function can export |
| 34 |
the raw header if the application attaches the :cpp:struct:`mfxExtCodingOptionSPSPPS` |
| 35 |
structure as part of the parameters. |
| 36 |
|
| 37 |
The encoder can use the :cpp:struct:`mfxExtCodingOptionSPSPPS` structure to import |
| 38 |
the encoding parameters during :cpp:func:`MFXVideoENCODE_Init`. The encoding |
| 39 |
parameters are in the encoded bitstream format. Upon a successful import of the |
| 40 |
header parameters, the encoder will generate bitstreams with a compatible (not |
| 41 |
necessarily bit-exact) header. The |
| 42 |
:ref:`Header Import Functions table <header-import-func-table>` shows all |
| 43 |
functions that can import a header and their error codes if there are |
| 44 |
unsupported parameters in the header or the encoder is unable to achieve |
| 45 |
compatibility with the imported header. |
| 46 |
|
| 47 |
.. _header-import-func-table: |
| 48 |
|
| 49 |
.. list-table:: Header Import Functions |
| 50 |
:header-rows: 1 |
| 51 |
:widths: 50 50 |
| 52 |
|
| 53 |
* - **Function Name** |
| 54 |
- **Error Code if Import Fails** |
| 55 |
* - :cpp:func:`MFXVideoENCODE_Init` |
| 56 |
- :cpp:enumerator:`MFX_ERR_INCOMPATIBLE_VIDEO_PARAM` |
| 57 |
* - :cpp:func:`MFXVideoENCODE_QueryIOSurf` |
| 58 |
- :cpp:enumerator:`MFX_ERR_INCOMPATIBLE_VIDEO_PARAM` |
| 59 |
* - :cpp:func:`MFXVideoENCODE_Reset` |
| 60 |
- :cpp:enumerator:`MFX_ERR_INCOMPATIBLE_VIDEO_PARAM` |
| 61 |
* - :cpp:func:`MFXVideoENCODE_Query` |
| 62 |
- :cpp:enumerator:`MFX_ERR_UNSUPPORTED` |
| 63 |
|
| 64 |
|
| 65 |
The encoder must encode frames to a GOP sequence starting with an IDR frame for |
| 66 |
H.264 (or I frame for MPEG-2) to ensure that the current segment encoding does |
| 67 |
not refer to any frames in the previous segment. This ensures that the encoded |
| 68 |
segment is self-contained, allowing the application to insert the segment anywhere |
| 69 |
in the final bitstream. After encoding, each encoded segment is HRD compliant. |
| 70 |
Concatenated segments may not be HRD compliant. |
| 71 |
|
| 72 |
The following example shows the encoder initialization procedure that imports |
| 73 |
H.264 sequence and picture parameter sets: |
| 74 |
|
| 75 |
.. literalinclude:: ../snippets/appnd_b.c |
| 76 |
:language: c++ |
| 77 |
:start-after: /*beg*/ |
| 78 |
:end-before: /*end*/ |
| 79 |
:lineno-start: 1 |
| 80 |
|
| 81 |
|