FFmpeg
v4l2_m2m_enc.c
Go to the documentation of this file.
1 /*
2  * V4L2 mem2mem encoders
3  *
4  * Copyright (C) 2017 Alexis Ballier <aballier@gentoo.org>
5  * Copyright (C) 2017 Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
26 #include <search.h>
27 #include "encode.h"
28 #include "libavcodec/avcodec.h"
29 #include "libavcodec/internal.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/pixfmt.h"
32 #include "libavutil/opt.h"
33 #include "profiles.h"
34 #include "v4l2_context.h"
35 #include "v4l2_m2m.h"
36 #include "v4l2_fmt.h"
37 
38 #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x
39 #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x
40 
41 static inline void v4l2_set_timeperframe(V4L2m2mContext *s, unsigned int num, unsigned int den)
42 {
43  struct v4l2_streamparm parm = { 0 };
44 
45  parm.type = V4L2_TYPE_IS_MULTIPLANAR(s->output.type) ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT;
46  parm.parm.output.timeperframe.denominator = den;
47  parm.parm.output.timeperframe.numerator = num;
48 
49  if (ioctl(s->fd, VIDIOC_S_PARM, &parm) < 0)
50  av_log(s->avctx, AV_LOG_WARNING, "Failed to set timeperframe");
51 }
52 
53 static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int value, const char *name, int log_warning)
54 {
55  struct v4l2_ext_controls ctrls = { { 0 } };
56  struct v4l2_ext_control ctrl = { 0 };
57 
58  /* set ctrls */
59  ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
60  ctrls.controls = &ctrl;
61  ctrls.count = 1;
62 
63  /* set ctrl*/
64  ctrl.value = value;
65  ctrl.id = id;
66 
67  if (ioctl(s->fd, VIDIOC_S_EXT_CTRLS, &ctrls) < 0)
68  av_log(s->avctx, log_warning || errno != EINVAL ? AV_LOG_WARNING : AV_LOG_DEBUG,
69  "Failed to set %s: %s\n", name, strerror(errno));
70  else
71  av_log(s->avctx, AV_LOG_DEBUG, "Encoder: %s = %d\n", name, value);
72 }
73 
74 static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int *value, const char *name, int log_warning)
75 {
76  struct v4l2_ext_controls ctrls = { { 0 } };
77  struct v4l2_ext_control ctrl = { 0 };
78  int ret;
79 
80  /* set ctrls */
81  ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
82  ctrls.controls = &ctrl;
83  ctrls.count = 1;
84 
85  /* set ctrl*/
86  ctrl.id = id ;
87 
88  ret = ioctl(s->fd, VIDIOC_G_EXT_CTRLS, &ctrls);
89  if (ret < 0) {
90  av_log(s->avctx, log_warning || errno != EINVAL ? AV_LOG_WARNING : AV_LOG_DEBUG,
91  "Failed to get %s\n", name);
92  return ret;
93  }
94 
95  *value = ctrl.value;
96 
97  return 0;
98 }
99 
100 static inline unsigned int v4l2_h264_profile_from_ff(int p)
101 {
102  static const struct h264_profile {
103  unsigned int ffmpeg_val;
104  unsigned int v4l2_val;
105  } profile[] = {
106  { FF_PROFILE_H264_CONSTRAINED_BASELINE, MPEG_VIDEO(H264_PROFILE_CONSTRAINED_BASELINE) },
107  { FF_PROFILE_H264_HIGH_444_PREDICTIVE, MPEG_VIDEO(H264_PROFILE_HIGH_444_PREDICTIVE) },
108  { FF_PROFILE_H264_HIGH_422_INTRA, MPEG_VIDEO(H264_PROFILE_HIGH_422_INTRA) },
109  { FF_PROFILE_H264_HIGH_444_INTRA, MPEG_VIDEO(H264_PROFILE_HIGH_444_INTRA) },
110  { FF_PROFILE_H264_HIGH_10_INTRA, MPEG_VIDEO(H264_PROFILE_HIGH_10_INTRA) },
111  { FF_PROFILE_H264_HIGH_422, MPEG_VIDEO(H264_PROFILE_HIGH_422) },
112  { FF_PROFILE_H264_BASELINE, MPEG_VIDEO(H264_PROFILE_BASELINE) },
113  { FF_PROFILE_H264_EXTENDED, MPEG_VIDEO(H264_PROFILE_EXTENDED) },
114  { FF_PROFILE_H264_HIGH_10, MPEG_VIDEO(H264_PROFILE_HIGH_10) },
115  { FF_PROFILE_H264_MAIN, MPEG_VIDEO(H264_PROFILE_MAIN) },
116  { FF_PROFILE_H264_HIGH, MPEG_VIDEO(H264_PROFILE_HIGH) },
117  };
118  int i;
119 
120  for (i = 0; i < FF_ARRAY_ELEMS(profile); i++) {
121  if (profile[i].ffmpeg_val == p)
122  return profile[i].v4l2_val;
123  }
124  return AVERROR(ENOENT);
125 }
126 
127 static inline int v4l2_mpeg4_profile_from_ff(int p)
128 {
129  static const struct mpeg4_profile {
130  unsigned int ffmpeg_val;
131  unsigned int v4l2_val;
132  } profile[] = {
133  { FF_PROFILE_MPEG4_ADVANCED_CODING, MPEG_VIDEO(MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY) },
134  { FF_PROFILE_MPEG4_ADVANCED_SIMPLE, MPEG_VIDEO(MPEG4_PROFILE_ADVANCED_SIMPLE) },
135  { FF_PROFILE_MPEG4_SIMPLE_SCALABLE, MPEG_VIDEO(MPEG4_PROFILE_SIMPLE_SCALABLE) },
136  { FF_PROFILE_MPEG4_SIMPLE, MPEG_VIDEO(MPEG4_PROFILE_SIMPLE) },
137  { FF_PROFILE_MPEG4_CORE, MPEG_VIDEO(MPEG4_PROFILE_CORE) },
138  };
139  int i;
140 
141  for (i = 0; i < FF_ARRAY_ELEMS(profile); i++) {
142  if (profile[i].ffmpeg_val == p)
143  return profile[i].v4l2_val;
144  }
145  return AVERROR(ENOENT);
146 }
147 
149 {
150  if (s->avctx->max_b_frames)
151  av_log(s->avctx, AV_LOG_WARNING, "Encoder does not support b-frames yet\n");
152 
153  v4l2_set_ext_ctrl(s, MPEG_CID(B_FRAMES), 0, "number of B-frames", 0);
154  v4l2_get_ext_ctrl(s, MPEG_CID(B_FRAMES), &s->avctx->max_b_frames, "number of B-frames", 0);
155  if (s->avctx->max_b_frames == 0)
156  return 0;
157 
158  avpriv_report_missing_feature(s->avctx, "DTS/PTS calculation for V4L2 encoding");
159 
160  return AVERROR_PATCHWELCOME;
161 }
162 
164 {
165  struct v4l2_event_subscription sub;
166 
167  memset(&sub, 0, sizeof(sub));
168  sub.type = V4L2_EVENT_EOS;
169  if (ioctl(s->fd, VIDIOC_SUBSCRIBE_EVENT, &sub) < 0)
170  av_log(s->avctx, AV_LOG_WARNING,
171  "the v4l2 driver does not support end of stream VIDIOC_SUBSCRIBE_EVENT\n");
172 }
173 
175 {
176  AVCodecContext *avctx = s->avctx;
177  int qmin_cid, qmax_cid, qmin, qmax;
178  int ret, val;
179 
180  /**
181  * requirements
182  */
184 
186  if (ret)
187  return ret;
188 
189  /**
190  * settingss
191  */
192  if (avctx->framerate.num || avctx->framerate.den)
194 
195  /* set ext ctrls */
196  v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode", 0);
197  v4l2_set_ext_ctrl(s, MPEG_CID(BITRATE) , avctx->bit_rate, "bit rate", 1);
198  v4l2_set_ext_ctrl(s, MPEG_CID(FRAME_RC_ENABLE), 1, "frame level rate control", 0);
199  v4l2_set_ext_ctrl(s, MPEG_CID(GOP_SIZE), avctx->gop_size,"gop size", 1);
200 
201  av_log(avctx, AV_LOG_DEBUG,
202  "Encoder Context: id (%d), profile (%d), frame rate(%d/%d), number b-frames (%d), "
203  "gop size (%d), bit rate (%"PRId64"), qmin (%d), qmax (%d)\n",
204  avctx->codec_id, avctx->profile, avctx->framerate.num, avctx->framerate.den,
205  avctx->max_b_frames, avctx->gop_size, avctx->bit_rate, avctx->qmin, avctx->qmax);
206 
207  switch (avctx->codec_id) {
208  case AV_CODEC_ID_H264:
209  if (avctx->profile != FF_PROFILE_UNKNOWN) {
211  if (val < 0)
212  av_log(avctx, AV_LOG_WARNING, "h264 profile not found\n");
213  else
214  v4l2_set_ext_ctrl(s, MPEG_CID(H264_PROFILE), val, "h264 profile", 1);
215  }
216  qmin_cid = MPEG_CID(H264_MIN_QP);
217  qmax_cid = MPEG_CID(H264_MAX_QP);
218  qmin = 0;
219  qmax = 51;
220  break;
221  case AV_CODEC_ID_MPEG4:
222  if (avctx->profile != FF_PROFILE_UNKNOWN) {
224  if (val < 0)
225  av_log(avctx, AV_LOG_WARNING, "mpeg4 profile not found\n");
226  else
227  v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_PROFILE), val, "mpeg4 profile", 1);
228  }
229  qmin_cid = MPEG_CID(MPEG4_MIN_QP);
230  qmax_cid = MPEG_CID(MPEG4_MAX_QP);
231  if (avctx->flags & AV_CODEC_FLAG_QPEL)
232  v4l2_set_ext_ctrl(s, MPEG_CID(MPEG4_QPEL), 1, "qpel", 1);
233  qmin = 1;
234  qmax = 31;
235  break;
236  case AV_CODEC_ID_H263:
237  qmin_cid = MPEG_CID(H263_MIN_QP);
238  qmax_cid = MPEG_CID(H263_MAX_QP);
239  qmin = 1;
240  qmax = 31;
241  break;
242  case AV_CODEC_ID_VP8:
243  qmin_cid = MPEG_CID(VPX_MIN_QP);
244  qmax_cid = MPEG_CID(VPX_MAX_QP);
245  qmin = 0;
246  qmax = 127;
247  break;
248  case AV_CODEC_ID_VP9:
249  qmin_cid = MPEG_CID(VPX_MIN_QP);
250  qmax_cid = MPEG_CID(VPX_MAX_QP);
251  qmin = 0;
252  qmax = 255;
253  break;
254  default:
255  return 0;
256  }
257 
258  if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
259  av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin should not "
260  "exceed qmax\n", avctx->qmin, avctx->qmax);
261  } else {
262  qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
263  qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
264  }
265 
266  v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
267  avctx->qmin >= 0);
268  v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
269  avctx->qmax >= 0);
270 
271  return 0;
272 }
273 
274 static int v4l2_send_frame(AVCodecContext *avctx, const AVFrame *frame)
275 {
276  V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
277  V4L2Context *const output = &s->output;
278 
279 #ifdef V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME
280  if (frame && frame->pict_type == AV_PICTURE_TYPE_I)
281  v4l2_set_ext_ctrl(s, MPEG_CID(FORCE_KEY_FRAME), 0, "force key frame", 1);
282 #endif
283 
285 }
286 
287 static int v4l2_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
288 {
289  V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
290  V4L2Context *const capture = &s->capture;
291  V4L2Context *const output = &s->output;
292  AVFrame *frame = s->frame;
293  int ret;
294 
295  if (s->draining)
296  goto dequeue;
297 
298  if (!frame->buf[0]) {
299  ret = ff_encode_get_frame(avctx, frame);
300  if (ret < 0 && ret != AVERROR_EOF)
301  return ret;
302 
303  if (ret == AVERROR_EOF)
304  frame = NULL;
305  }
306 
307  ret = v4l2_send_frame(avctx, frame);
308  if (ret != AVERROR(EAGAIN))
310 
311  if (ret < 0 && ret != AVERROR(EAGAIN))
312  return ret;
313 
314  if (!output->streamon) {
315  ret = ff_v4l2_context_set_status(output, VIDIOC_STREAMON);
316  if (ret) {
317  av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMON failed on output context\n");
318  return ret;
319  }
320  }
321 
322  if (!capture->streamon) {
323  ret = ff_v4l2_context_set_status(capture, VIDIOC_STREAMON);
324  if (ret) {
325  av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMON failed on capture context\n");
326  return ret;
327  }
328  }
329 
330 dequeue:
331  return ff_v4l2_context_dequeue_packet(capture, avpkt);
332 }
333 
335 {
336  V4L2Context *capture, *output;
337  V4L2m2mContext *s;
338  V4L2m2mPriv *priv = avctx->priv_data;
339  enum AVPixelFormat pix_fmt_output;
340  uint32_t v4l2_fmt_output;
341  int ret;
342 
343  ret = ff_v4l2_m2m_create_context(priv, &s);
344  if (ret < 0)
345  return ret;
346 
347  capture = &s->capture;
348  output = &s->output;
349 
350  /* common settings output/capture */
351  output->height = capture->height = avctx->height;
352  output->width = capture->width = avctx->width;
353 
354  /* output context */
355  output->av_codec_id = AV_CODEC_ID_RAWVIDEO;
356  output->av_pix_fmt = avctx->pix_fmt;
357 
358  /* capture context */
359  capture->av_codec_id = avctx->codec_id;
360  capture->av_pix_fmt = AV_PIX_FMT_NONE;
361 
362  s->avctx = avctx;
363  ret = ff_v4l2_m2m_codec_init(priv);
364  if (ret) {
365  av_log(avctx, AV_LOG_ERROR, "can't configure encoder\n");
366  return ret;
367  }
368 
369  if (V4L2_TYPE_IS_MULTIPLANAR(output->type))
370  v4l2_fmt_output = output->format.fmt.pix_mp.pixelformat;
371  else
372  v4l2_fmt_output = output->format.fmt.pix.pixelformat;
373 
374  pix_fmt_output = ff_v4l2_format_v4l2_to_avfmt(v4l2_fmt_output, AV_CODEC_ID_RAWVIDEO);
375  if (pix_fmt_output != avctx->pix_fmt) {
376  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt_output);
377  av_log(avctx, AV_LOG_ERROR, "Encoder requires %s pixel format.\n", desc->name);
378  return AVERROR(EINVAL);
379  }
380 
381  return v4l2_prepare_encoder(s);
382 }
383 
385 {
386  return ff_v4l2_m2m_codec_end(avctx->priv_data);
387 }
388 
389 #define OFFSET(x) offsetof(V4L2m2mPriv, x)
390 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
391 
392 #define V4L_M2M_CAPTURE_OPTS \
393  V4L_M2M_DEFAULT_OPTS,\
394  { "num_capture_buffers", "Number of buffers in the capture context", \
395  OFFSET(num_capture_buffers), AV_OPT_TYPE_INT, {.i64 = 4 }, 4, INT_MAX, FLAGS }
396 
397 static const AVOption mpeg4_options[] = {
400  { NULL },
401 };
402 
403 static const AVOption options[] = {
405  { NULL },
406 };
407 
409  { "qmin", "-1" },
410  { "qmax", "-1" },
411  { NULL },
412 };
413 
414 #define M2MENC_CLASS(NAME, OPTIONS_NAME) \
415  static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
416  .class_name = #NAME "_v4l2m2m_encoder", \
417  .item_name = av_default_item_name, \
418  .option = OPTIONS_NAME, \
419  .version = LIBAVUTIL_VERSION_INT, \
420  };
421 
422 #define M2MENC(NAME, LONGNAME, OPTIONS_NAME, CODEC) \
423  M2MENC_CLASS(NAME, OPTIONS_NAME) \
424  const AVCodec ff_ ## NAME ## _v4l2m2m_encoder = { \
425  .name = #NAME "_v4l2m2m" , \
426  .long_name = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " encoder wrapper"), \
427  .type = AVMEDIA_TYPE_VIDEO, \
428  .id = CODEC , \
429  .priv_data_size = sizeof(V4L2m2mPriv), \
430  .priv_class = &v4l2_m2m_ ## NAME ##_enc_class, \
431  .init = v4l2_encode_init, \
432  .receive_packet = v4l2_receive_packet, \
433  .close = v4l2_encode_close, \
434  .defaults = v4l2_m2m_defaults, \
435  .capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
436  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
437  .wrapper_name = "v4l2m2m", \
438  }
439 
440 M2MENC(mpeg4,"MPEG4", mpeg4_options, AV_CODEC_ID_MPEG4);
441 M2MENC(h263, "H.263", options, AV_CODEC_ID_H263);
442 M2MENC(h264, "H.264", options, AV_CODEC_ID_H264);
443 M2MENC(hevc, "HEVC", options, AV_CODEC_ID_HEVC);
444 M2MENC(vp8, "VP8", options, AV_CODEC_ID_VP8);
v4l2_h264_profile_from_ff
static unsigned int v4l2_h264_profile_from_ff(int p)
Definition: v4l2_m2m_enc.c:100
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
V4L2Context::av_pix_fmt
enum AVPixelFormat av_pix_fmt
AVPixelFormat corresponding to this buffer context.
Definition: v4l2_context.h:54
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
FF_PROFILE_MPEG4_SIMPLE
#define FF_PROFILE_MPEG4_SIMPLE
Definition: avcodec.h:1585
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2660
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FF_PROFILE_H264_BASELINE
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:1564
v4l2_encode_close
static av_cold int v4l2_encode_close(AVCodecContext *avctx)
Definition: v4l2_m2m_enc.c:384
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
v4l2_encode_init
static av_cold int v4l2_encode_init(AVCodecContext *avctx)
Definition: v4l2_m2m_enc.c:334
V4L2Context::av_codec_id
enum AVCodecID av_codec_id
AVCodecID corresponding to this buffer context.
Definition: v4l2_context.h:60
V4L2m2mContext
Definition: v4l2_m2m.h:43
FF_PROFILE_H264_CONSTRAINED_BASELINE
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
Definition: avcodec.h:1565
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
v4l2_subscribe_eos_event
static void v4l2_subscribe_eos_event(V4L2m2mContext *s)
Definition: v4l2_m2m_enc.c:163
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
pixdesc.h
ff_v4l2_context_dequeue_packet
int ff_v4l2_context_dequeue_packet(V4L2Context *ctx, AVPacket *pkt)
Dequeues a buffer from a V4L2Context to an AVPacket.
Definition: v4l2_context.c:651
internal.h
AVOption
AVOption.
Definition: opt.h:247
encode.h
FF_PROFILE_H264_HIGH_444_PREDICTIVE
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:1576
v4l2_send_frame
static int v4l2_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition: v4l2_m2m_enc.c:274
v4l2_get_ext_ctrl
static int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int *value, const char *name, int log_warning)
Definition: v4l2_m2m_enc.c:74
AVCodecContext::qmax
int qmax
maximum quantizer
Definition: avcodec.h:1165
v4l2_m2m_defaults
static const AVCodecDefault v4l2_m2m_defaults[]
Definition: v4l2_m2m_enc.c:408
FF_PROFILE_MPEG4_SIMPLE_SCALABLE
#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE
Definition: avcodec.h:1586
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1710
M2MENC
#define M2MENC(NAME, LONGNAME, OPTIONS_NAME, CODEC)
Definition: v4l2_m2m_enc.c:422
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:463
FF_PROFILE_H264_HIGH
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:1568
val
static double val(void *priv, double ch)
Definition: aeval.c:76
V4L2Context::streamon
int streamon
Whether the stream has been started (VIDIOC_STREAMON has been sent).
Definition: v4l2_context.h:88
AVRational::num
int num
Numerator.
Definition: rational.h:59
FF_PROFILE_MPEG4_CORE
#define FF_PROFILE_MPEG4_CORE
Definition: avcodec.h:1587
MPEG_VIDEO
#define MPEG_VIDEO(x)
Definition: v4l2_m2m_enc.c:39
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
v4l2_fmt.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
ff_v4l2_format_v4l2_to_avfmt
enum AVPixelFormat ff_v4l2_format_v4l2_to_avfmt(uint32_t v4l2_fmt, enum AVCodecID avcodec)
Definition: v4l2_fmt.c:132
v4l2_set_timeperframe
static void v4l2_set_timeperframe(V4L2m2mContext *s, unsigned int num, unsigned int den)
Definition: v4l2_m2m_enc.c:41
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:218
FF_PROFILE_H264_EXTENDED
#define FF_PROFILE_H264_EXTENDED
Definition: avcodec.h:1567
FF_PROFILE_UNKNOWN
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1526
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ff_v4l2_m2m_codec_init
int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv)
Probes the video nodes looking for the required codec capabilities.
Definition: v4l2_m2m.c:365
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:393
MPEG_CID
#define MPEG_CID(x)
Definition: v4l2_m2m_enc.c:38
v4l2_mpeg4_profile_from_ff
static int v4l2_mpeg4_profile_from_ff(int p)
Definition: v4l2_m2m_enc.c:127
AVCodecDefault
Definition: internal.h:215
V4L2Context
Definition: v4l2_context.h:37
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
options
static const AVOption options[]
Definition: v4l2_m2m_enc.c:403
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:433
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
profiles.h
ff_v4l2_m2m_create_context
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
Definition: v4l2_m2m.c:403
mpeg4_options
static const AVOption mpeg4_options[]
Definition: v4l2_m2m_enc.c:397
v4l2_receive_packet
static int v4l2_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: v4l2_m2m_enc.c:287
AV_CODEC_FLAG_QPEL
#define AV_CODEC_FLAG_QPEL
Use qpel MC.
Definition: avcodec.h:222
ff_v4l2_m2m_codec_end
int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
Releases all the codec resources if all AVBufferRefs have been returned to the ctx.
Definition: v4l2_m2m.c:339
V4L2Context::width
int width
Width and height of the frames it produces (in case of a capture context, e.g.
Definition: v4l2_context.h:72
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:578
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
FF_PROFILE_H264_HIGH_422
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:1572
FF_PROFILE_MPEG4_ADVANCED_CODING
#define FF_PROFILE_MPEG4_ADVANCED_CODING
Definition: avcodec.h:1596
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:54
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
ff_v4l2_context_set_status
int ff_v4l2_context_set_status(V4L2Context *ctx, uint32_t cmd)
Sets the status of a V4L2Context.
Definition: v4l2_context.c:567
FF_MPEG4_PROFILE_OPTS
#define FF_MPEG4_PROFILE_OPTS
Definition: profiles.h:40
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
FF_PROFILE_MPEG4_ADVANCED_SIMPLE
#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition: avcodec.h:1600
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:224
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:435
profile
int profile
Definition: mxfenc.c:2003
v4l2_context.h
ff_v4l2_context_enqueue_frame
int ff_v4l2_context_enqueue_frame(V4L2Context *ctx, const AVFrame *frame)
Enqueues a buffer to a V4L2Context from an AVFrame.
Definition: v4l2_context.c:581
AVCodecContext::height
int height
Definition: avcodec.h:556
v4l2_prepare_encoder
static int v4l2_prepare_encoder(V4L2m2mContext *s)
Definition: v4l2_m2m_enc.c:174
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:593
FF_PROFILE_H264_HIGH_10_INTRA
#define FF_PROFILE_H264_HIGH_10_INTRA
Definition: avcodec.h:1570
avcodec.h
FF_PROFILE_H264_HIGH_444_INTRA
#define FF_PROFILE_H264_HIGH_444_INTRA
Definition: avcodec.h:1577
ret
ret
Definition: filter_design.txt:187
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FF_PROFILE_H264_HIGH_422_INTRA
#define FF_PROFILE_H264_HIGH_422_INTRA
Definition: avcodec.h:1573
V4L2Context::height
int height
Definition: v4l2_context.h:72
AVCodecContext
main external API structure.
Definition: avcodec.h:383
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1158
AVRational::den
int den
Denominator.
Definition: rational.h:60
v4l2_set_ext_ctrl
static void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int value, const char *name, int log_warning)
Definition: v4l2_m2m_enc.c:53
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1525
V4L2m2mPriv
Definition: v4l2_m2m.h:71
FF_PROFILE_H264_MAIN
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:1566
desc
const char * desc
Definition: libsvtav1.c:79
AVCodecContext::max_b_frames
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:655
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:157
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
v4l2_m2m.h
FF_PROFILE_H264_HIGH_10
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:1569
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:556
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
V4L_M2M_CAPTURE_OPTS
#define V4L_M2M_CAPTURE_OPTS
Definition: v4l2_m2m_enc.c:392
v4l2_check_b_frame_support
static int v4l2_check_b_frame_support(V4L2m2mContext *s)
Definition: v4l2_m2m_enc.c:148