Lines Matching full:the
11 them into a bytestream. It generates complete chunks of the bytestream, including
12 all metadata, headers, etc. The resulting bytestream does not require any
13 further post-processing by the client.
15 Performing software stream processing, header generation etc. in the driver
17 operations are needed, use of the Stateless Video Encoder Interface (in
23 1. The general V4L2 API rules apply if not specified in this document
26 2. The meaning of words "must", "may", "should", etc. is as per `RFC
37 depending on encoder capabilities and following the general V4L2 guidelines.
42 7. Given an ``OUTPUT`` buffer A, then A' represents a buffer on the ``CAPTURE``
88 1. To enumerate the set of coded formats supported by the encoder, the
91 * The full set of supported formats will be returned, regardless of the
94 2. To enumerate the set of supported raw formats, the client may call
97 * Only the formats supported for the format currently active on ``CAPTURE``
101 the client must first set that coded format on ``CAPTURE`` and then
102 enumerate the formats on ``OUTPUT``.
104 3. The client may use :c:func:`VIDIOC_ENUM_FRAMESIZES` to detect supported
105 resolutions for a given format, passing the desired pixel format in
109 format will include all possible coded resolutions supported by the
110 encoder for the given coded pixel format.
113 will include all possible frame buffer resolutions supported by the
114 encoder for the given raw pixel format and coded format currently set on
117 4. The client may use :c:func:`VIDIOC_ENUM_FRAMEINTERVALS` to detect supported
118 frame intervals for a given format and resolution, passing the desired pixel
119 format in :c:type:`v4l2_frmivalenum` ``pixel_format`` and the resolution
125 supported by the encoder for the given coded pixel format and resolution.
129 by the encoder for the given raw pixel format and resolution and for the
134 not implemented, then there are no special restrictions other than the
135 limits of the codec itself.
137 5. Supported profiles and levels for the coded format currently set on
147 1. Set the coded format on the ``CAPTURE`` queue via :c:func:`VIDIOC_S_FMT`.
155 the coded format to be produced.
158 desired size of ``CAPTURE`` buffers; the encoder may adjust it to
173 the coded size selected by the encoder based on current state, e.g.
178 Changing the ``CAPTURE`` format may change the currently set ``OUTPUT``
179 format. How the new ``OUTPUT`` format is determined is up to the encoder
180 and the client must ensure it matches its needs afterwards.
183 source) for the selected coded format via :c:func:`VIDIOC_ENUM_FMT`.
196 raw format supported for the coded format currently selected on
197 the ``CAPTURE`` queue.
202 3. Set the raw source format on the ``OUTPUT`` queue via
211 raw format of the source.
223 requirements, as required by the currently selected formats, as
229 * Setting the ``OUTPUT`` format will reset the selection rectangles to their
230 default values, based on the new resolution, as described in the next
233 4. Set the raw frame interval on the ``OUTPUT`` queue via
234 :c:func:`VIDIOC_S_PARM`. This also sets the coded frame interval on the
235 ``CAPTURE`` queue to the same value.
246 the desired frame interval; the encoder may adjust it to
252 the adjusted frame interval.
256 Changing the ``OUTPUT`` frame interval *also* sets the framerate that
257 the encoder uses to encode the video. So setting the frame interval
259 that can be played back at that speed. The frame interval for the
260 ``OUTPUT`` queue is just a hint, the application may provide raw
261 frames at a different rate. It can be used by the driver to help
264 In the next step the ``CAPTURE`` frame interval can optionally be
266 were the coded frame interval can be different from the rate at
272 formats this is the time per two fields, since a frame consists of
277 It is due to historical reasons that changing the ``OUTPUT`` frame
278 interval also changes the coded frame interval on the ``CAPTURE``
280 break the existing API.
282 5. **Optional** Set the coded frame interval on the ``CAPTURE`` queue via
283 :c:func:`VIDIOC_S_PARM`. This is only necessary if the coded frame
284 interval is different from the raw frame interval, which is typically
285 the case for off-line encoding. Support for this feature is signalled
286 by the :ref:`V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL <fmtdesc-flags>` format flag.
297 the desired coded frame interval; the encoder may adjust it to
303 the adjusted frame interval.
307 Changing the ``CAPTURE`` frame interval sets the framerate for the
308 coded video. It does *not* set the rate at which buffers arrive on the
309 ``CAPTURE`` queue, that depends on how fast the encoder is and how
310 fast raw frames are queued on the ``OUTPUT`` queue.
315 formats this is the time per two fields, since a frame consists of
321 the desired coded frame interval for the ``OUTPUT`` queue.
323 However, drivers that can schedule multiple encoders based on the
326 6. **Optional.** Set the visible resolution for the stream metadata via
327 :c:func:`VIDIOC_S_SELECTION` on the ``OUTPUT`` queue if it is desired
328 to be different than the full OUTPUT resolution.
339 visible rectangle; this must fit within the `V4L2_SEL_TGT_CROP_BOUNDS`
346 visible rectangle adjusted by the encoder.
348 * The following selection targets are supported on ``OUTPUT``:
351 equal to the full source frame, matching the active ``OUTPUT``
358 rectangle within the source buffer to be encoded into the
365 e.g. the common 1920x1080 resolution may require the source
367 size. To avoid encoding the padding, the client needs to explicitly
372 The encoder may adjust the crop/compose rectangles to the nearest
373 supported ones to meet codec and hardware requirements. The client needs
374 to check the adjusted rectangle returned by :c:func:`VIDIOC_S_SELECTION`.
398 The actual number of allocated buffers may differ from the ``count``
399 given. The client must check the updated value of ``count`` after the
404 To allocate more than the minimum number of OUTPUT buffers (for pipeline
405 depth), the client may query the ``V4L2_CID_MIN_BUFFERS_FOR_OUTPUT``
406 control to get the minimum number of buffers required, and pass the
407 obtained value plus the number of additional buffers needed in the
427 adjusted to the number of allocated buffers.
430 :c:func:`VIDIOC_STREAMON`. This may be performed in any order. The actual
435 If the client stops the ``CAPTURE`` queue during the encode process and then
436 restarts it again, the encoder will begin generating a stream independent
437 from the stream generated before the stop. The exact constraints depend
438 on the coded format, but may include the following implications:
440 * encoded frames produced after the restart must not reference any
441 frames produced before the stop, e.g. no long term references for
450 This state is reached after the `Initialization` sequence finishes
451 successfully. In this state, the client queues and dequeues buffers to both
452 queues via :c:func:`VIDIOC_QBUF` and :c:func:`VIDIOC_DQBUF`, following the
455 The content of encoded ``CAPTURE`` buffers depends on the active coded pixel
457 in the documentation of each format.
460 queues and memory-to-memory devices. In addition, the order of encoded frames
461 dequeued from the ``CAPTURE`` queue may differ from the order of queuing raw
462 frames to the ``OUTPUT`` queue, due to properties of the selected coded format,
465 The client must not assume any direct relationship between ``CAPTURE`` and
470 ``CAPTURE`` (for example, if returning an encoded frame allowed the encoder
471 to return a frame that preceded it in display, but succeeded it in the decode
479 * buffers may become available on the ``CAPTURE`` queue without additional
480 buffers queued to ``OUTPUT`` (e.g. during drain or ``EOS``), because of the
481 ``OUTPUT`` buffers queued in the past whose encoding results are only
482 available at later time, due to specifics of the encoding process,
485 after being encoded into a corresponding ``CAPTURE`` buffer, e.g. if the
486 encoder needs to use the frame as a reference for encoding further frames.
491 originated from, the client can set the ``timestamp`` field of the
492 :c:type:`v4l2_buffer` struct when queuing an ``OUTPUT`` buffer. The
494 will have their ``timestamp`` field set to the same value when dequeued.
496 In addition to the straightforward case of one ``OUTPUT`` buffer producing
497 one ``CAPTURE`` buffer, the following cases are defined:
499 * one ``OUTPUT`` buffer generates multiple ``CAPTURE`` buffers: the same
502 * the encoding order differs from the presentation order (i.e. the
503 ``CAPTURE`` buffers are out-of-order compared to the ``OUTPUT`` buffers):
504 ``CAPTURE`` timestamps will not retain the order of ``OUTPUT`` timestamps.
508 To let the client distinguish between frame types (keyframes, intermediate
509 frames; the exact list of types depends on the coded format), the
511 :c:type:`v4l2_buffer` struct when dequeued. See the documentation of
515 Should an encoding error occur, it will be reported to the client with the level
516 of details depending on the encoder capabilities. Specifically:
518 * the ``CAPTURE`` buffer (if any) that contains the results of the failed encode
519 operation will be returned with the ``V4L2_BUF_FLAG_ERROR`` flag set,
521 * if the encoder is able to precisely report the ``OUTPUT`` buffer(s) that triggered
522 the error, such buffer(s) will be returned with the ``V4L2_BUF_FLAG_ERROR`` flag
527 If a ``CAPTURE`` buffer is too small then it is just returned with the
529 error occurred because the buffer was too small, and to provide support to
532 In case of a fatal failure that does not allow the encoding to continue, any
533 further operations on corresponding encoder file handle will return the -EIO
534 error code. The client may close the file handle and open a new one, or
535 alternatively reinitialize the instance by stopping streaming on both queues,
536 releasing all buffers and performing the Initialization sequence again.
541 The client is allowed to use :c:func:`VIDIOC_S_CTRL` to change encoder
542 parameters at any time. The availability of parameters is encoder-specific
543 and the client must query the encoder to find the set of available controls.
545 The ability to change each parameter during encoding is encoder-specific, as
546 per the standard semantics of the V4L2 control interface. The client may
547 attempt to set a control during encoding and if the operation fails with the
548 -EBUSY error code, the ``CAPTURE`` queue needs to be stopped for the
549 configuration change to be allowed. To do this, it may follow the `Drain`
550 sequence to avoid losing the already queued/encoded frames.
552 The timing of parameter updates is encoder-specific, as per the standard
553 semantics of the V4L2 control interface. If the client needs to apply the
554 parameters exactly at specific frame, using the Request API
555 (:ref:`media-request-api`) should be considered, if supported by the encoder.
560 To ensure that all the queued ``OUTPUT`` buffers have been processed and the
561 related ``CAPTURE`` buffers are given to the client, the client must follow the
562 drain sequence described below. After the drain sequence ends, the client has
563 received all encoded frames for all ``OUTPUT`` buffers queued before the
566 1. Begin the drain sequence by issuing :c:func:`VIDIOC_ENCODER_CMD`.
581 The sequence can be only initiated if both ``OUTPUT`` and ``CAPTURE``
582 queues are streaming. For compatibility reasons, the call to
583 :c:func:`VIDIOC_ENCODER_CMD` will not fail even if any of the queues is
584 not streaming, but at the same time it will not initiate the `Drain`
585 sequence and so the steps described below would not be applicable.
587 2. Any ``OUTPUT`` buffers queued by the client before the
589 normal. The client must continue to handle both queues independently,
592 * queuing and dequeuing ``CAPTURE`` buffers, until a buffer marked with the
597 The last buffer may be empty (with :c:type:`v4l2_buffer`
598 ``bytesused`` = 0) and in that case it must be ignored by the client,
603 Any attempt to dequeue more ``CAPTURE`` buffers beyond the buffer
607 * dequeuing processed ``OUTPUT`` buffers, until all the buffers queued
608 before the ``V4L2_ENC_CMD_STOP`` command are dequeued,
610 * dequeuing the ``V4L2_EVENT_EOS`` event, if the client subscribes to it.
614 For backwards compatibility, the encoder will signal a ``V4L2_EVENT_EOS``
615 event when the last frame has been encoded and all frames are ready to be
616 dequeued. It is deprecated behavior and the client must not rely on it.
617 The ``V4L2_BUF_FLAG_LAST`` buffer flag should be used instead.
619 3. Once all ``OUTPUT`` buffers queued before the ``V4L2_ENC_CMD_STOP`` call are
620 dequeued and the last ``CAPTURE`` buffer is dequeued, the encoder is stopped
622 until the client issues any of the following operations:
624 * ``V4L2_ENC_CMD_START`` - the encoder will not be reset and will resume
625 operation normally, with all the state from before the drain,
627 * a pair of :c:func:`VIDIOC_STREAMOFF` and :c:func:`VIDIOC_STREAMON` on the
628 ``CAPTURE`` queue - the encoder will be reset (see the `Reset` sequence)
631 * a pair of :c:func:`VIDIOC_STREAMOFF` and :c:func:`VIDIOC_STREAMON` on the
632 ``OUTPUT`` queue - the encoder will resume operation normally, however any
633 source frames queued to the ``OUTPUT`` queue between ``V4L2_ENC_CMD_STOP``
638 Once the drain sequence is initiated, the client needs to drive it to
639 completion, as described by the steps above, unless it aborts the process by
640 issuing :c:func:`VIDIOC_STREAMOFF` on any of the ``OUTPUT`` or ``CAPTURE``
641 queues. The client is not allowed to issue ``V4L2_ENC_CMD_START`` or
642 ``V4L2_ENC_CMD_STOP`` again while the drain sequence is in progress and they
647 * In case of no buffer in the ``OUTPUT`` queue at the time the
648 ``V4L2_ENC_CMD_STOP`` command was issued, the drain sequence completes
649 immediately and the encoder returns an empty ``CAPTURE`` buffer with the
652 * In case of no buffer in the ``CAPTURE`` queue at the time the drain
653 sequence completes, the next time the client queues a ``CAPTURE`` buffer
654 it is returned at once as an empty buffer with the ``V4L2_BUF_FLAG_LAST``
657 * If :c:func:`VIDIOC_STREAMOFF` is called on the ``CAPTURE`` queue in the
658 middle of the drain sequence, the drain sequence is canceled and all
659 ``CAPTURE`` buffers are implicitly returned to the client.
661 * If :c:func:`VIDIOC_STREAMOFF` is called on the ``OUTPUT`` queue in the
662 middle of the drain sequence, the drain sequence completes immediately and
663 next ``CAPTURE`` buffer will be returned empty with the
666 Although not mandatory, the availability of encoder commands may be queried
672 The client may want to request the encoder to reinitialize the encoding, so
673 that the following stream data becomes independent from the stream data
674 generated before. Depending on the coded format, that may imply that:
676 * encoded frames produced after the restart must not reference any frames
677 produced before the stop, e.g. no long term references for H.264/HEVC,
682 This can be achieved by performing the reset sequence.
684 1. Perform the `Drain` sequence to ensure all the in-flight encoding finishes
687 2. Stop streaming on the ``CAPTURE`` queue via :c:func:`VIDIOC_STREAMOFF`. This
688 will return all currently queued ``CAPTURE`` buffers to the client, without
691 3. Start streaming on the ``CAPTURE`` queue via :c:func:`VIDIOC_STREAMON` and
692 continue with regular encoding sequence. The encoded frames produced into
694 decoded without the need for frames encoded before the reset sequence,
695 starting at the first ``OUTPUT`` buffer queued after issuing the
696 `V4L2_ENC_CMD_STOP` of the `Drain` sequence.
699 without the ability to change the parameters on the fly.
704 Setting formats and allocating buffers triggers changes in the behavior of the
707 1. Setting the format on the ``CAPTURE`` queue may change the set of formats
708 supported/advertised on the ``OUTPUT`` queue. In particular, it also means
709 that the ``OUTPUT`` format may be reset and the client must not rely on the
712 2. Enumerating formats on the ``OUTPUT`` queue always returns only formats
713 supported for the current ``CAPTURE`` format.
715 3. Setting the format on the ``OUTPUT`` queue does not change the list of
716 formats available on the ``CAPTURE`` queue. An attempt to set the ``OUTPUT``
717 format that is not supported for the currently selected ``CAPTURE`` format
718 will result in the encoder adjusting the requested ``OUTPUT`` format to a
721 4. Enumerating formats on the ``CAPTURE`` queue always returns the full set of
722 supported coded formats, irrespective of the current ``OUTPUT`` format.
724 5. While buffers are allocated on any of the ``OUTPUT`` or ``CAPTURE`` queues,
725 the client must not change the format on the ``CAPTURE`` queue. Drivers will
726 return the -EBUSY error code for any such format change attempt.
728 To summarize, setting formats and allocation must always start with the
729 ``CAPTURE`` queue and the ``CAPTURE`` queue is the master that governs the
730 set of supported formats for the ``OUTPUT`` queue.