FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vc2enc.c File Reference
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "libavutil/version.h"
#include "codec_internal.h"
#include "dirac.h"
#include "encode.h"
#include "put_bits.h"
#include "version.h"
#include "vc2enc_dwt.h"
#include "diractab.h"

Go to the source code of this file.

Data Structures

struct  VC2BaseVideoFormat
 
struct  SubBand
 
struct  Plane
 
struct  SliceArgs
 
struct  TransformArgs
 
struct  VC2EncContext
 

Macros

#define SSIZE_ROUND(b)   (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes)
 
#define SLICE_REDIST_TOTAL   150
 
#define QUANT(c, mul, add, shift)   (((mul) * (c) + (add)) >> (shift))
 
#define VC2ENC_FLAGS   (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
 

Enumerations

enum  VC2_QM { VC2_QM_DEF = 0, VC2_QM_COL, VC2_QM_FLAT, VC2_QM_NB }
 

Functions

static av_always_inline void put_vc2_ue_uint (PutBitContext *pb, uint32_t val)
 
static av_always_inline int count_vc2_ue_uint (uint32_t val)
 
static void encode_parse_info (VC2EncContext *s, enum DiracParseCodes pcode)
 
static void encode_parse_params (VC2EncContext *s)
 
static void encode_frame_size (VC2EncContext *s)
 
static void encode_sample_fmt (VC2EncContext *s)
 
static void encode_scan_format (VC2EncContext *s)
 
static void encode_frame_rate (VC2EncContext *s)
 
static void encode_aspect_ratio (VC2EncContext *s)
 
static void encode_clean_area (VC2EncContext *s)
 
static void encode_signal_range (VC2EncContext *s)
 
static void encode_color_spec (VC2EncContext *s)
 
static void encode_source_params (VC2EncContext *s)
 
static void encode_seq_header (VC2EncContext *s)
 
static void encode_picture_header (VC2EncContext *s)
 
static void encode_slice_params (VC2EncContext *s)
 
static void init_quant_matrix (VC2EncContext *s)
 
static void encode_quant_matrix (VC2EncContext *s)
 
static void encode_transform_params (VC2EncContext *s)
 
static void encode_wavelet_transform (VC2EncContext *s)
 
static void encode_picture_start (VC2EncContext *s)
 
static void encode_subband (const VC2EncContext *s, PutBitContext *pb, int sx, int sy, const SubBand *b, int quant)
 
static int count_hq_slice (SliceArgs *slice, int quant_idx)
 
static int rate_control (AVCodecContext *avctx, void *arg)
 
static int calc_slice_sizes (VC2EncContext *s)
 
static int encode_hq_slice (AVCodecContext *avctx, void *arg)
 
static int encode_slices (VC2EncContext *s)
 
static int dwt_plane (AVCodecContext *avctx, void *arg)
 
static int encode_frame (VC2EncContext *s, AVPacket *avpkt, const AVFrame *frame, const char *aux_data, const int header_size, int field)
 
static av_cold int vc2_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
 
static av_cold int vc2_encode_end (AVCodecContext *avctx)
 
static av_cold int vc2_encode_init (AVCodecContext *avctx)
 

Variables

static const VC2BaseVideoFormat base_video_fmts []
 
static const int base_video_fmts_len = FF_ARRAY_ELEMS(base_video_fmts)
 
static const uint8_t vc2_qm_col_tab [][4]
 
static const uint8_t vc2_qm_flat_tab [][4]
 
static const AVOption vc2enc_options []
 
static const AVClass vc2enc_class
 
static const FFCodecDefault vc2enc_defaults []
 
static enum AVPixelFormat allowed_pix_fmts []
 
const FFCodec ff_vc2_encoder
 

Macro Definition Documentation

◆ SSIZE_ROUND

#define SSIZE_ROUND (   b)    (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes)

Definition at line 36 of file vc2enc.c.

◆ SLICE_REDIST_TOTAL

#define SLICE_REDIST_TOTAL   150

Definition at line 39 of file vc2enc.c.

◆ QUANT

#define QUANT (   c,
  mul,
  add,
  shift 
)    (((mul) * (c) + (add)) >> (shift))

Definition at line 533 of file vc2enc.c.

◆ VC2ENC_FLAGS

#define VC2ENC_FLAGS   (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)

Definition at line 1195 of file vc2enc.c.

Enumeration Type Documentation

◆ VC2_QM

enum VC2_QM
Enumerator
VC2_QM_DEF 
VC2_QM_COL 
VC2_QM_FLAT 
VC2_QM_NB 

Definition at line 82 of file vc2enc.c.

Function Documentation

◆ put_vc2_ue_uint()

static av_always_inline void put_vc2_ue_uint ( PutBitContext pb,
uint32_t  val 
)
static

◆ count_vc2_ue_uint()

static av_always_inline int count_vc2_ue_uint ( uint32_t  val)
static

Definition at line 220 of file vc2enc.c.

Referenced by count_hq_slice().

◆ encode_parse_info()

static void encode_parse_info ( VC2EncContext s,
enum DiracParseCodes  pcode 
)
static

Definition at line 237 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_parse_params()

static void encode_parse_params ( VC2EncContext s)
static

Definition at line 269 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_frame_size()

static void encode_frame_size ( VC2EncContext s)
static

Definition at line 278 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_sample_fmt()

static void encode_sample_fmt ( VC2EncContext s)
static

Definition at line 289 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_scan_format()

static void encode_scan_format ( VC2EncContext s)
static

Definition at line 305 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_frame_rate()

static void encode_frame_rate ( VC2EncContext s)
static

Definition at line 313 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_aspect_ratio()

static void encode_aspect_ratio ( VC2EncContext s)
static

Definition at line 325 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_clean_area()

static void encode_clean_area ( VC2EncContext s)
static

Definition at line 337 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_signal_range()

static void encode_signal_range ( VC2EncContext s)
static

Definition at line 343 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_color_spec()

static void encode_color_spec ( VC2EncContext s)
static

Definition at line 351 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_source_params()

static void encode_source_params ( VC2EncContext s)
static

Definition at line 396 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_seq_header()

static void encode_seq_header ( VC2EncContext s)
static

Definition at line 409 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_picture_header()

static void encode_picture_header ( VC2EncContext s)
static

Definition at line 419 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_slice_params()

static void encode_slice_params ( VC2EncContext s)
static

Definition at line 426 of file vc2enc.c.

Referenced by encode_transform_params().

◆ init_quant_matrix()

static void init_quant_matrix ( VC2EncContext s)
static

Definition at line 451 of file vc2enc.c.

Referenced by calc_slice_sizes().

◆ encode_quant_matrix()

static void encode_quant_matrix ( VC2EncContext s)
static

Definition at line 493 of file vc2enc.c.

Referenced by encode_transform_params().

◆ encode_transform_params()

static void encode_transform_params ( VC2EncContext s)
static

Definition at line 508 of file vc2enc.c.

Referenced by encode_wavelet_transform().

◆ encode_wavelet_transform()

static void encode_wavelet_transform ( VC2EncContext s)
static

Definition at line 518 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_picture_start()

static void encode_picture_start ( VC2EncContext s)
static

Definition at line 525 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_subband()

static void encode_subband ( const VC2EncContext s,
PutBitContext pb,
int  sx,
int  sy,
const SubBand b,
int  quant 
)
static

Definition at line 536 of file vc2enc.c.

Referenced by encode_hq_slice().

◆ count_hq_slice()

static int count_hq_slice ( SliceArgs slice,
int  quant_idx 
)
static

Definition at line 562 of file vc2enc.c.

Referenced by calc_slice_sizes(), and rate_control().

◆ rate_control()

static int rate_control ( AVCodecContext avctx,
void *  arg 
)
static

Definition at line 624 of file vc2enc.c.

Referenced by calc_slice_sizes(), and siren_decode().

◆ calc_slice_sizes()

static int calc_slice_sizes ( VC2EncContext s)
static

Definition at line 652 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_hq_slice()

static int encode_hq_slice ( AVCodecContext avctx,
void *  arg 
)
static

Definition at line 730 of file vc2enc.c.

Referenced by encode_slices().

◆ encode_slices()

static int encode_slices ( VC2EncContext s)
static

Definition at line 786 of file vc2enc.c.

Referenced by encode_frame().

◆ dwt_plane()

static int dwt_plane ( AVCodecContext avctx,
void *  arg 
)
static

Definition at line 846 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( VC2EncContext s,
AVPacket avpkt,
const AVFrame frame,
const char *  aux_data,
const int  header_size,
int  field 
)
static

Definition at line 905 of file vc2enc.c.

Referenced by vc2_encode_frame().

◆ vc2_encode_frame()

static av_cold int vc2_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 956 of file vc2enc.c.

◆ vc2_encode_end()

static av_cold int vc2_encode_end ( AVCodecContext avctx)
static

Definition at line 1011 of file vc2enc.c.

◆ vc2_encode_init()

static av_cold int vc2_encode_init ( AVCodecContext avctx)
static

Definition at line 1028 of file vc2enc.c.

Variable Documentation

◆ base_video_fmts

const VC2BaseVideoFormat base_video_fmts[]
static

Definition at line 49 of file vc2enc.c.

Referenced by vc2_encode_init().

◆ base_video_fmts_len

const int base_video_fmts_len = FF_ARRAY_ELEMS(base_video_fmts)
static

Definition at line 80 of file vc2enc.c.

Referenced by vc2_encode_init().

◆ vc2_qm_col_tab

const uint8_t vc2_qm_col_tab[][4]
static
Initial value:
= {
{20, 9, 15, 4},
{ 0, 6, 6, 4},
{ 0, 3, 3, 5},
{ 0, 3, 5, 1},
{ 0, 11, 10, 11}
}

Definition at line 435 of file vc2enc.c.

Referenced by init_quant_matrix().

◆ vc2_qm_flat_tab

const uint8_t vc2_qm_flat_tab[][4]
static
Initial value:
= {
{ 0, 0, 0, 0},
{ 0, 0, 0, 0},
{ 0, 0, 0, 0},
{ 0, 0, 0, 0},
{ 0, 0, 0, 0}
}

Definition at line 443 of file vc2enc.c.

Referenced by init_quant_matrix().

◆ vc2enc_options

const AVOption vc2enc_options[]
static
Initial value:
= {
{"tolerance", "Max undershoot in percent", 0x42, AV_OPT_TYPE_DOUBLE, {.dbl = 5.0f}, 0.0f, 45.0f, VC2ENC_FLAGS, .unit = "tolerance"},
{"slice_width", "Slice width", 0x42, AV_OPT_TYPE_INT, {.i64 = 32}, 32, 1024, VC2ENC_FLAGS, .unit = "slice_width"},
{"slice_height", "Slice height", 0x42, AV_OPT_TYPE_INT, {.i64 = 16}, 8, 1024, VC2ENC_FLAGS, .unit = "slice_height"},
{"wavelet_depth", "Transform depth", 0x42, AV_OPT_TYPE_INT, {.i64 = 4}, 1, 5, VC2ENC_FLAGS, .unit = "wavelet_depth"},
{"wavelet_type", "Transform type", 0x42, AV_OPT_TYPE_INT, {.i64 = VC2_TRANSFORM_9_7}, 0, VC2_TRANSFORMS_NB, VC2ENC_FLAGS, .unit = "wavelet_idx"},
{"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"},
{"5_3", "LeGall (5,3)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "wavelet_idx"},
{"haar", "Haar (with shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR_S}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "wavelet_idx"},
{"haar_noshift", "Haar (without shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "wavelet_idx"},
{"qm", "Custom quantization matrix", 0x42, AV_OPT_TYPE_INT, {.i64 = VC2_QM_DEF}, 0, VC2_QM_NB, VC2ENC_FLAGS, .unit = "quant_matrix"},
{"default", "Default from the specifications", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_DEF}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "quant_matrix"},
{"color", "Prevents low bitrate discoloration", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_COL}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "quant_matrix"},
{"flat", "Optimize for PSNR", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_FLAT}, INT_MIN, INT_MAX, VC2ENC_FLAGS, .unit = "quant_matrix"},
{NULL}
}

Definition at line 1196 of file vc2enc.c.

◆ vc2enc_class

const AVClass vc2enc_class
static
Initial value:
= {
.class_name = "SMPTE VC-2 encoder",
.option = vc2enc_options,
.item_name = av_default_item_name,
}

Definition at line 1213 of file vc2enc.c.

◆ vc2enc_defaults

const FFCodecDefault vc2enc_defaults[]
static
Initial value:
= {
{ "b", "600000000" },
{ NULL },
}

Definition at line 1221 of file vc2enc.c.

◆ allowed_pix_fmts

enum AVPixelFormat allowed_pix_fmts[]
static

◆ ff_vc2_encoder

const FFCodec ff_vc2_encoder
Initial value:
= {
.p.name = "vc2",
CODEC_LONG_NAME("SMPTE VC-2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.priv_data_size = sizeof(VC2EncContext),
.close = vc2_encode_end,
.p.priv_class = &vc2enc_class,
.defaults = vc2enc_defaults,
.p.pix_fmts = allowed_pix_fmts,
}

Definition at line 1233 of file vc2enc.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
VC2_TRANSFORM_9_7
@ VC2_TRANSFORM_9_7
Definition: vc2enc_dwt.h:31
AV_CODEC_ID_DIRAC
@ AV_CODEC_ID_DIRAC
Definition: codec_id.h:168
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:696
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:487
vc2_encode_frame
static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Definition: vc2enc.c:956
VC2_QM_NB
@ VC2_QM_NB
Definition: vc2enc.c:87
VC2_TRANSFORMS_NB
@ VC2_TRANSFORMS_NB
Definition: vc2enc_dwt.h:39
VC2_QM_FLAT
@ VC2_QM_FLAT
Definition: vc2enc.c:85
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:490
vc2enc_class
static const AVClass vc2enc_class
Definition: vc2enc.c:1213
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
vc2enc_options
static const AVOption vc2enc_options[]
Definition: vc2enc.c:1196
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
VC2_QM_COL
@ VC2_QM_COL
Definition: vc2enc.c:84
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:488
allowed_pix_fmts
static enum AVPixelFormat allowed_pix_fmts[]
Definition: vc2enc.c:1226
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:492
vc2_encode_init
static av_cold int vc2_encode_init(AVCodecContext *avctx)
Definition: vc2enc.c:1028
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:494
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:679
vc2_encode_end
static av_cold int vc2_encode_end(AVCodecContext *avctx)
Definition: vc2enc.c:1011
vc2enc_defaults
static const FFCodecDefault vc2enc_defaults[]
Definition: vc2enc.c:1221
VC2EncContext
Definition: vc2enc.c:130
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:491
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
VC2_TRANSFORM_HAAR
@ VC2_TRANSFORM_HAAR
Definition: vc2enc_dwt.h:34
VC2ENC_FLAGS
#define VC2ENC_FLAGS
Definition: vc2enc.c:1195
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
VC2_QM_DEF
@ VC2_QM_DEF
Definition: vc2enc.c:83
AV_CLASS_CATEGORY_ENCODER
@ AV_CLASS_CATEGORY_ENCODER
Definition: log.h:34
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
VC2_TRANSFORM_HAAR_S
@ VC2_TRANSFORM_HAAR_S
Definition: vc2enc_dwt.h:35
VC2_TRANSFORM_5_3
@ VC2_TRANSFORM_5_3
Definition: vc2enc_dwt.h:32