22 #include "libavutil/ffversion.h"
33 #define MAX_QUANT_INDEX 100
35 #define COEF_LUT_TAB 2048
52 typedef struct Plane {
153 int pbits = 0,
bits = 0, topbit = 1, maxval = 1;
160 while (val > maxval) {
168 for (i = 0; i <
bits; i++) {
175 put_bits(pb, bits*2 + 1, (pbits << 1) | 1);
180 int topbit = 1, maxval = 1;
185 while (val > maxval) {
198 int pbits = 0,
bits = 0, topbit = 1, maxval = 1;
206 while (val > maxval) {
214 for (i = 0; i <
bits; i++) {
222 *eval = (pbits << 1) | 1;
228 uint32_t cur_pos, dist;
347 }
else if (depth == 10) {
464 int level, orientation;
468 for (orientation = 0; orientation < 4; orientation++) {
477 for (orientation = 0; orientation < 4; orientation++) {
483 for (orientation = 0; orientation < 4; orientation++) {
493 int level, custom_quant_matrix = 0;
495 custom_quant_matrix = 1;
497 if (custom_quant_matrix) {
552 *eval = (*eval << 1) | (coeff < 0);
583 for (y = top; y < bottom; y++) {
584 for (x = left; x < right; x++) {
586 put_bits(pb, len_lut[coeff[x]], val_lut[coeff[x]]);
595 int slice_y,
int quant_idx)
597 int x, y, left, right, top, bottom, qfactor;
605 for (orientation = !!level; orientation < 4; orientation++)
606 quants[level][orientation] =
FFMAX(quant_idx - s->
quant[level][orientation], 0);
608 for (p = 0; p < 3; p++) {
609 int bytes_start, bytes_len, pad_s, pad_c;
610 bytes_start = bits >> 3;
613 for (orientation = !!level; orientation < 4; orientation++) {
617 quant_idx = quants[
level][orientation];
627 for (y = top; y < bottom; y++) {
628 for (x = left; x < right; x++) {
643 bytes_len = (bits >> 3) - bytes_start - 1;
659 const int sx = slice_dat->
x;
660 const int sy = slice_dat->
y;
662 const int64_t top = slice_dat->
bits_ceil;
664 const double bottom = top - top*(percent/100.0f);
667 while ((bits > top) || (bits < bottom)) {
668 range *= bits > top ? +1 : -1;
669 quant = av_clip(quant + range, 0, s->
q_ceil);
671 range = av_clip(range/2, 1, s->
q_ceil);
672 if (quant_buf[1] == quant) {
673 quant = bits_buf[0] < bits ? quant_buf[0] :
quant;
674 bits = bits_buf[0] < bits ? bits_buf[0] :
bits;
677 quant_buf[1] = quant_buf[0];
678 quant_buf[0] =
quant;
679 bits_buf[1] = bits_buf[0];
690 int slice_x, slice_y;
693 for (slice_y = 0; slice_y < s->
num_y; slice_y++) {
694 for (slice_x = 0; slice_x < s->
num_x; slice_x++) {
714 const int slice_x = slice_dat->
x;
715 const int slice_y = slice_dat->
y;
716 const int quant_idx = slice_dat->
quant_idx;
717 const int slice_bytes_max = slice_dat->
bytes;
719 int p,
level, orientation;
727 for (orientation = !!level; orientation < 4; orientation++)
728 quants[level][orientation] =
FFMAX(quant_idx - s->
quant[level][orientation], 0);
731 for (p = 0; p < 3; p++) {
732 int bytes_start, bytes_len, pad_s, pad_c;
736 for (orientation = !!level; orientation < 4; orientation++) {
739 quants[level][orientation]);
752 pb->
buf[bytes_start] = pad_s;
763 int slice_x, slice_y, skip = 0;
770 for (slice_y = 0; slice_y < s->
num_y; slice_y++) {
771 for (slice_x = 0; slice_x < s->
num_x; slice_x++) {
828 const void *frame_data = transform_dat->
idata;
829 const ptrdiff_t linesize = transform_dat->
istride;
830 const int field = transform_dat->
field;
838 ptrdiff_t pix_stride = linesize >> (s->
bpp - 1);
843 }
else if (field == 2) {
852 for (y = 0; y < p->
height*skip; y+=skip) {
853 for (x = 0; x < p->
width; x++) {
860 const uint16_t *pix = (
const uint16_t *)frame_data + offset;
861 for (y = 0; y < p->
height*skip; y+=skip) {
862 for (x = 0; x < p->
width; x++) {
882 const char *aux_data,
int field)
900 for (i = 0; i < 3; i++) {
926 int max_frame_bytes, sig_size = 256;
928 const char aux_data[] =
"FFmpeg version "FFMPEG_VERSION;
929 const int aux_data_size =
sizeof(aux_data);
930 const int header_size = 100 + aux_data_size;
944 while (sig_size > 255) {
977 for (i = 0; i < 3; i++) {
1015 if (avctx->
width == 1280 && avctx->
height == 720) {
1021 }
else if (avctx->
width == 1920 && avctx->
height == 1080) {
1036 }
else if (avctx->
width == 3840 && avctx->
height == 2160) {
1046 av_log(avctx,
AV_LOG_ERROR,
"Interlacing not supported with non standard formats!\n");
1071 "the specifications, please add a -strict -1 flag to use it\n");
1081 for (i = 0; i < 3; i++) {
1097 for (o = 0; o < 4; o++) {
1131 for (i = 0; i < s->
q_ceil; i++) {
1147 #define VC2ENC_FLAGS (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
1149 {
"tolerance",
"Max undershoot in percent", offsetof(
VC2EncContext, tolerance),
AV_OPT_TYPE_DOUBLE, {.dbl = 10.0f}, 0.0f, 45.0f,
VC2ENC_FLAGS,
"tolerance"},
1150 {
"slice_width",
"Slice width", offsetof(
VC2EncContext, slice_width),
AV_OPT_TYPE_INT, {.i64 = 128}, 32, 1024,
VC2ENC_FLAGS,
"slice_width"},
1151 {
"slice_height",
"Slice height", offsetof(
VC2EncContext, slice_height),
AV_OPT_TYPE_INT, {.i64 = 64}, 8, 1024,
VC2ENC_FLAGS,
"slice_height"},
1152 {
"wavelet_depth",
"Transform depth", offsetof(
VC2EncContext, wavelet_depth),
AV_OPT_TYPE_INT, {.i64 = 5}, 1, 5,
VC2ENC_FLAGS,
"wavelet_depth"},
1153 {
"wavelet_type",
"Transform type", offsetof(
VC2EncContext, wavelet_idx),
AV_OPT_TYPE_INT, {.i64 =
VC2_TRANSFORM_9_7}, 0,
VC2_TRANSFORMS_NB,
VC2ENC_FLAGS,
"wavelet_idx"},
1154 {
"9_7",
"Deslauriers-Dubuc (9,7)", 0,
AV_OPT_TYPE_CONST, {.i64 =
VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX,
VC2ENC_FLAGS,
"wavelet_idx"},
1155 {
"5_3",
"LeGall (5,3)", 0,
AV_OPT_TYPE_CONST, {.i64 =
VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX,
VC2ENC_FLAGS,
"wavelet_idx"},
1156 {
"qm",
"Custom quantization matrix", offsetof(
VC2EncContext, quant_matrix),
AV_OPT_TYPE_INT, {.i64 =
VC2_QM_DEF}, 0,
VC2_QM_NB,
VC2ENC_FLAGS,
"quant_matrix"},
1172 {
"b",
"600000000" },
1193 .priv_class = &vc2enc_class,
static void encode_parse_info(VC2EncContext *s, enum DiracParseCodes pcode)
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
const char const char void * val
const int32_t ff_dirac_qscale_tab[116]
static void encode_wavelet_transform(VC2EncContext *s)
static void encode_aspect_ratio(VC2EncContext *s)
static int shift(int a, int b)
static av_cold int vc2_encode_init(AVCodecContext *avctx)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
av_cold void ff_vc2enc_free_transforms(VC2TransformContext *s)
"Linear transfer characteristics"
TransformArgs transform_args[3]
uint32_t next_parse_offset
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
static void encode_source_params(VC2EncContext *s)
static av_cold int init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static av_always_inline void coeff_quantize_encode(PutBitContext *pb, qcoef coeff, int qfactor)
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
static av_always_inline int count_vc2_ue_uint(uint16_t val)
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static av_cold int vc2_encode_end(AVCodecContext *avctx)
const uint8_t vc2_qm_flat_tab[][4]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static void encode_transform_params(VC2EncContext *s)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
enum DiracParseCodes last_parse_code
Interface to Dirac Decoder/Encoder.
static void encode_frame(VC2EncContext *s, const AVFrame *frame, const char *aux_data, int field)
#define AV_PIX_FMT_YUV422P12
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
static void encode_clean_area(VC2EncContext *s)
const uint8_t vc2_qm_col_tab[][4]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
ITU-R BT1361 Extended Colour Gamut.
static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void encode_parse_params(VC2EncContext *s)
const uint8_t ff_dirac_default_qmat[7][4][4]
const char * name
Name of the codec implementation.
static av_always_inline void get_vc2_ue_uint(uint16_t val, uint8_t *nbits, uint32_t *eval)
#define AV_PIX_FMT_YUV444P10
static const AVCodecDefault vc2enc_defaults[]
static const uint8_t offset[127][2]
static int put_bits_count(PutBitContext *s)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static void encode_seq_header(VC2EncContext *s)
SubBand band[DWT_LEVELS][4]
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int count_hq_slice(VC2EncContext *s, int slice_x, int slice_y, int quant_idx)
static void encode_scan_format(VC2EncContext *s)
int width
picture width / height.
static void init_custom_qm(VC2EncContext *s)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static void encode_frame_size(VC2EncContext *s)
static void encode_quant_matrix(VC2EncContext *s)
void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
the normal 2^n-1 "JPEG" YUV ranges
static void encode_slice_params(VC2EncContext *s)
static void encode_sample_fmt(VC2EncContext *s)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
uint8_t quant[MAX_DWT_LEVELS][4]
static void encode_frame_rate(VC2EncContext *s)
static void encode_picture_header(VC2EncContext *s)
#define AV_LOG_INFO
Standard information.
static void encode_signal_range(VC2EncContext *s)
static int dwt_plane(AVCodecContext *avctx, void *arg)
functionally identical to above
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
DiracParseCodes
Parse code values:
static void encode_color_spec(VC2EncContext *s)
static int encode_hq_slice(AVCodecContext *avctx, void *arg)
#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 int encode_slices(VC2EncContext *s)
#define AV_PIX_FMT_YUV420P10
Describe the class of an AVClass context structure.
void(* vc2_subband_dwt[VC2_TRANSFORMS_NB])(struct VC2TransformContext *t, dwtcoef *data, ptrdiff_t stride, int width, int height)
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static void calc_slice_sizes(VC2EncContext *s)
static av_always_inline void put_padding(PutBitContext *pb, int bytes)
static av_always_inline void coeff_quantize_get(qcoef coeff, int qfactor, uint8_t *len, uint32_t *eval)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static void encode_subband(VC2EncContext *s, PutBitContext *pb, int sx, int sy, SubBand *b, int quant)
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static enum AVPixelFormat allowed_pix_fmts[]
the normal 219*2^(n-8) "MPEG" YUV ranges
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static const AVOption vc2enc_options[]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int rate_control(AVCodecContext *avctx, void *arg)
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
static const double coeff[2][5]
static void encode_picture_start(VC2EncContext *s)
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
enum AVFieldOrder field_order
Field order.
static const AVCodecDefault defaults[]
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
static const AVClass vc2enc_class
av_cold int ff_vc2enc_init_transforms(VC2TransformContext *s, int p_width, int p_height)