33#include "config_components.h"
72 uint8_t *uni_ac_vlc_len)
74 for (
int i = 0;
i < 128;
i++) {
82 len = (
run >> 4) * huff_size_ac[0xf0];
87 len += huff_size_ac[
code] + nbits;
98 s->c.intra_scantable.permutated, 0,
99 s->c.intra_matrix,
s->c.chroma_intra_matrix,
100 s->c.slice_context_count > 1);
103 for (
int i = 1;
i <
s->c.slice_context_count;
i++)
104 s->c.enc_contexts[
i]->esc_pos = 0;
119#if CONFIG_MJPEG_ENCODER
128 int nbits,
code, table_id;
138 size_t total_bits = 0;
148 total_bits += huff_size[table_id][
code] + nbits;
151 bytes_needed = (total_bits + 7) / 8;
186 &ac_chrominance_ctx };
187 for (
int i = 0;
i < 4;
i++)
242 int mb_y =
s->c.mb_y - !
s->c.mb_x;
245#if CONFIG_MJPEG_ENCODER
251 mjpeg_build_optimal_huffman(m);
257 s->intra_ac_vlc_length =
259 s->intra_chroma_ac_vlc_length =
263 mjpeg_encode_picture_frame(
main);
276 if (
s->c.slice_context_count > 1 && mb_y < s->
c.mb_height - 1)
281 for (
int i = 0;
i < 3;
i++)
291 static const char blocks_per_mb[] = {
297 num_blocks =
s->c.mb_num * blocks_per_mb[
s->c.chroma_format];
324 c->table_id = table_id;
352 s->huff_buffer[
s->huff_ncode].mant = mant;
367 int component, dc, last_index,
val,
run;
371 component = (n <= 3 ? 0 : (n&1) + 1);
372 table_id = (n <= 3 ? 0 : 1);
374 val = dc -
s->last_dc[component];
378 s->last_dc[component] = dc;
383 last_index =
s->c.block_last_index[n];
386 for(
i=1;
i<=last_index;
i++) {
387 j =
s->c.intra_scantable.permutated[
i];
403 if (last_index < 63 ||
run != 0)
409 int mant, nbits,
code,
i, j;
410 int component, dc,
run, last_index,
val;
412 const uint16_t *huff_code_ac;
413 const uint8_t *huff_size_ac;
416 component = (n <= 3 ? 0 : (n&1) + 1);
418 val = dc -
s->last_dc[component];
428 s->last_dc[component] = dc;
433 last_index =
s->c.block_last_index[n];
434 for(
i=1;
i<=last_index;
i++) {
435 j =
s->c.intra_scantable.permutated[
i];
441 put_bits(&
s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
461 if (last_index < 63 ||
run != 0)
462 put_bits(&
s->pb, huff_size_ac[0], huff_code_ac[0]);
466 int unused_x,
int unused_y)
476 if (16*
s->c.mb_x+8 <
s->c.width) {
485 for (
int i = 0;
i < 5;
i++)
498 int unused_x,
int unused_y)
508 if (16 *
s->c.mb_x + 8 <
s->c.width) {
517 for (
int i = 0;
i < 5;
i++)
546 "QP RD is no longer compatible with MJPEG or AMV\n");
556 if (avctx->
width > 65500 || avctx->
height > 65500) {
584 s->min_qcoeff = -1023;
585 s->max_qcoeff = 1023;
587 s->intra_ac_vlc_length =
589 s->intra_chroma_ac_vlc_length =
599 if (
s->c.slice_context_count > 1)
611#if CONFIG_AMV_ENCODER
615 const AVFrame *pic_arg,
int *got_packet)
620 int chroma_v_shift = 1;
624 "Heights which are not a multiple of 16 might fail with some decoders, "
625 "use vstrict=-1 / -strict -1 to use %d anyway.\n", avctx->
height);
626 av_log(avctx,
AV_LOG_WARNING,
"If you have a device that plays AMV videos, please test if videos "
627 "with such heights work with it and report your findings to ffmpeg-devel@ffmpeg.org\n");
635 for(
i=0;
i < 3;
i++) {
636 int vsample =
i ? 2 >> chroma_v_shift : 2;
637 pic->
data[
i] += pic->
linesize[
i] * (vsample *
s->c.height / V_MAX - 1);
646#define OFFSET(x) offsetof(MJPEGEncContext, mjpeg.x)
647#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
649#define AMV_OPTIONS_OFFSET 4
653{
"force_duplicated_matrix",
"Always write luma and chroma matrix for mjpeg, useful for rtp streaming.",
OFFSET(force_duplicated_matrix),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1,
VE },
658#if CONFIG_MJPEG_ENCODER
659static const AVClass mjpeg_class = {
660 .class_name =
"mjpeg encoder",
701 .p.priv_class = &mjpeg_class,
703 .get_supported_config = mjpeg_get_supported_config,
707#if CONFIG_AMV_ENCODER
708static const AVClass amv_class = {
709 .class_name =
"amv encoder",
728 .p.priv_class = &amv_class,
static double val(void *priv, double ch)
const FFCodec ff_amv_encoder
const FFCodec ff_mjpeg_encoder
static AVFormatContext * ctx
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_default_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out_configs, int *out_num_configs)
Libavcodec external API header.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
#define FF_CODEC_ENCODE_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...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AV_CODEC_CONFIG_COLOR_RANGE
AVColorRange, terminated by AVCOL_RANGE_UNSPECIFIED.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
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[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
MJPEG encoder and decoder.
static void record_block(MPVEncContext *const s, int16_t block[], int n)
Add the block's data into the JPEG buffer.
static int mjpeg_amv_encode_picture_header(MPVMainEncContext *const m)
static av_cold int mjpeg_encode_init(AVCodecContext *avctx)
static void mjpeg_record_mb(MPVEncContext *const s, int16_t block[][64], int unused_x, int unused_y)
static void mjpeg_encode_coef(MJpegContext *s, uint8_t table_id, int val, int run)
Add the coefficient's data to the JPEG buffer.
int ff_mjpeg_encode_stuffing(MPVEncContext *const s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
#define AMV_OPTIONS_OFFSET
static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len)
static av_cold int mjpeg_encode_close(AVCodecContext *avctx)
static void mjpeg_encode_mb(MPVEncContext *const s, int16_t block[][64], int unused_x, int unused_y)
static void mjpeg_encode_picture_header(MPVEncContext *const s)
static void encode_block(MPVEncContext *const s, int16_t block[], int n)
static int alloc_huffman(MJPEGEncContext *const m2)
static void mjpeg_encode_code(MJpegContext *s, uint8_t table_id, int code)
Add code and table_id to the JPEG buffer.
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
@ NB_HUFFMAN_TABLE_OPTION
@ HUFFMAN_TABLE_DEFAULT
Use the default Huffman tables.
static void put_marker(PutBitContext *p, enum JpegMarker code)
void ff_mjpeg_encode_dc(PutBitContext *pb, int val, const uint8_t huff_size[], const uint16_t huff_code[])
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, const AVFrame *frame, const struct MJpegContext *m, const uint8_t intra_matrix_permutation[64], int pred, const uint16_t luma_intra_matrix[64], const uint16_t chroma_intra_matrix[64], int use_slices)
int ff_mjpeg_encode_check_pix_fmt(AVCodecContext *avctx)
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, const uint8_t *bits_table, const uint8_t *val_table)
void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17], uint8_t val[], int max_nval)
Produces a Huffman encoding with a given input.
Huffman table generation for MJPEG encoder.
static void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s, uint8_t val)
int ff_mpv_reallocate_putbitbuffer(MPVEncContext *const s, size_t threshold, size_t size_increase)
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
static int get_bits_diff(MPVEncContext *s)
#define FF_MPV_FLAG_QP_RD
#define UNI_AC_ENC_INDEX(run, level)
#define FF_MPV_COMMON_OPTS
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
const AVProfile ff_mjpeg_profiles[]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static int put_bits_count(PutBitContext *s)
static int put_bytes_count(const PutBitContext *s, int round_up)
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
main external API structure.
int width
picture width / height.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
Holds JPEG frame data and Huffman table data.
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
struct MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
size_t huff_ncode
Number of current entries in the buffer.
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC.
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC.
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Buffer of JPEG frame data.
uint16_t mant
The mantissa.
uint8_t table_id
The Huffman table id associated with the data.
uint8_t code
The exponent.
MPVEncContext s
The main slicecontext.
int(* encode_picture_header)(struct MPVMainEncContext *m)
#define av_malloc_array(a, b)