1 .. -*- coding: utf-8; mode: rst -*-
3 .. _VIDIOC_ENCODER_CMD:
5 ************************************************
6 ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
7 ************************************************
12 VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
18 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_encoder_cmd *argp )
25 File descriptor returned by :ref:`open() <func-open>`.
28 VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
36 These ioctls control an audio/video (usually MPEG-) encoder.
37 ``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
38 ``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
41 To send a command applications must initialize all fields of a struct
42 :ref:`v4l2_encoder_cmd <v4l2-encoder-cmd>` and call
43 ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
46 The ``cmd`` field must contain the command code. The ``flags`` field is
47 currently only used by the STOP command and contains one bit: If the
48 ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag is set, encoding will continue
49 until the end of the current *Group Of Pictures*, otherwise it will stop
52 A :ref:`read() <func-read>` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
53 call sends an implicit START command to the encoder if it has not been
54 started yet. After a STOP command, :ref:`read() <func-read>` calls will read
55 the remaining data buffered by the driver. When the buffer is empty,
56 :ref:`read() <func-read>` will return zero and the next :ref:`read() <func-read>`
57 call will restart the encoder.
59 A :ref:`close() <func-close>` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
60 call of a streaming file descriptor sends an implicit immediate STOP to
61 the encoder, and all buffered data is discarded.
63 These ioctls are optional, not all drivers may support them. They were
64 introduced in Linux 2.6.21.
69 .. flat-table:: struct v4l2_encoder_cmd
81 - The encoder command, see :ref:`encoder-cmds`.
89 - Flags to go with the command, see :ref:`encoder-flags`. If no
90 flags are defined for this command, drivers and applications must
91 set this field to zero.
99 - Reserved for future extensions. Drivers and applications must set
106 .. flat-table:: Encoder Commands
114 - ``V4L2_ENC_CMD_START``
118 - Start the encoder. When the encoder is already running or paused,
119 this command does nothing. No flags are defined for this command.
123 - ``V4L2_ENC_CMD_STOP``
127 - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
128 is set, encoding will continue until the end of the current *Group
129 Of Pictures*, otherwise encoding will stop immediately. When the
130 encoder is already stopped, this command does nothing. mem2mem
131 encoders will send a ``V4L2_EVENT_EOS`` event when the last frame
132 has been encoded and all frames are ready to be dequeued and will
133 set the ``V4L2_BUF_FLAG_LAST`` buffer flag on the last buffer of
134 the capture queue to indicate there will be no new buffers
135 produced to dequeue. This buffer may be empty, indicated by the
136 driver setting the ``bytesused`` field to 0. Once the
137 ``V4L2_BUF_FLAG_LAST`` flag was set, the
138 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
139 but return an ``EPIPE`` error code.
143 - ``V4L2_ENC_CMD_PAUSE``
147 - Pause the encoder. When the encoder has not been started yet, the
148 driver will return an ``EPERM`` error code. When the encoder is
149 already paused, this command does nothing. No flags are defined
154 - ``V4L2_ENC_CMD_RESUME``
158 - Resume encoding after a PAUSE command. When the encoder has not
159 been started yet, the driver will return an ``EPERM`` error code. When
160 the encoder is already running, this command does nothing. No
161 flags are defined for this command.
167 .. flat-table:: Encoder Command Flags
175 - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
179 - Stop encoding at the end of the current *Group Of Pictures*,
180 rather than immediately.
186 On success 0 is returned, on error -1 and the ``errno`` variable is set
187 appropriately. The generic error codes are described at the
188 :ref:`Generic Error Codes <gen-errors>` chapter.
191 The ``cmd`` field is invalid.
194 The application sent a PAUSE or RESUME command when the encoder was