Go to the documentation of this file.
37 #define SSIZE_ROUND(b) (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes)
40 #define SLICE_REDIST_TOTAL 150
98 typedef struct Plane {
200 for (
unsigned i = 2;
i < 256; ++
i) {
238 uint32_t cur_pos, dist;
251 dist = cur_pos -
s->next_parse_offset;
252 AV_WB32(
s->pb.buf +
s->next_parse_offset + 5, dist);
253 s->next_parse_offset = cur_pos;
259 s->last_parse_code = pcode;
280 if (!
s->strict_compliance) {
291 if (!
s->strict_compliance) {
293 if (
s->chroma_x_shift == 1 &&
s->chroma_y_shift == 0)
295 else if (
s->chroma_x_shift == 1 &&
s->chroma_y_shift == 1)
307 if (!
s->strict_compliance)
315 if (!
s->strict_compliance) {
327 if (!
s->strict_compliance) {
345 if (!
s->strict_compliance)
354 if (!
s->strict_compliance) {
452 int level, orientation;
454 if (
s->wavelet_depth <= 4 &&
s->quant_matrix ==
VC2_QM_DEF) {
455 s->custom_quant_matrix = 0;
465 s->custom_quant_matrix = 1;
469 for (orientation = 0; orientation < 4; orientation++) {
478 for (orientation = 0; orientation < 4; orientation++) {
484 for (orientation = 0; orientation < 4; orientation++) {
496 if (
s->custom_quant_matrix) {
532 #define QUANT(c, mul, add, shift) (((mul) * (c) + (add)) >> (shift))
540 const int left =
b->width * (sx+0) /
s->num_x;
541 const int right =
b->width * (sx+1) /
s->num_x;
542 const int top =
b->height * (sy+0) /
s->num_y;
543 const int bottom =
b->height * (sy+1) /
s->num_y;
546 const uint64_t q_m = ((uint64_t)(
s->qmagic_lut[
quant][0])) << 2;
547 const uint64_t q_a =
s->qmagic_lut[
quant][1];
550 for (y = top; y < bottom; y++) {
551 for (x =
left; x < right; x++) {
568 if (slice->
cache[quant_idx])
569 return slice->
cache[quant_idx];
571 bits += 8*
s->prefix_bytes;
575 for (orientation = !!
level; orientation < 4; orientation++)
576 quants[
level][orientation] =
FFMAX(quant_idx -
s->quant[
level][orientation], 0);
578 for (p = 0; p < 3; p++) {
579 int bytes_start, bytes_len, pad_s, pad_c;
580 bytes_start =
bits >> 3;
583 for (orientation = !!
level; orientation < 4; orientation++) {
586 const int q_idx = quants[
level][orientation];
587 const uint64_t q_m = ((uint64_t)
s->qmagic_lut[q_idx][0]) << 2;
588 const uint64_t q_a =
s->qmagic_lut[q_idx][1];
591 const int left =
b->width * slice->
x /
s->num_x;
592 const int right =
b->width *(slice->
x+1) /
s->num_x;
593 const int top =
b->height * slice->
y /
s->num_y;
594 const int bottom =
b->height *(slice->
y+1) /
s->num_y;
598 for (y = top; y < bottom; y++) {
599 for (x =
left; x < right; x++) {
600 uint32_t c_abs =
QUANT(
FFABS(buf[x]), q_m, q_a, q_s);
609 bytes_len = (
bits >> 3) - bytes_start - 1;
610 pad_s =
FFALIGN(bytes_len,
s->size_scaler)/
s->size_scaler;
611 pad_c = (pad_s*
s->size_scaler) - bytes_len;
629 int quant_buf[2] = {-1, -1};
632 while ((
bits > top) || (
bits < bottom)) {
636 if (quant_buf[1] ==
quant) {
642 quant_buf[1] = quant_buf[0];
643 quant_buf[0] =
quant;
653 int i, j, slice_x, slice_y, bytes_left = 0;
655 int64_t total_bytes_needed = 0;
662 for (slice_y = 0; slice_y <
s->num_y; slice_y++) {
663 for (slice_x = 0; slice_x <
s->num_x; slice_x++) {
664 SliceArgs *args = &enc_args[
s->num_x*slice_y + slice_x];
670 memset(args->
cache, 0,
s->q_ceil*
sizeof(*args->
cache));
678 for (
i = 0;
i <
s->num_x*
s->num_y;
i++) {
680 bytes_left += args->
bytes;
681 for (j = 0; j < slice_redist_range; j++) {
682 if (args->
bytes > bytes_top[j]) {
683 bytes_top[j] = args->
bytes;
690 bytes_left =
s->frame_max_bytes - bytes_left;
693 while (bytes_left > 0) {
695 for (
i = 0;
i < slice_redist_range;
i++) {
697 int bits, bytes,
diff, prev_bytes, new_idx;
700 if (!top_loc[
i] || !top_loc[
i]->quant_idx)
703 prev_bytes = args->
bytes;
707 diff = bytes - prev_bytes;
708 if ((bytes_left -
diff) > 0) {
719 for (
i = 0;
i <
s->num_x*
s->num_y;
i++) {
721 total_bytes_needed += args->
bytes;
725 return total_bytes_needed;
734 const int slice_x = slice_dat->
x;
735 const int slice_y = slice_dat->
y;
736 const int quant_idx = slice_dat->
quant_idx;
737 const int slice_bytes_max = slice_dat->
bytes;
739 int p,
level, orientation;
742 memset(slice_dat->
buf, 0,
s->prefix_bytes);
750 for (orientation = !!
level; orientation < 4; orientation++)
751 quants[
level][orientation] =
FFMAX(quant_idx -
s->quant[
level][orientation], 0);
754 for (p = 0; p < 3; p++) {
755 int bytes_start, bytes_len, pad_s, pad_c;
759 for (orientation = !!
level; orientation < 4; orientation++) {
761 &
s->plane[p].band[
level][orientation],
762 quants[
level][orientation]);
769 pad_s =
FFALIGN((bytes_len + len_diff),
s->size_scaler)/
s->size_scaler;
770 pad_c = (pad_s*
s->size_scaler) - bytes_len;
772 pad_s =
FFALIGN(bytes_len,
s->size_scaler)/
s->size_scaler;
773 pad_c = (pad_s*
s->size_scaler) - bytes_len;
775 pb->
buf[bytes_start] = pad_s;
788 int slice_x, slice_y,
skip = 0;
794 for (slice_y = 0; slice_y <
s->num_y; slice_y++) {
795 for (slice_x = 0; slice_x <
s->num_x; slice_x++) {
796 SliceArgs *args = &enc_args[
s->num_x*slice_y + slice_x];
850 const ptrdiff_t linesize = transform_dat->
istride;
855 const int idx =
s->wavelet_idx;
856 const int skip = 1 +
s->interlaced;
859 ptrdiff_t pix_stride = linesize >> (
s->bpp - 1);
864 }
else if (
field == 2) {
874 for (x = 0; x < p->
width; x++) {
875 buf[x] = pix[x] -
s->diff_offset;
884 for (x = 0; x < p->
width; x++) {
885 buf[x] = pix[x] -
s->diff_offset;
898 b->width,
b->height);
905 const char *aux_data,
const int header_size,
int field)
911 for (
i = 0;
i < 3;
i++) {
912 s->transform_args[
i].ctx =
s;
913 s->transform_args[
i].field =
field;
914 s->transform_args[
i].plane = &
s->plane[
i];
915 s->transform_args[
i].idata =
frame->data[
i];
916 s->transform_args[
i].istride =
frame->linesize[
i];
926 max_frame_bytes <<
s->interlaced, 0);
959 int slice_ceil, sig_size = 256;
963 const int aux_data_size = bitexact ?
sizeof(
"Lavc") :
sizeof(
LIBAVCODEC_IDENT);
964 const int header_size = 100 + aux_data_size;
970 s->last_parse_code = 0;
971 s->next_parse_offset = 0;
974 s->frame_max_bytes = (
av_rescale(r_bitrate,
s->avctx->time_base.num,
975 s->avctx->time_base.den) >> 3) - header_size;
976 s->slice_max_bytes = slice_ceil =
av_rescale(
s->frame_max_bytes, 1,
s->num_x*
s->num_y);
979 while (sig_size > 255) {
981 if (r_size > slice_ceil) {
982 s->slice_max_bytes -= r_size - slice_ceil;
985 sig_size = r_size/
s->size_scaler;
986 s->size_scaler <<= 1;
989 s->slice_min_bytes =
s->slice_max_bytes -
s->slice_max_bytes*(
s->tolerance/100.0f);
990 if (
s->slice_min_bytes < 0 ||
s->slice_max_bytes > INT_MAX >> 3)
1017 for (
i = 0;
i < 3;
i++) {
1037 s->picture_number = 0;
1048 s->strict_compliance = 1;
1051 s->slice_max_bytes = 0;
1052 s->slice_min_bytes = 0;
1080 if ((
s->slice_width & (
s->slice_width - 1)) ||
1081 (
s->slice_height & (
s->slice_height - 1))) {
1086 if ((
s->slice_width > avctx->
width) ||
1087 (
s->slice_height > avctx->
height)) {
1092 if (
s->base_vf <= 0) {
1094 s->strict_compliance =
s->base_vf = 0;
1098 "the specifications, decrease strictness to use it.\n");
1116 s->diff_offset = 128;
1121 s->diff_offset = 128;
1122 }
else if (depth == 10) {
1125 s->diff_offset = 512;
1129 s->diff_offset = 2048;
1133 for (
i = 0;
i < 3;
i++) {
1136 p->
width = avctx->
width >> (
i ?
s->chroma_x_shift : 0);
1149 for (o = 0; o < 4; o++) {
1154 shift = (o > 1)*
b->height*
b->stride + (o & 1)*
b->width;
1161 s->plane[
i].coef_stride,
1162 s->plane[
i].dwt_height,
1163 s->slice_width,
s->slice_height))
1168 s->num_x =
s->plane[0].dwt_width/
s->slice_width;
1169 s->num_y =
s->plane[0].dwt_height/
s->slice_height;
1175 for (
i = 0;
i < 116;
i++) {
1177 const uint32_t m =
av_log2(qf);
1178 const uint32_t t = (1ULL << (m + 32)) / qf;
1179 const uint32_t
r = (t*qf + qf) & UINT32_MAX;
1180 if (!(qf & (qf - 1))) {
1181 s->qmagic_lut[
i][0] = 0xFFFFFFFF;
1182 s->qmagic_lut[
i][1] = 0xFFFFFFFF;
1183 }
else if (
r <= 1 << m) {
1184 s->qmagic_lut[
i][0] = t + 1;
1185 s->qmagic_lut[
i][1] = 0;
1187 s->qmagic_lut[
i][0] = t;
1188 s->qmagic_lut[
i][1] = t;
1197 #define VC2ENC_FLAGS (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
1199 {
"tolerance",
"Max undershoot in percent", offsetof(
VC2EncContext, tolerance),
AV_OPT_TYPE_DOUBLE, {.dbl = 5.0f}, 0.0f, 45.0f,
VC2ENC_FLAGS, .unit =
"tolerance"},
1200 {
"slice_width",
"Slice width", offsetof(
VC2EncContext, slice_width),
AV_OPT_TYPE_INT, {.i64 = 32}, 32, 1024,
VC2ENC_FLAGS, .unit =
"slice_width"},
1201 {
"slice_height",
"Slice height", offsetof(
VC2EncContext, slice_height),
AV_OPT_TYPE_INT, {.i64 = 16}, 8, 1024,
VC2ENC_FLAGS, .unit =
"slice_height"},
1202 {
"wavelet_depth",
"Transform depth", offsetof(
VC2EncContext, wavelet_depth),
AV_OPT_TYPE_INT, {.i64 = 4}, 1, 5,
VC2ENC_FLAGS, .unit =
"wavelet_depth"},
1203 {
"wavelet_type",
"Transform type", offsetof(
VC2EncContext, wavelet_idx),
AV_OPT_TYPE_INT, {.i64 =
VC2_TRANSFORM_9_7}, 0,
VC2_TRANSFORMS_NB,
VC2ENC_FLAGS, .unit =
"wavelet_idx"},
1204 {
"9_7",
"Deslauriers-Dubuc (9,7)", 0,
AV_OPT_TYPE_CONST, {.i64 =
VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX,
VC2ENC_FLAGS, .unit =
"wavelet_idx"},
1205 {
"5_3",
"LeGall (5,3)", 0,
AV_OPT_TYPE_CONST, {.i64 =
VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX,
VC2ENC_FLAGS, .unit =
"wavelet_idx"},
1208 {
"qm",
"Custom quantization matrix", offsetof(
VC2EncContext, quant_matrix),
AV_OPT_TYPE_INT, {.i64 =
VC2_QM_DEF}, 0,
VC2_QM_NB,
VC2ENC_FLAGS, .unit =
"quant_matrix"},
1224 {
"b",
"600000000" },
static void init_quant_matrix(VC2EncContext *s)
static const uint8_t vc2_qm_col_tab[][4]
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
static const uint8_t vc2_qm_flat_tab[][4]
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
enum AVColorSpace colorspace
YUV colorspace type.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static int put_bytes_output(const PutBitContext *s)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
#define MAX_DWT_LEVELS
The spec limits the number of wavelet decompositions to 4 for both level 1 (VC-2) and 128 (long-gop d...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
int depth
Number of bits in the component.
enum AVFieldOrder field_order
Field order.
static int put_bytes_count(const PutBitContext *s, int round_up)
static void encode_scan_format(VC2EncContext *s)
static int encode_slices(VC2EncContext *s)
static int rate_control(AVCodecContext *avctx, void *arg)
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
#define AV_PIX_FMT_YUV420P10
av_cold void ff_vc2enc_free_transforms(VC2TransformContext *s)
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
static const VC2BaseVideoFormat base_video_fmts[]
static void encode_picture_header(VC2EncContext *s)
static void encode_slice_params(VC2EncContext *s)
static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
void(* vc2_subband_dwt[VC2_TRANSFORMS_NB])(struct VC2TransformContext *t, dwtcoef *data, ptrdiff_t stride, int width, int height)
uint32_t qmagic_lut[116][2]
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
const int32_t ff_dirac_qscale_tab[116]
static void encode_clean_area(VC2EncContext *s)
static void encode_frame_size(VC2EncContext *s)
static void encode_quant_matrix(VC2EncContext *s)
const uint8_t ff_dirac_default_qmat[7][4][4]
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
static void encode_color_spec(VC2EncContext *s)
static int count_hq_slice(SliceArgs *slice, int quant_idx)
static av_noinline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
AVCodec p
The public AVCodec.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
int flags
AV_CODEC_FLAG_*.
static double val(void *priv, double ch)
#define FF_CODEC_ENCODE_CB(func)
#define AV_PIX_FMT_YUV444P10
static const uint8_t quant[64]
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint32_t next_parse_offset
#define FF_ARRAY_ELEMS(a)
av_cold int ff_vc2enc_init_transforms(VC2TransformContext *s, int p_stride, int p_height, int slice_w, int slice_h)
DiracParseCodes
Parse code values:
const struct VC2EncContext * ctx
static const AVClass vc2enc_class
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
static uint16_t interleaved_ue_golomb_tab[256]
x_k x_{k-1} ... x_0 -> 0 x_k 0 x_{k - 1} ... 0 x_0
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
static int encode_frame(VC2EncContext *s, AVPacket *avpkt, const AVFrame *frame, const char *aux_data, const int header_size, int field)
static void encode_transform_params(VC2EncContext *s)
static int dwt_plane(AVCodecContext *avctx, void *arg)
static void put_bits63(PutBitContext *s, int n, uint64_t value)
Write up to 63 bits into a bitstream.
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
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 field
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_always_inline void put_vc2_ue_uint_inline(PutBitContext *pb, uint32_t val)
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
#define CODEC_LONG_NAME(str)
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static uint16_t top_interleaved_ue_golomb_tab[256]
1 x_{k-1} ... x_0 -> 0 0 0 x_{k - 1} ... 0 x_0
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static void encode_frame_rate(VC2EncContext *s)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define CODEC_PIXFMTS_ARRAY(array)
uint8_t quant[MAX_DWT_LEVELS][4]
Rational number (pair of numerator and denominator).
static void encode_wavelet_transform(VC2EncContext *s)
int64_t bit_rate
the average bitrate
static const AVOption vc2enc_options[]
static const int base_video_fmts_len
const char * av_default_item_name(void *ptr)
Return the context name.
static void encode_aspect_ratio(VC2EncContext *s)
#define AV_PIX_FMT_YUV422P10
#define DIRAC_MAX_QUANT_INDEX
@ AVCOL_RANGE_UNSPECIFIED
static enum AVPixelFormat allowed_pix_fmts[]
static int encode_hq_slice(AVCodecContext *avctx, void *arg)
enum DiracParseCodes last_parse_code
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static int shift(int a, int b)
#define AV_PIX_FMT_YUV422P12
static av_cold int vc2_encode_init(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV444P12
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static void encode_source_params(VC2EncContext *s)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
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 offset
static void encode_picture_start(VC2EncContext *s)
#define AV_LOG_INFO
Standard information.
static void encode_parse_params(VC2EncContext *s)
#define i(width, name, range_min, range_max)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
void * av_calloc(size_t nmemb, size_t size)
static void encode_parse_info(VC2EncContext *s, enum DiracParseCodes pcode)
const FFCodec ff_vc2_encoder
static av_cold int vc2_encode_end(AVCodecContext *avctx)
static const FFCodecDefault vc2enc_defaults[]
TransformArgs transform_args[3]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
#define AV_PIX_FMT_YUV420P12
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
static av_cold void vc2_init_static_data(void)
main external API structure.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
int cache[DIRAC_MAX_QUANT_INDEX]
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
@ AV_OPT_TYPE_INT
Underlying C type is int.
static void encode_seq_header(VC2EncContext *s)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static void encode_subband(const VC2EncContext *s, PutBitContext *pb, int sx, int sy, const SubBand *b, int quant)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define QUANT(c, mul, add, shift)
static av_always_inline int count_vc2_ue_uint(uint32_t val)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
SubBand band[DWT_LEVELS_3D][4]
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int calc_slice_sizes(VC2EncContext *s)
This structure stores compressed data.
int width
picture width / height.
static const double coeff[2][5]
@ AV_CLASS_CATEGORY_ENCODER
static uint8_t golomb_len_tab[256]
1 x_{k-1} ... x_0 -> 2 * k
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define SLICE_REDIST_TOTAL
static void encode_sample_fmt(VC2EncContext *s)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
static void encode_signal_range(VC2EncContext *s)
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.