20#include <va/va_enc_jpeg.h>
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,
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,
86 char *
data,
size_t *data_len)
93 err = ff_cbs_insert_unit_content(frag, -1,
100 err = ff_cbs_insert_unit_content(frag, -1,
106 err = ff_cbs_insert_unit_content(frag, -1,
113 err = ff_cbs_insert_unit_content(frag, -1,
120 err = ff_cbs_insert_unit_content(frag, -1,
126 err = ff_cbs_write_fragment_data(priv->
cbc, frag);
132 if (*data_len < 8 * frag->data_size) {
134 "%zu < %zu.\n", *data_len, 8 * frag->
data_size);
145 ff_cbs_fragment_reset(frag);
152 char *
data,
size_t *data_len)
161 VAQMatrixBufferJPEG *
quant;
163 if (*data_len <
sizeof(*
quant))
165 *
type = VAQMatrixBufferType;
166 *data_len =
sizeof(*quant);
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];
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];
182 }
else if (
index == 1) {
186 VAHuffmanTableBufferJPEGBaseline *huff;
188 if (*data_len <
sizeof(*huff))
190 *
type = VAHuffmanTableBufferType;
191 *data_len =
sizeof(*huff);
193 huff = (VAHuffmanTableBufferJPEGBaseline*)
data;
194 memset(huff, 0,
sizeof(*huff));
196 for (t = 0; t < 1 + (sh->
Ns > 1); t++) {
199 huff->load_huffman_table[t] = 1;
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];
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];
232 const uint8_t components_rgb[3] = {
'R',
'G',
'B' };
233 const uint8_t components_yuv[3] = { 1, 2, 3 };
234 const uint8_t *components;
235 int t,
i, quant_scale,
len;
242 components = components_rgb;
244 components = components_yuv;
251 fh->
Nf =
desc->nb_components;
253 for (
i = 0;
i < fh->
Nf;
i++) {
254 fh->
C[
i] = components[
i];
255 fh->
H[
i] = 1 + (
i == 0 ?
desc->log2_chroma_w : 0);
256 fh->
V[
i] = 1 + (
i == 0 ?
desc->log2_chroma_h : 0);
261 fh->
Lf = 8 + 3 * fh->
Nf;
274 bytestream2_put_be16(&pbc, 0x0102);
275 bytestream2_put_byte(&pbc, 0);
278 if (sar_w && sar_h) {
279 bytestream2_put_be16(&pbc, sar_w);
280 bytestream2_put_be16(&pbc, sar_h);
282 bytestream2_put_be16(&pbc, 1);
283 bytestream2_put_be16(&pbc, 1);
286 bytestream2_put_byte(&pbc, 0);
287 bytestream2_put_byte(&pbc, 0);
299 quant_scale = 5000 / priv->
quality;
301 quant_scale = 200 - 2 * priv->
quality;
305 for (t = 0; t < 1 + (fh->
Nf > 1); t++) {
307 const uint8_t *
data = t == 0 ?
313 for (
i = 0;
i < 64;
i++)
325 for (t = 0; t < 2 + 2 * (fh->
Nf > 1); t++) {
327 const uint8_t *lengths, *values;
352 for (
i = k = 0;
i < 16;
i++)
353 k += (huff->
L[
i] = lengths[
i]);
355 for (
i = 0;
i < k;
i++)
356 huff->
V[
i] = values[
i];
367 for (
i = 0;
i < fh->
Nf;
i++) {
368 sh->
Cs[
i] = fh->
C[
i];
378 sh->
Ls = 6 + 2 * sh->
Ns;
381 *vpic = (VAEncPictureParameterBufferJPEG) {
385 .picture_width = fh->
X,
386 .picture_height = fh->
Y,
396 .sample_bit_depth = fh->
P,
398 .num_components = fh->
Nf,
406 for (
i = 0;
i < fh->
Nf;
i++) {
407 vpic->component_id[
i] = fh->
C[
i];
408 vpic->quantiser_table_selector[
i] = fh->
Tq[
i];
425 *vslice = (VAEncSliceParameterBufferJPEG) {
426 .restart_interval = 0,
427 .num_components = sh->
Ns,
430 for (
i = 0;
i < sh->
Ns;
i++) {
431 vslice->components[
i].component_selector = sh->
Cs[
i];
432 vslice->components[
i].dc_table_selector = sh->
Td[
i];
433 vslice->components[
i].ac_table_selector = sh->
Ta[
i];
462 "(must be 1-100).\n", priv->
quality);
472 if (
ctx->va_packed_headers & VA_ENC_PACKED_HEADER_RAW_DATA) {
473 ctx->va_packed_headers &= ~VA_ENC_PACKED_HEADER_RAW_DATA;
474 ctx->va_packed_headers |= VA_ENC_PACKED_HEADER_SLICE;
486 8, 1, 0, 0, VAProfileJPEGBaseline },
488 8, 3, 1, 1, VAProfileJPEGBaseline },
490 8, 3, 1, 0, VAProfileJPEGBaseline },
492 8, 3, 0, 0, VAProfileJPEGBaseline },
505 .default_quality = 80,
507 .picture_params_size =
sizeof(VAEncPictureParameterBufferJPEG),
510 .slice_params_size =
sizeof(VAEncSliceParameterBufferJPEG),
513 .slice_header_type = VAEncPackedHeaderRawData,
526 ctx->desired_packed_headers =
527 VA_ENC_PACKED_HEADER_RAW_DATA;
537 ff_cbs_close(&priv->
cbc);
542#define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
543#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
548 {
"jfif",
"Include JFIF header",
550 { .i64 = 0 }, 0, 1,
FLAGS },
551 {
"huffman",
"Include huffman tables",
553 { .i64 = 1 }, 0, 1,
FLAGS },
564 .class_name =
"mjpeg_vaapi",
571 .p.name =
"mjpeg_vaapi",
588 .p.wrapper_name =
"vaapi",
const FFCodec ff_mjpeg_vaapi_encoder
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_get_bytes_left_p(const PutByteContext *p)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
static int FUNC dht(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawHuffmanTableSpecification *current)
static int FUNC dqt(CodedBitstreamContext *ctx, RWContext *rw, JPEGRawQuantisationTableSpecification *current)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define LIBAVUTIL_VERSION_INT
#define HW_BASE_ENCODE_COMMON_OPTIONS
@ FF_HW_FLAG_CONSTANT_QUALITY_ONLY
FF_VISIBILITY_PUSH_HIDDEN const uint8_t ff_mjpeg_bits_dc_luminance[]
const uint8_t ff_mjpeg_val_ac_chrominance[]
const uint8_t ff_mjpeg_bits_ac_luminance[]
const uint8_t ff_mjpeg_bits_dc_chrominance[]
const uint8_t ff_mjpeg_bits_ac_chrominance[]
const uint8_t ff_mjpeg_val_dc[]
const uint8_t ff_mjpeg_val_ac_luminance[]
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
common internal API header
MJPEG encoder and decoder.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Describe the class of an AVClass context structure.
main external API structure.
int width
picture width / height.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
size_t data_size
The number of bytes in the bitstream.
uint8_t * data
Pointer to the bitstream form of this fragment.
AVHWFramesContext * input_frames
JPEGRawHuffmanTable table[8]
JPEGRawQuantisationTable table[4]
JPEGRawApplicationData jfif_header
CodedBitstreamFragment current_fragment
CodedBitstreamContext * cbc
JPEGRawFrameHeader frame_header
JPEGRawQuantisationTableSpecification quant_tables
VAAPIEncodeContext common
JPEGRawHuffmanTableSpecification huffman_tables
void * codec_picture_params
VASurfaceID recon_surface
void * codec_slice_params
static AVFormatContext * ctx
#define VAAPI_ENCODE_COMMON_OPTIONS
static const FFCodecDefault vaapi_encode_mjpeg_defaults[]
static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *base, VAAPIEncodeSlice *slice)
static av_cold int vaapi_encode_mjpeg_get_encoder_caps(AVCodecContext *avctx)
static const AVClass vaapi_encode_mjpeg_class
static const VAAPIEncodeType vaapi_encode_type_mjpeg
static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx)
static const unsigned char vaapi_encode_mjpeg_quant_chrominance[64]
static const VAAPIEncodeProfile vaapi_encode_mjpeg_profiles[]
static const unsigned char vaapi_encode_mjpeg_quant_luminance[64]
static const AVOption vaapi_encode_mjpeg_options[]
static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx)
static int vaapi_encode_mjpeg_write_image_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
static int vaapi_encode_mjpeg_write_extra_buffer(AVCodecContext *avctx, FFHWBaseEncodePicture *base, int index, int *type, char *data, size_t *data_len)
static const uint8_t quant[64]