FFmpeg
vaapi_encode_mjpeg.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <va/va.h>
20 #include <va/va_enc_jpeg.h>
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/common.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 
28 #include "avcodec.h"
29 #include "bytestream.h"
30 #include "cbs.h"
31 #include "cbs_jpeg.h"
32 #include "codec_internal.h"
33 #include "jpegtables.h"
34 #include "mjpeg.h"
35 #include "put_bits.h"
36 #include "vaapi_encode.h"
37 
38 
39 // Standard JPEG quantisation tables, in zigzag order.
40 static const unsigned char vaapi_encode_mjpeg_quant_luminance[64] = {
41  16, 11, 12, 14, 12, 10, 16, 14,
42  13, 14, 18, 17, 16, 19, 24, 40,
43  26, 24, 22, 22, 24, 49, 35, 37,
44  29, 40, 58, 51, 61, 60, 57, 51,
45  56, 55, 64, 72, 92, 78, 64, 68,
46  87, 69, 55, 56, 80, 109, 81, 87,
47  95, 98, 103, 104, 103, 62, 77, 113,
48  121, 112, 100, 120, 92, 101, 103, 99,
49 };
50 static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64] = {
51  17, 18, 18, 24, 21, 24, 47, 26,
52  26, 47, 99, 66, 56, 66, 99, 99,
53  99, 99, 99, 99, 99, 99, 99, 99,
54  99, 99, 99, 99, 99, 99, 99, 99,
55  99, 99, 99, 99, 99, 99, 99, 99,
56  99, 99, 99, 99, 99, 99, 99, 99,
57  99, 99, 99, 99, 99, 99, 99, 99,
58  99, 99, 99, 99, 99, 99, 99, 99,
59 };
60 
61 typedef struct VAAPIEncodeMJPEGContext {
63 
64  // User options.
65  int jfif;
66  int huffman;
67 
68  // Derived settings.
69  int quality;
70  uint8_t jfif_data[14];
71 
72  // Writer structures.
78 
82 
84  VAAPIEncodePicture *pic,
85  VAAPIEncodeSlice *slice,
86  char *data, size_t *data_len)
87 {
88  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
90  int err;
91 
92  if (priv->jfif) {
93  err = ff_cbs_insert_unit_content(frag, -1,
94  JPEG_MARKER_APPN + 0,
95  &priv->jfif_header, NULL);
96  if (err < 0)
97  goto fail;
98  }
99 
100  err = ff_cbs_insert_unit_content(frag, -1,
102  &priv->quant_tables, NULL);
103  if (err < 0)
104  goto fail;
105 
106  err = ff_cbs_insert_unit_content(frag, -1,
108  &priv->frame_header, NULL);
109  if (err < 0)
110  goto fail;
111 
112  if (priv->huffman) {
113  err = ff_cbs_insert_unit_content(frag, -1,
115  &priv->huffman_tables, NULL);
116  if (err < 0)
117  goto fail;
118  }
119 
120  err = ff_cbs_insert_unit_content(frag, -1,
122  &priv->scan, NULL);
123  if (err < 0)
124  goto fail;
125 
126  err = ff_cbs_write_fragment_data(priv->cbc, frag);
127  if (err < 0) {
128  av_log(avctx, AV_LOG_ERROR, "Failed to write image header.\n");
129  goto fail;
130  }
131 
132  if (*data_len < 8 * frag->data_size) {
133  av_log(avctx, AV_LOG_ERROR, "Image header too large: "
134  "%zu < %zu.\n", *data_len, 8 * frag->data_size);
135  err = AVERROR(ENOSPC);
136  goto fail;
137  }
138 
139  // Remove the EOI at the end of the fragment.
140  memcpy(data, frag->data, frag->data_size - 2);
141  *data_len = 8 * (frag->data_size - 2);
142 
143  err = 0;
144 fail:
145  ff_cbs_fragment_reset(frag);
146  return err;
147 }
148 
150  VAAPIEncodePicture *pic,
151  int index, int *type,
152  char *data, size_t *data_len)
153 {
154  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
155  int t, i, k;
156 
157  if (index == 0) {
158  // Write quantisation tables.
159  JPEGRawFrameHeader *fh = &priv->frame_header;
161  VAQMatrixBufferJPEG *quant;
162 
163  if (*data_len < sizeof(*quant))
164  return AVERROR(ENOSPC);
165  *type = VAQMatrixBufferType;
166  *data_len = sizeof(*quant);
167 
168  quant = (VAQMatrixBufferJPEG*)data;
169  memset(quant, 0, sizeof(*quant));
170 
171  quant->load_lum_quantiser_matrix = 1;
172  for (i = 0; i < 64; i++)
173  quant->lum_quantiser_matrix[i] = dqt->table[fh->Tq[0]].Q[i];
174 
175  if (fh->Nf > 1) {
176  quant->load_chroma_quantiser_matrix = 1;
177  for (i = 0; i < 64; i++)
178  quant->chroma_quantiser_matrix[i] =
179  dqt->table[fh->Tq[1]].Q[i];
180  }
181 
182  } else if (index == 1) {
183  // Write huffman tables.
184  JPEGRawScanHeader *sh = &priv->scan.header;
186  VAHuffmanTableBufferJPEGBaseline *huff;
187 
188  if (*data_len < sizeof(*huff))
189  return AVERROR(ENOSPC);
190  *type = VAHuffmanTableBufferType;
191  *data_len = sizeof(*huff);
192 
193  huff = (VAHuffmanTableBufferJPEGBaseline*)data;
194  memset(huff, 0, sizeof(*huff));
195 
196  for (t = 0; t < 1 + (sh->Ns > 1); t++) {
197  const JPEGRawHuffmanTable *ht;
198 
199  huff->load_huffman_table[t] = 1;
200 
201  ht = &dht->table[2 * t];
202  for (i = k = 0; i < 16; i++)
203  k += (huff->huffman_table[t].num_dc_codes[i] = ht->L[i]);
204  av_assert0(k <= sizeof(huff->huffman_table[t].dc_values));
205  for (i = 0; i < k; i++)
206  huff->huffman_table[t].dc_values[i] = ht->V[i];
207 
208  ht = &dht->table[2 * t + 1];
209  for (i = k = 0; i < 16; i++)
210  k += (huff->huffman_table[t].num_ac_codes[i] = ht->L[i]);
211  av_assert0(k <= sizeof(huff->huffman_table[t].ac_values));
212  for (i = 0; i < k; i++)
213  huff->huffman_table[t].ac_values[i] = ht->V[i];
214  }
215 
216  } else {
217  return AVERROR_EOF;
218  }
219  return 0;
220 }
221 
223  VAAPIEncodePicture *pic)
224 {
225  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
226  JPEGRawFrameHeader *fh = &priv->frame_header;
227  JPEGRawScanHeader *sh = &priv->scan.header;
228  VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params;
229  const AVPixFmtDescriptor *desc;
230  const uint8_t components_rgb[3] = { 'R', 'G', 'B' };
231  const uint8_t components_yuv[3] = { 1, 2, 3 };
232  const uint8_t *components;
233  int t, i, quant_scale, len;
234 
236 
238  av_assert0(desc);
239  if (desc->flags & AV_PIX_FMT_FLAG_RGB)
240  components = components_rgb;
241  else
242  components = components_yuv;
243 
244  // Frame header.
245 
246  fh->P = 8;
247  fh->Y = avctx->height;
248  fh->X = avctx->width;
249  fh->Nf = desc->nb_components;
250 
251  for (i = 0; i < fh->Nf; i++) {
252  fh->C[i] = components[i];
253  fh->H[i] = 1 + (i == 0 ? desc->log2_chroma_w : 0);
254  fh->V[i] = 1 + (i == 0 ? desc->log2_chroma_h : 0);
255 
256  fh->Tq[i] = !!i;
257  }
258 
259  fh->Lf = 8 + 3 * fh->Nf;
260 
261  // JFIF header.
262  if (priv->jfif) {
263  JPEGRawApplicationData *app = &priv->jfif_header;
265  int sar_w, sar_h;
266  PutByteContext pbc;
267 
269  sizeof(priv->jfif_data));
270 
271  bytestream2_put_buffer(&pbc, "JFIF", 5);
272  bytestream2_put_be16(&pbc, 0x0102);
273  bytestream2_put_byte(&pbc, 0);
274 
275  av_reduce(&sar_w, &sar_h, sar.num, sar.den, 65535);
276  if (sar_w && sar_h) {
277  bytestream2_put_be16(&pbc, sar_w);
278  bytestream2_put_be16(&pbc, sar_h);
279  } else {
280  bytestream2_put_be16(&pbc, 1);
281  bytestream2_put_be16(&pbc, 1);
282  }
283 
284  bytestream2_put_byte(&pbc, 0);
285  bytestream2_put_byte(&pbc, 0);
286 
288 
289  app->Lp = 2 + sizeof(priv->jfif_data);
290  app->Ap = priv->jfif_data;
291  app->Ap_ref = NULL;
292  }
293 
294  // Quantisation tables.
295 
296  if (priv->quality < 50)
297  quant_scale = 5000 / priv->quality;
298  else
299  quant_scale = 200 - 2 * priv->quality;
300 
301  len = 2;
302 
303  for (t = 0; t < 1 + (fh->Nf > 1); t++) {
305  const uint8_t *data = t == 0 ?
308 
309  quant->Pq = 0;
310  quant->Tq = t;
311  for (i = 0; i < 64; i++)
312  quant->Q[i] = av_clip(data[i] * quant_scale / 100, 1, 255);
313 
314  len += 65;
315  }
316 
317  priv->quant_tables.Lq = len;
318 
319  // Huffman tables.
320 
321  len = 2;
322 
323  for (t = 0; t < 2 + 2 * (fh->Nf > 1); t++) {
324  JPEGRawHuffmanTable *huff = &priv->huffman_tables.table[t];
325  const uint8_t *lengths, *values;
326  int k;
327 
328  switch (t) {
329  case 0:
330  lengths = ff_mjpeg_bits_dc_luminance + 1;
332  break;
333  case 1:
334  lengths = ff_mjpeg_bits_ac_luminance + 1;
336  break;
337  case 2:
338  lengths = ff_mjpeg_bits_dc_chrominance + 1;
340  break;
341  case 3:
342  lengths = ff_mjpeg_bits_ac_chrominance + 1;
344  break;
345  }
346 
347  huff->Tc = t % 2;
348  huff->Th = t / 2;
349 
350  for (i = k = 0; i < 16; i++)
351  k += (huff->L[i] = lengths[i]);
352 
353  for (i = 0; i < k; i++)
354  huff->V[i] = values[i];
355 
356  len += 17 + k;
357  }
358 
359  priv->huffman_tables.Lh = len;
360 
361  // Scan header.
362 
363  sh->Ns = fh->Nf;
364 
365  for (i = 0; i < fh->Nf; i++) {
366  sh->Cs[i] = fh->C[i];
367  sh->Td[i] = i > 0;
368  sh->Ta[i] = i > 0;
369  }
370 
371  sh->Ss = 0;
372  sh->Se = 63;
373  sh->Ah = 0;
374  sh->Al = 0;
375 
376  sh->Ls = 6 + 2 * sh->Ns;
377 
378 
379  *vpic = (VAEncPictureParameterBufferJPEG) {
380  .reconstructed_picture = pic->recon_surface,
381  .coded_buf = pic->output_buffer,
382 
383  .picture_width = fh->X,
384  .picture_height = fh->Y,
385 
386  .pic_flags.bits = {
387  .profile = 0,
388  .progressive = 0,
389  .huffman = 1,
390  .interleaved = 0,
391  .differential = 0,
392  },
393 
394  .sample_bit_depth = fh->P,
395  .num_scan = 1,
396  .num_components = fh->Nf,
397 
398  // The driver modifies the provided quantisation tables according
399  // to this quality value; the middle value of 50 makes that the
400  // identity so that they are used unchanged.
401  .quality = 50,
402  };
403 
404  for (i = 0; i < fh->Nf; i++) {
405  vpic->component_id[i] = fh->C[i];
406  vpic->quantiser_table_selector[i] = fh->Tq[i];
407  }
408 
409  pic->nb_slices = 1;
410 
411  return 0;
412 }
413 
415  VAAPIEncodePicture *pic,
416  VAAPIEncodeSlice *slice)
417 {
418  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
419  JPEGRawScanHeader *sh = &priv->scan.header;
420  VAEncSliceParameterBufferJPEG *vslice = slice->codec_slice_params;
421  int i;
422 
423  *vslice = (VAEncSliceParameterBufferJPEG) {
424  .restart_interval = 0,
425  .num_components = sh->Ns,
426  };
427 
428  for (i = 0; i < sh->Ns; i++) {
429  vslice->components[i].component_selector = sh->Cs[i];
430  vslice->components[i].dc_table_selector = sh->Td[i];
431  vslice->components[i].ac_table_selector = sh->Ta[i];
432  }
433 
434  return 0;
435 }
436 
438 {
439  VAAPIEncodeContext *ctx = avctx->priv_data;
440  const AVPixFmtDescriptor *desc;
441 
442  desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
443  av_assert0(desc);
444 
445  ctx->surface_width = FFALIGN(avctx->width, 8 << desc->log2_chroma_w);
446  ctx->surface_height = FFALIGN(avctx->height, 8 << desc->log2_chroma_h);
447 
448  return 0;
449 }
450 
452 {
453  VAAPIEncodeContext *ctx = avctx->priv_data;
454  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
455  int err;
456 
457  priv->quality = ctx->rc_quality;
458  if (priv->quality < 1 || priv->quality > 100) {
459  av_log(avctx, AV_LOG_ERROR, "Invalid quality value %d "
460  "(must be 1-100).\n", priv->quality);
461  return AVERROR(EINVAL);
462  }
463 
464  // Hack: the implementation calls the JPEG image header (which we
465  // will use in the same way as a slice header) generic "raw data".
466  // Therefore, if after the packed header capability check we have
467  // PACKED_HEADER_RAW_DATA available, rewrite it as
468  // PACKED_HEADER_SLICE so that the header-writing code can do the
469  // right thing.
470  if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) {
471  ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA;
472  ctx->va_packed_headers |= VA_ENC_PACKED_HEADER_SLICE;
473  }
474 
475  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MJPEG, avctx);
476  if (err < 0)
477  return err;
478 
479  return 0;
480 }
481 
484  8, 1, 0, 0, VAProfileJPEGBaseline },
486  8, 3, 1, 1, VAProfileJPEGBaseline },
488  8, 3, 1, 0, VAProfileJPEGBaseline },
490  8, 3, 0, 0, VAProfileJPEGBaseline },
492 };
493 
496 
497  .flags = FLAG_CONSTANT_QUALITY_ONLY |
499 
500  .get_encoder_caps = &vaapi_encode_mjpeg_get_encoder_caps,
501  .configure = &vaapi_encode_mjpeg_configure,
502 
503  .default_quality = 80,
504 
505  .picture_params_size = sizeof(VAEncPictureParameterBufferJPEG),
506  .init_picture_params = &vaapi_encode_mjpeg_init_picture_params,
507 
508  .slice_params_size = sizeof(VAEncSliceParameterBufferJPEG),
509  .init_slice_params = &vaapi_encode_mjpeg_init_slice_params,
510 
511  .slice_header_type = VAEncPackedHeaderRawData,
512  .write_slice_header = &vaapi_encode_mjpeg_write_image_header,
513 
514  .write_extra_buffer = &vaapi_encode_mjpeg_write_extra_buffer,
515 };
516 
518 {
519  VAAPIEncodeContext *ctx = avctx->priv_data;
520 
521  ctx->codec = &vaapi_encode_type_mjpeg;
522 
523  // The JPEG image header - see note above.
524  ctx->desired_packed_headers =
525  VA_ENC_PACKED_HEADER_RAW_DATA;
526 
527  return ff_vaapi_encode_init(avctx);
528 }
529 
531 {
532  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
533 
535  ff_cbs_close(&priv->cbc);
536 
537  return ff_vaapi_encode_close(avctx);
538 }
539 
540 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
541 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
544 
545  { "jfif", "Include JFIF header",
546  OFFSET(jfif), AV_OPT_TYPE_BOOL,
547  { .i64 = 0 }, 0, 1, FLAGS },
548  { "huffman", "Include huffman tables",
549  OFFSET(huffman), AV_OPT_TYPE_BOOL,
550  { .i64 = 1 }, 0, 1, FLAGS },
551 
552  { NULL },
553 };
554 
556  { "b", "0" },
557  { NULL },
558 };
559 
561  .class_name = "mjpeg_vaapi",
562  .item_name = av_default_item_name,
563  .option = vaapi_encode_mjpeg_options,
564  .version = LIBAVUTIL_VERSION_INT,
565 };
566 
568  .p.name = "mjpeg_vaapi",
569  CODEC_LONG_NAME("MJPEG (VAAPI)"),
570  .p.type = AVMEDIA_TYPE_VIDEO,
571  .p.id = AV_CODEC_ID_MJPEG,
572  .priv_data_size = sizeof(VAAPIEncodeMJPEGContext),
575  .close = &vaapi_encode_mjpeg_close,
576  .p.priv_class = &vaapi_encode_mjpeg_class,
577  .p.capabilities = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DR1 |
579  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
581  .defaults = vaapi_encode_mjpeg_defaults,
582  .p.pix_fmts = (const enum AVPixelFormat[]) {
585  },
586  .hw_configs = ff_vaapi_encode_hw_configs,
587  .p.wrapper_name = "vaapi",
588 };
VAAPIEncodeSlice::codec_slice_params
void * codec_slice_params
Definition: vaapi_encode.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
jpegtables.h
mjpeg.h
JPEGRawApplicationData::Lp
uint16_t Lp
Definition: cbs_jpeg.h:111
av_clip
#define av_clip
Definition: common.h:98
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
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
vaapi_encode_mjpeg_write_extra_buffer
static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode_mjpeg.c:149
cbs_jpeg.h
VAAPIEncodeMJPEGContext::common
VAAPIEncodeContext common
Definition: vaapi_encode_mjpeg.c:62
vaapi_encode_mjpeg_quant_luminance
static const unsigned char vaapi_encode_mjpeg_quant_luminance[64]
Definition: vaapi_encode_mjpeg.c:40
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:185
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:145
JPEGRawHuffmanTableSpecification::table
JPEGRawHuffmanTable table[8]
Definition: cbs_jpeg.h:107
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:782
VAAPIEncodeMJPEGContext::cbc
CodedBitstreamContext * cbc
Definition: vaapi_encode_mjpeg.c:79
vaapi_encode_mjpeg_options
static const AVOption vaapi_encode_mjpeg_options[]
Definition: vaapi_encode_mjpeg.c:542
JPEGRawFrameHeader::Y
uint16_t Y
Definition: cbs_jpeg.h:56
pixdesc.h
JPEGRawHuffmanTable::L
uint8_t L[16]
Definition: cbs_jpeg.h:101
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:171
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VAAPIEncodeSlice
Definition: vaapi_encode.h:64
JPEG_MARKER_APPN
@ JPEG_MARKER_APPN
Definition: cbs_jpeg.h:40
AVOption
AVOption.
Definition: opt.h:346
data
const char data[16]
Definition: mxf.c:148
vaapi_encode_mjpeg_defaults
static const FFCodecDefault vaapi_encode_mjpeg_defaults[]
Definition: vaapi_encode_mjpeg.c:555
ff_mjpeg_val_dc
const uint8_t ff_mjpeg_val_dc[]
Definition: jpegtabs.h:34
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
ff_vaapi_encode_close
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
Definition: vaapi_encode.c:2965
cbs.h
PICTURE_TYPE_IDR
@ PICTURE_TYPE_IDR
Definition: vaapi_encode.h:58
vaapi_encode_mjpeg_get_encoder_caps
static av_cold int vaapi_encode_mjpeg_get_encoder_caps(AVCodecContext *avctx)
Definition: vaapi_encode_mjpeg.c:437
ff_mjpeg_bits_ac_chrominance
const uint8_t ff_mjpeg_bits_ac_chrominance[]
Definition: jpegtabs.h:66
JPEGRawScanHeader::Ah
uint8_t Ah
Definition: cbs_jpeg.h:76
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:141
JPEG_MARKER_DHT
@ JPEG_MARKER_DHT
Definition: cbs_jpeg.h:34
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
JPEGRawQuantisationTable
Definition: cbs_jpeg.h:87
vaapi_encode.h
fail
#define fail()
Definition: checkasm.h:179
VAAPIEncodePicture
Definition: vaapi_encode.h:73
OFFSET
#define OFFSET(x)
Definition: vaapi_encode_mjpeg.c:540
JPEGRawQuantisationTableSpecification::Lq
uint16_t Lq
Definition: cbs_jpeg.h:94
type
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 type
Definition: writing_filters.txt:86
vaapi_encode_mjpeg_close
static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx)
Definition: vaapi_encode_mjpeg.c:530
JPEGRawQuantisationTableSpecification
Definition: cbs_jpeg.h:93
JPEGRawApplicationData::Ap_ref
AVBufferRef * Ap_ref
Definition: cbs_jpeg.h:113
JPEGRawFrameHeader::Tq
uint8_t Tq[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:63
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
FLAG_INTRA_ONLY
@ FLAG_INTRA_ONLY
Definition: vaapi_encode.h:406
VAAPIEncodeMJPEGContext::huffman_tables
JPEGRawHuffmanTableSpecification huffman_tables
Definition: vaapi_encode_mjpeg.c:77
quant
static const uint8_t quant[64]
Definition: vmixdec.c:71
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
bytestream2_get_bytes_left_p
static av_always_inline int bytestream2_get_bytes_left_p(PutByteContext *p)
Definition: bytestream.h:163
av_cold
#define av_cold
Definition: attributes.h:90
JPEGRawScanHeader::Al
uint8_t Al
Definition: cbs_jpeg.h:77
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
VAAPIEncodeMJPEGContext::current_fragment
CodedBitstreamFragment current_fragment
Definition: vaapi_encode_mjpeg.c:80
AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT
#define AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT
Definition: defs.h:171
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
JPEGRawHuffmanTable::Th
uint8_t Th
Definition: cbs_jpeg.h:100
VAAPIEncodePicture::codec_picture_params
void * codec_picture_params
Definition: vaapi_encode.h:111
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
bytestream2_put_buffer
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_vaapi_encode_receive_packet
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: vaapi_encode.c:1396
JPEGRawQuantisationTableSpecification::table
JPEGRawQuantisationTable table[4]
Definition: cbs_jpeg.h:95
VAAPIEncodeType
Definition: vaapi_encode.h:419
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
VAAPIEncodeContext
Definition: vaapi_encode.h:195
if
if(ret)
Definition: filter_design.txt:179
vaapi_encode_mjpeg_init_slice_params
static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode_mjpeg.c:414
VAAPIEncodeMJPEGContext::frame_header
JPEGRawFrameHeader frame_header
Definition: vaapi_encode_mjpeg.c:73
JPEGRawScanHeader::Ns
uint8_t Ns
Definition: cbs_jpeg.h:68
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
VAAPIEncodeType::profiles
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:422
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
VAAPIEncodeMJPEGContext
Definition: vaapi_encode_mjpeg.c:61
JPEGRawFrameHeader::H
uint8_t H[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:61
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:302
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
JPEGRawHuffmanTable::Tc
uint8_t Tc
Definition: cbs_jpeg.h:99
ff_mjpeg_val_ac_chrominance
const uint8_t ff_mjpeg_val_ac_chrominance[]
Definition: jpegtabs.h:69
JPEGRawFrameHeader::P
uint8_t P
Definition: cbs_jpeg.h:55
index
int index
Definition: gxfenc.c:89
FLAG_CONSTANT_QUALITY_ONLY
@ FLAG_CONSTANT_QUALITY_ONLY
Definition: vaapi_encode.h:404
PutByteContext
Definition: bytestream.h:37
JPEGRawHuffmanTableSpecification
Definition: cbs_jpeg.h:105
vaapi_encode_mjpeg_write_image_header
static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode_mjpeg.c:83
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
VAAPIEncodeMJPEGContext::quant_tables
JPEGRawQuantisationTableSpecification quant_tables
Definition: vaapi_encode_mjpeg.c:76
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
VAAPIEncodePicture::type
int type
Definition: vaapi_encode.h:92
vaapi_encode_mjpeg_class
static const AVClass vaapi_encode_mjpeg_class
Definition: vaapi_encode_mjpeg.c:560
ff_mjpeg_val_ac_luminance
const uint8_t ff_mjpeg_val_ac_luminance[]
Definition: jpegtabs.h:42
vaapi_encode_mjpeg_profiles
static const VAAPIEncodeProfile vaapi_encode_mjpeg_profiles[]
Definition: vaapi_encode_mjpeg.c:482
JPEGRawFrameHeader::X
uint16_t X
Definition: cbs_jpeg.h:57
codec_internal.h
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
JPEGRawScanHeader::Ss
uint8_t Ss
Definition: cbs_jpeg.h:74
ff_mjpeg_bits_ac_luminance
const uint8_t ff_mjpeg_bits_ac_luminance[]
Definition: jpegtabs.h:40
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
vaapi_encode_mjpeg_quant_chrominance
static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64]
Definition: vaapi_encode_mjpeg.c:50
VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:505
VAAPIEncodePicture::recon_surface
VASurfaceID recon_surface
Definition: vaapi_encode.h:101
VAAPIEncodePicture::output_buffer
VABufferID output_buffer
Definition: vaapi_encode.h:108
JPEGRawScanHeader::Cs
uint8_t Cs[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:70
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
JPEGRawScanHeader::Ls
uint16_t Ls
Definition: cbs_jpeg.h:67
JPEGRawScanHeader::Td
uint8_t Td[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:71
VAAPIEncodeMJPEGContext::jfif
int jfif
Definition: vaapi_encode_mjpeg.c:65
ff_mjpeg_vaapi_encoder
const FFCodec ff_mjpeg_vaapi_encoder
Definition: vaapi_encode_mjpeg.c:567
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
JPEGRawScan::header
JPEGRawScanHeader header
Definition: cbs_jpeg.h:81
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
VAAPIEncodeMJPEGContext::huffman
int huffman
Definition: vaapi_encode_mjpeg.c:66
internal.h
VAAPIEncodeContext::input_frames
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:275
common.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
len
int len
Definition: vorbis_enc_data.h:426
AVCodecContext::height
int height
Definition: avcodec.h:618
VAAPIEncodeMJPEGContext::quality
int quality
Definition: vaapi_encode_mjpeg.c:69
ff_cbs_write_fragment_data
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:408
VAAPIEncodeMJPEGContext::jfif_data
uint8_t jfif_data[14]
Definition: vaapi_encode_mjpeg.c:70
JPEGRawFrameHeader::Nf
uint16_t Nf
Definition: cbs_jpeg.h:58
avcodec.h
JPEGRawApplicationData
Definition: cbs_jpeg.h:110
ff_vaapi_encode_hw_configs
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:35
ff_vaapi_encode_init
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
Definition: vaapi_encode.c:2756
JPEGRawScan
Definition: cbs_jpeg.h:80
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
dht
static int FUNC() dht(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawHuffmanTableSpecification *current)
Definition: cbs_jpeg_syntax_template.c:102
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:482
JPEGRawFrameHeader::C
uint8_t C[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:60
AVCodecContext
main external API structure.
Definition: avcodec.h:445
JPEGRawHuffmanTable::V
uint8_t V[256]
Definition: cbs_jpeg.h:102
vaapi_encode_mjpeg_init_picture_params
static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode_mjpeg.c:222
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
JPEG_MARKER_SOF0
@ JPEG_MARKER_SOF0
Definition: cbs_jpeg.h:29
FLAGS
#define FLAGS
Definition: vaapi_encode_mjpeg.c:541
values
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 values
Definition: filter_design.txt:263
JPEGRawFrameHeader::V
uint8_t V[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:62
dqt
static int FUNC() dqt(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawQuantisationTableSpecification *current)
Definition: cbs_jpeg_syntax_template.c:62
ff_mjpeg_bits_dc_chrominance
const uint8_t ff_mjpeg_bits_dc_chrominance[]
Definition: jpegtabs.h:37
JPEGRawHuffmanTableSpecification::Lh
uint16_t Lh
Definition: cbs_jpeg.h:106
desc
const char * desc
Definition: libsvtav1.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
VAAPIEncodePicture::input_image
AVFrame * input_image
Definition: vaapi_encode.h:97
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_cbs_init
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:89
JPEGRawFrameHeader
Definition: cbs_jpeg.h:53
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ff_mjpeg_bits_dc_luminance
const FF_VISIBILITY_PUSH_HIDDEN uint8_t ff_mjpeg_bits_dc_luminance[]
Definition: jpegtabs.h:32
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
JPEG_MARKER_DQT
@ JPEG_MARKER_DQT
Definition: cbs_jpeg.h:38
JPEGRawFrameHeader::Lf
uint16_t Lf
Definition: cbs_jpeg.h:54
JPEG_MARKER_SOS
@ JPEG_MARKER_SOS
Definition: cbs_jpeg.h:37
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
bytestream.h
JPEGRawHuffmanTable
Definition: cbs_jpeg.h:98
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
vaapi_encode_mjpeg_configure
static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
Definition: vaapi_encode_mjpeg.c:451
JPEGRawApplicationData::Ap
uint8_t * Ap
Definition: cbs_jpeg.h:112
JPEGRawScanHeader::Ta
uint8_t Ta[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:72
put_bits.h
JPEGRawScanHeader::Se
uint8_t Se
Definition: cbs_jpeg.h:75
JPEGRawScanHeader
Definition: cbs_jpeg.h:66
VAAPIEncodeMJPEGContext::jfif_header
JPEGRawApplicationData jfif_header
Definition: vaapi_encode_mjpeg.c:75
vaapi_encode_mjpeg_init
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
Definition: vaapi_encode_mjpeg.c:517
VAAPIEncodeProfile
Definition: vaapi_encode.h:150
vaapi_encode_type_mjpeg
static const VAAPIEncodeType vaapi_encode_type_mjpeg
Definition: vaapi_encode_mjpeg.c:494
VAAPIEncodePicture::nb_slices
int nb_slices
Definition: vaapi_encode.h:135
VAAPIEncodeMJPEGContext::scan
JPEGRawScan scan
Definition: vaapi_encode_mjpeg.c:74