FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "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;
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(priv->cbc, 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(priv->cbc, frag, -1,
102  &priv->quant_tables, NULL);
103  if (err < 0)
104  goto fail;
105 
106  err = ff_cbs_insert_unit_content(priv->cbc, 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(priv->cbc, frag, -1,
115  &priv->huffman_tables, NULL);
116  if (err < 0)
117  goto fail;
118  }
119 
120  err = ff_cbs_insert_unit_content(priv->cbc, 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_uninit(priv->cbc, 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;
231  int t, i, quant_scale, len;
232 
234  av_assert0(desc);
235  if (desc->flags & AV_PIX_FMT_FLAG_RGB)
236  components = (uint8_t[3]) { 'R', 'G', 'B' };
237  else
238  components = (uint8_t[3]) { 1, 2, 3 };
239 
240  // Frame header.
241 
242  fh->P = 8;
243  fh->Y = avctx->height;
244  fh->X = avctx->width;
245  fh->Nf = desc->nb_components;
246 
247  for (i = 0; i < fh->Nf; i++) {
248  fh->C[i] = components[i];
249  fh->H[i] = 1 + (i == 0 ? desc->log2_chroma_w : 0);
250  fh->V[i] = 1 + (i == 0 ? desc->log2_chroma_h : 0);
251 
252  fh->Tq[i] = !!i;
253  }
254 
255  fh->Lf = 8 + 3 * fh->Nf;
256 
257  // JFIF header.
258  if (priv->jfif) {
259  JPEGRawApplicationData *app = &priv->jfif_header;
261  int sar_w, sar_h;
262  PutByteContext pbc;
263 
265  sizeof(priv->jfif_data));
266 
267  bytestream2_put_buffer(&pbc, "JFIF", 5);
268  bytestream2_put_be16(&pbc, 0x0102);
269  bytestream2_put_byte(&pbc, 0);
270 
271  av_reduce(&sar_w, &sar_h, sar.num, sar.den, 65535);
272  if (sar_w && sar_h) {
273  bytestream2_put_be16(&pbc, sar_w);
274  bytestream2_put_be16(&pbc, sar_h);
275  } else {
276  bytestream2_put_be16(&pbc, 1);
277  bytestream2_put_be16(&pbc, 1);
278  }
279 
280  bytestream2_put_byte(&pbc, 0);
281  bytestream2_put_byte(&pbc, 0);
282 
284 
285  app->Lp = 2 + sizeof(priv->jfif_data);
286  app->Ap = priv->jfif_data;
287  app->Ap_ref = NULL;
288  }
289 
290  // Quantisation tables.
291 
292  if (priv->quality < 50)
293  quant_scale = 5000 / priv->quality;
294  else
295  quant_scale = 200 - 2 * priv->quality;
296 
297  len = 2;
298 
299  for (t = 0; t < 1 + (fh->Nf > 1); t++) {
301  const uint8_t *data = t == 0 ?
304 
305  quant->Pq = 0;
306  quant->Tq = t;
307  for (i = 0; i < 64; i++)
308  quant->Q[i] = av_clip(data[i] * quant_scale / 100, 1, 255);
309 
310  len += 65;
311  }
312 
313  priv->quant_tables.Lq = len;
314 
315  // Huffman tables.
316 
317  len = 2;
318 
319  for (t = 0; t < 2 + 2 * (fh->Nf > 1); t++) {
320  JPEGRawHuffmanTable *huff = &priv->huffman_tables.table[t];
321  const uint8_t *lengths, *values;
322  int k;
323 
324  switch (t) {
325  case 0:
326  lengths = avpriv_mjpeg_bits_dc_luminance + 1;
327  values = avpriv_mjpeg_val_dc;
328  break;
329  case 1:
330  lengths = avpriv_mjpeg_bits_ac_luminance + 1;
332  break;
333  case 2:
334  lengths = avpriv_mjpeg_bits_dc_chrominance + 1;
335  values = avpriv_mjpeg_val_dc;
336  break;
337  case 3:
338  lengths = avpriv_mjpeg_bits_ac_chrominance + 1;
340  break;
341  }
342 
343  huff->Tc = t % 2;
344  huff->Th = t / 2;
345 
346  for (i = k = 0; i < 16; i++)
347  k += (huff->L[i] = lengths[i]);
348 
349  for (i = 0; i < k; i++)
350  huff->V[i] = values[i];
351 
352  len += 17 + k;
353  }
354 
355  priv->huffman_tables.Lh = len;
356 
357  // Scan header.
358 
359  sh->Ns = fh->Nf;
360 
361  for (i = 0; i < fh->Nf; i++) {
362  sh->Cs[i] = fh->C[i];
363  sh->Td[i] = i > 0;
364  sh->Ta[i] = i > 0;
365  }
366 
367  sh->Ss = 0;
368  sh->Se = 63;
369  sh->Ah = 0;
370  sh->Al = 0;
371 
372  sh->Ls = 6 + 2 * sh->Ns;
373 
374 
375  *vpic = (VAEncPictureParameterBufferJPEG) {
376  .reconstructed_picture = pic->recon_surface,
377  .coded_buf = pic->output_buffer,
378 
379  .picture_width = fh->X,
380  .picture_height = fh->Y,
381 
382  .pic_flags.bits = {
383  .profile = 0,
384  .progressive = 0,
385  .huffman = 1,
386  .interleaved = 0,
387  .differential = 0,
388  },
389 
390  .sample_bit_depth = fh->P,
391  .num_scan = 1,
392  .num_components = fh->Nf,
393 
394  // The driver modifies the provided quantisation tables according
395  // to this quality value; the middle value of 50 makes that the
396  // identity so that they are used unchanged.
397  .quality = 50,
398  };
399 
400  for (i = 0; i < fh->Nf; i++) {
401  vpic->component_id[i] = fh->C[i];
402  vpic->quantiser_table_selector[i] = fh->Tq[i];
403  }
404 
405  pic->nb_slices = 1;
406 
407  return 0;
408 }
409 
411  VAAPIEncodePicture *pic,
412  VAAPIEncodeSlice *slice)
413 {
414  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
415  JPEGRawScanHeader *sh = &priv->scan.header;
416  VAEncSliceParameterBufferJPEG *vslice = slice->codec_slice_params;
417  int i;
418 
419  *vslice = (VAEncSliceParameterBufferJPEG) {
420  .restart_interval = 0,
421  .num_components = sh->Ns,
422  };
423 
424  for (i = 0; i < sh->Ns; i++) {
425  vslice->components[i].component_selector = sh->Cs[i];
426  vslice->components[i].dc_table_selector = sh->Td[i];
427  vslice->components[i].ac_table_selector = sh->Ta[i];
428  }
429 
430  return 0;
431 }
432 
434 {
435  VAAPIEncodeContext *ctx = avctx->priv_data;
436  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
437  int err;
438 
439  priv->quality = avctx->global_quality;
440  if (priv->quality < 1 || priv->quality > 100) {
441  av_log(avctx, AV_LOG_ERROR, "Invalid quality value %d "
442  "(must be 1-100).\n", priv->quality);
443  return AVERROR(EINVAL);
444  }
445 
446  // Hack: the implementation calls the JPEG image header (which we
447  // will use in the same way as a slice header) generic "raw data".
448  // Therefore, if after the packed header capability check we have
449  // PACKED_HEADER_RAW_DATA available, rewrite it as
450  // PACKED_HEADER_SLICE so that the header-writing code can do the
451  // right thing.
452  if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) {
453  ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA;
454  ctx->va_packed_headers |= VA_ENC_PACKED_HEADER_SLICE;
455  }
456 
457  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MJPEG, avctx);
458  if (err < 0)
459  return err;
460 
461  return 0;
462 }
463 
466  8, 1, 0, 0, VAProfileJPEGBaseline },
468  8, 3, 1, 1, VAProfileJPEGBaseline },
470  8, 3, 1, 0, VAProfileJPEGBaseline },
472  8, 3, 0, 0, VAProfileJPEGBaseline },
474 };
475 
478 
480 
481  .configure = &vaapi_encode_mjpeg_configure,
482 
483  .picture_params_size = sizeof(VAEncPictureParameterBufferJPEG),
484  .init_picture_params = &vaapi_encode_mjpeg_init_picture_params,
485 
486  .slice_params_size = sizeof(VAEncSliceParameterBufferJPEG),
487  .init_slice_params = &vaapi_encode_mjpeg_init_slice_params,
488 
489  .slice_header_type = VAEncPackedHeaderRawData,
490  .write_slice_header = &vaapi_encode_mjpeg_write_image_header,
491 
492  .write_extra_buffer = &vaapi_encode_mjpeg_write_extra_buffer,
493 };
494 
496 {
497  VAAPIEncodeContext *ctx = avctx->priv_data;
498 
500 
501  // The JPEG image header - see note above.
503  VA_ENC_PACKED_HEADER_RAW_DATA;
504 
505  ctx->surface_width = FFALIGN(avctx->width, 8);
506  ctx->surface_height = FFALIGN(avctx->height, 8);
507 
508  return ff_vaapi_encode_init(avctx);
509 }
510 
512 {
513  VAAPIEncodeMJPEGContext *priv = avctx->priv_data;
514 
515  ff_cbs_close(&priv->cbc);
516 
517  return ff_vaapi_encode_close(avctx);
518 }
519 
520 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
521 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
524 
525  { "jfif", "Include JFIF header",
526  OFFSET(jfif), AV_OPT_TYPE_BOOL,
527  { .i64 = 0 }, 0, 1, FLAGS },
528  { "huffman", "Include huffman tables",
529  OFFSET(huffman), AV_OPT_TYPE_BOOL,
530  { .i64 = 1 }, 0, 1, FLAGS },
531 
532  { NULL },
533 };
534 
536  { "global_quality", "80" },
537  { "b", "0" },
538  { "g", "1" },
539  { NULL },
540 };
541 
543  .class_name = "mjpeg_vaapi",
544  .item_name = av_default_item_name,
545  .option = vaapi_encode_mjpeg_options,
546  .version = LIBAVUTIL_VERSION_INT,
547 };
548 
550  .name = "mjpeg_vaapi",
551  .long_name = NULL_IF_CONFIG_SMALL("MJPEG (VAAPI)"),
552  .type = AVMEDIA_TYPE_VIDEO,
553  .id = AV_CODEC_ID_MJPEG,
554  .priv_data_size = sizeof(VAAPIEncodeMJPEGContext),
556  .encode2 = &ff_vaapi_encode2,
557  .close = &vaapi_encode_mjpeg_close,
558  .priv_class = &vaapi_encode_mjpeg_class,
559  .capabilities = AV_CODEC_CAP_HARDWARE |
561  .defaults = vaapi_encode_mjpeg_defaults,
562  .pix_fmts = (const enum AVPixelFormat[]) {
565  },
566  .wrapper_name = "vaapi",
567 };
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static int FUNC() dqt(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawQuantisationTableSpecification *current)
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * desc
Definition: nvenc.c:65
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: avcodec.h:1065
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:74
int num
Numerator.
Definition: rational.h:59
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
CodedBitstreamFragment current_fragment
JPEGRawApplicationData jfif_header
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:570
AVCodec.
Definition: avcodec.h:3424
JPEGRawQuantisationTableSpecification quant_tables
MJPEG encoder and decoder.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64]
uint8_t Td[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:71
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:1054
#define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT
Definition: avcodec.h:2956
unsigned int va_packed_headers
Definition: vaapi_encode.h:151
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:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t
#define av_cold
Definition: attributes.h:82
uint8_t V[224]
Definition: cbs_jpeg.h:102
AVOptions.
const uint8_t avpriv_mjpeg_bits_dc_luminance[17]
Definition: jpegtables.c:65
VAAPIEncodeContext common
#define AVERROR_EOF
End of file.
Definition: error.h:55
static int FUNC() dht(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawHuffmanTableSpecification *current)
VASurfaceID recon_surface
Definition: vaapi_encode.h:79
AVBufferRef * Ap_ref
Definition: cbs_jpeg.h:113
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
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:129
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:166
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t L[16]
Definition: cbs_jpeg.h:101
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
Definition: bytestream.h:159
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:139
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
const uint8_t avpriv_mjpeg_bits_dc_chrominance[17]
Definition: jpegtables.c:70
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
JPEGRawScanHeader header
Definition: cbs_jpeg.h:81
CodedBitstreamContext * cbc
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3431
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
void * codec_picture_params
Definition: vaapi_encode.h:88
#define fail()
Definition: checkasm.h:117
static const unsigned char vaapi_encode_mjpeg_quant_luminance[64]
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
AVCodec ff_mjpeg_vaapi_encoder
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
uint8_t V[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:62
uint8_t Cs[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:70
static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
int width
picture width / height.
Definition: avcodec.h:1706
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2860
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:261
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
AVFormatContext * ctx
Definition: movenc.c:48
AVFrame * input_image
Definition: vaapi_encode.h:75
static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
JPEGRawHuffmanTableSpecification huffman_tables
uint8_t C[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:60
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:282
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:282
static const AVCodecDefault vaapi_encode_mjpeg_defaults[]
static const AVClass vaapi_encode_mjpeg_class
static const VAAPIEncodeProfile vaapi_encode_mjpeg_profiles[]
#define OFFSET(x)
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:116
Libavcodec external API header.
JPEGRawQuantisationTable table[4]
Definition: cbs_jpeg.h:95
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:1533
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:314
uint8_t H[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:61
GLint GLenum type
Definition: opengl_enc.c:105
const uint8_t avpriv_mjpeg_val_dc[12]
Definition: jpegtables.c:67
static const AVOption vaapi_encode_mjpeg_options[]
static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx)
Describe the class of an AVClass context structure.
Definition: log.h:67
Context structure for coded bitstream operations.
Definition: cbs.h:159
int index
Definition: gxfenc.c:89
Rational number (pair of numerator and denominator).
Definition: rational.h:58
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:113
const uint8_t avpriv_mjpeg_bits_ac_chrominance[17]
Definition: jpegtables.c:99
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
const uint8_t * quant
const uint8_t avpriv_mjpeg_val_ac_chrominance[]
Definition: jpegtables.c:102
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1599
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:330
JPEGRawFrameHeader frame_header
static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
common internal api header.
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
uint16_t Ls
Definition: cbs_jpeg.h:67
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:895
int den
Denominator.
Definition: rational.h:60
const uint8_t avpriv_mjpeg_bits_ac_luminance[17]
Definition: jpegtables.c:73
void * priv_data
Definition: avcodec.h:1560
int len
const uint8_t avpriv_mjpeg_val_ac_luminance[]
Definition: jpegtables.c:75
#define FLAGS
void * codec_slice_params
Definition: vaapi_encode.h:60
uint8_t Ta[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:72
unsigned int desired_packed_headers
Definition: vaapi_encode.h:124
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
uint8_t Tq[JPEG_MAX_COMPONENTS]
Definition: cbs_jpeg.h:63
JPEGRawHuffmanTable table[8]
Definition: cbs_jpeg.h:107
VABufferID output_buffer
Definition: vaapi_encode.h:85
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
for(j=16;j >0;--j)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
static const VAAPIEncodeType vaapi_encode_type_mjpeg
bitstream writer API