FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vc2enc.c File Reference
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "dirac.h"
#include "put_bits.h"
#include "internal.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 (VC2EncContext *s, PutBitContext *pb, int sx, int sy, 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)
 
const uint8_t vc2_qm_col_tab [][4]
 
const uint8_t vc2_qm_flat_tab [][4]
 
static const AVOption vc2enc_options []
 
static const AVClass vc2enc_class
 
static const AVCodecDefault vc2enc_defaults []
 
static enum AVPixelFormat allowed_pix_fmts []
 
AVCodec ff_vc2_encoder
 

Macro Definition Documentation

◆ SSIZE_ROUND

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

Definition at line 33 of file vc2enc.c.

◆ SLICE_REDIST_TOTAL

#define SLICE_REDIST_TOTAL   150

Definition at line 36 of file vc2enc.c.

◆ QUANT

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

Definition at line 524 of file vc2enc.c.

◆ VC2ENC_FLAGS

#define VC2ENC_FLAGS   (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)

Definition at line 1192 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 78 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 211 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 228 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_parse_params()

static void encode_parse_params ( VC2EncContext s)
static

Definition at line 260 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_frame_size()

static void encode_frame_size ( VC2EncContext s)
static

Definition at line 269 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_sample_fmt()

static void encode_sample_fmt ( VC2EncContext s)
static

Definition at line 280 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_scan_format()

static void encode_scan_format ( VC2EncContext s)
static

Definition at line 296 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_frame_rate()

static void encode_frame_rate ( VC2EncContext s)
static

Definition at line 304 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_aspect_ratio()

static void encode_aspect_ratio ( VC2EncContext s)
static

Definition at line 316 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_clean_area()

static void encode_clean_area ( VC2EncContext s)
static

Definition at line 328 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_signal_range()

static void encode_signal_range ( VC2EncContext s)
static

Definition at line 334 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_color_spec()

static void encode_color_spec ( VC2EncContext s)
static

Definition at line 342 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_source_params()

static void encode_source_params ( VC2EncContext s)
static

Definition at line 387 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_seq_header()

static void encode_seq_header ( VC2EncContext s)
static

Definition at line 400 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_picture_header()

static void encode_picture_header ( VC2EncContext s)
static

Definition at line 410 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_slice_params()

static void encode_slice_params ( VC2EncContext s)
static

Definition at line 417 of file vc2enc.c.

Referenced by encode_transform_params().

◆ init_quant_matrix()

static void init_quant_matrix ( VC2EncContext s)
static

Definition at line 442 of file vc2enc.c.

Referenced by calc_slice_sizes().

◆ encode_quant_matrix()

static void encode_quant_matrix ( VC2EncContext s)
static

Definition at line 484 of file vc2enc.c.

Referenced by encode_transform_params().

◆ encode_transform_params()

static void encode_transform_params ( VC2EncContext s)
static

Definition at line 499 of file vc2enc.c.

Referenced by encode_wavelet_transform().

◆ encode_wavelet_transform()

static void encode_wavelet_transform ( VC2EncContext s)
static

Definition at line 509 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_picture_start()

static void encode_picture_start ( VC2EncContext s)
static

Definition at line 516 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_subband()

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

Definition at line 527 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 553 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 615 of file vc2enc.c.

Referenced by calc_slice_sizes().

◆ calc_slice_sizes()

static int calc_slice_sizes ( VC2EncContext s)
static

Definition at line 643 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_hq_slice()

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

Definition at line 721 of file vc2enc.c.

Referenced by encode_slices().

◆ encode_slices()

static int encode_slices ( VC2EncContext s)
static

Definition at line 777 of file vc2enc.c.

Referenced by encode_frame().

◆ dwt_plane()

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

Definition at line 838 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 895 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 949 of file vc2enc.c.

◆ vc2_encode_end()

static av_cold int vc2_encode_end ( AVCodecContext avctx)
static

Definition at line 1004 of file vc2enc.c.

Referenced by vc2_encode_init().

◆ vc2_encode_init()

static av_cold int vc2_encode_init ( AVCodecContext avctx)
static

Definition at line 1021 of file vc2enc.c.

Variable Documentation

◆ base_video_fmts

const VC2BaseVideoFormat base_video_fmts[]
static

Definition at line 45 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 76 of file vc2enc.c.

Referenced by vc2_encode_init().

◆ vc2_qm_col_tab

const uint8_t vc2_qm_col_tab[][4]
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 426 of file vc2enc.c.

Referenced by init_quant_matrix().

◆ vc2_qm_flat_tab

const uint8_t vc2_qm_flat_tab[][4]
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 434 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, "tolerance"},
{"slice_width", "Slice width", 0x42, AV_OPT_TYPE_INT, {.i64 = 32}, 32, 1024, VC2ENC_FLAGS, "slice_width"},
{"slice_height", "Slice height", 0x42, AV_OPT_TYPE_INT, {.i64 = 16}, 8, 1024, VC2ENC_FLAGS, "slice_height"},
{"wavelet_depth", "Transform depth", 0x42, AV_OPT_TYPE_INT, {.i64 = 4}, 1, 5, VC2ENC_FLAGS, "wavelet_depth"},
{"wavelet_type", "Transform type", 0x42, AV_OPT_TYPE_INT, {.i64 = VC2_TRANSFORM_9_7}, 0, VC2_TRANSFORMS_NB, VC2ENC_FLAGS, "wavelet_idx"},
{"9_7", "Deslauriers-Dubuc (9,7)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_9_7}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
{"5_3", "LeGall (5,3)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_5_3}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
{"haar", "Haar (with shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR_S}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
{"haar_noshift", "Haar (without shift)", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_TRANSFORM_HAAR}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "wavelet_idx"},
{"qm", "Custom quantization matrix", 0x42, AV_OPT_TYPE_INT, {.i64 = VC2_QM_DEF}, 0, VC2_QM_NB, VC2ENC_FLAGS, "quant_matrix"},
{"default", "Default from the specifications", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_DEF}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "quant_matrix"},
{"color", "Prevents low bitrate discoloration", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_COL}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "quant_matrix"},
{"flat", "Optimize for PSNR", 0, AV_OPT_TYPE_CONST, {.i64 = VC2_QM_FLAT}, INT_MIN, INT_MAX, VC2ENC_FLAGS, "quant_matrix"},
{NULL}
}

Definition at line 1193 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 1210 of file vc2enc.c.

◆ vc2enc_defaults

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

Definition at line 1218 of file vc2enc.c.

◆ allowed_pix_fmts

enum AVPixelFormat allowed_pix_fmts[]
static

◆ ff_vc2_encoder

AVCodec ff_vc2_encoder
Initial value:
= {
.name = "vc2",
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-2"),
.priv_data_size = sizeof(VC2EncContext),
.close = vc2_encode_end,
.capabilities = AV_CODEC_CAP_SLICE_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
.encode2 = vc2_encode_frame,
.priv_class = &vc2enc_class,
}

Definition at line 1230 of file vc2enc.c.

FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
VC2_TRANSFORM_9_7
@ VC2_TRANSFORM_9_7
Definition: vc2enc_dwt.h:31
AV_CODEC_ID_DIRAC
@ AV_CODEC_ID_DIRAC
Definition: avcodec.h:334
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
vc2_encode_frame
static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Definition: vc2enc.c:949
VC2_QM_NB
@ VC2_QM_NB
Definition: vc2enc.c:83
VC2_TRANSFORMS_NB
@ VC2_TRANSFORMS_NB
Definition: vc2enc_dwt.h:39
VC2_QM_FLAT
@ VC2_QM_FLAT
Definition: vc2enc.c:81
defaults
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
vc2enc_class
static const AVClass vc2enc_class
Definition: vc2enc.c:1210
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
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:66
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:1193
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
VC2_QM_COL
@ VC2_QM_COL
Definition: vc2enc.c:80
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
allowed_pix_fmts
static enum AVPixelFormat allowed_pix_fmts[]
Definition: vc2enc.c:1223
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
vc2_encode_init
static av_cold int vc2_encode_init(AVCodecContext *avctx)
Definition: vc2enc.c:1021
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:1041
vc2enc_defaults
static const AVCodecDefault vc2enc_defaults[]
Definition: vc2enc.c:1218
vc2_encode_end
static av_cold int vc2_encode_end(AVCodecContext *avctx)
Definition: vc2enc.c:1004
VC2EncContext
Definition: vc2enc.c:124
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
VC2_TRANSFORM_HAAR
@ VC2_TRANSFORM_HAAR
Definition: vc2enc_dwt.h:34
VC2ENC_FLAGS
#define VC2ENC_FLAGS
Definition: vc2enc.c:1192
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:71
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:70
VC2_QM_DEF
@ VC2_QM_DEF
Definition: vc2enc.c:79
AV_CLASS_CATEGORY_ENCODER
@ AV_CLASS_CATEGORY_ENCODER
Definition: log.h:35
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
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