FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vc2enc.c File Reference
#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 (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)
 
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 35 of file vc2enc.c.

◆ SLICE_REDIST_TOTAL

#define SLICE_REDIST_TOTAL   150

Definition at line 38 of file vc2enc.c.

◆ QUANT

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

Definition at line 526 of file vc2enc.c.

◆ VC2ENC_FLAGS

#define VC2ENC_FLAGS   (AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)

Definition at line 1189 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 80 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 213 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 230 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_parse_params()

static void encode_parse_params ( VC2EncContext s)
static

Definition at line 262 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_frame_size()

static void encode_frame_size ( VC2EncContext s)
static

Definition at line 271 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_sample_fmt()

static void encode_sample_fmt ( VC2EncContext s)
static

Definition at line 282 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_scan_format()

static void encode_scan_format ( VC2EncContext s)
static

Definition at line 298 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_frame_rate()

static void encode_frame_rate ( VC2EncContext s)
static

Definition at line 306 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_aspect_ratio()

static void encode_aspect_ratio ( VC2EncContext s)
static

Definition at line 318 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_clean_area()

static void encode_clean_area ( VC2EncContext s)
static

Definition at line 330 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_signal_range()

static void encode_signal_range ( VC2EncContext s)
static

Definition at line 336 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_color_spec()

static void encode_color_spec ( VC2EncContext s)
static

Definition at line 344 of file vc2enc.c.

Referenced by encode_source_params().

◆ encode_source_params()

static void encode_source_params ( VC2EncContext s)
static

Definition at line 389 of file vc2enc.c.

Referenced by encode_seq_header().

◆ encode_seq_header()

static void encode_seq_header ( VC2EncContext s)
static

Definition at line 402 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_picture_header()

static void encode_picture_header ( VC2EncContext s)
static

Definition at line 412 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_slice_params()

static void encode_slice_params ( VC2EncContext s)
static

Definition at line 419 of file vc2enc.c.

Referenced by encode_transform_params().

◆ init_quant_matrix()

static void init_quant_matrix ( VC2EncContext s)
static

Definition at line 444 of file vc2enc.c.

Referenced by calc_slice_sizes().

◆ encode_quant_matrix()

static void encode_quant_matrix ( VC2EncContext s)
static

Definition at line 486 of file vc2enc.c.

Referenced by encode_transform_params().

◆ encode_transform_params()

static void encode_transform_params ( VC2EncContext s)
static

Definition at line 501 of file vc2enc.c.

Referenced by encode_wavelet_transform().

◆ encode_wavelet_transform()

static void encode_wavelet_transform ( VC2EncContext s)
static

Definition at line 511 of file vc2enc.c.

Referenced by encode_picture_start().

◆ encode_picture_start()

static void encode_picture_start ( VC2EncContext s)
static

Definition at line 518 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 529 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 555 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 617 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 645 of file vc2enc.c.

Referenced by encode_frame().

◆ encode_hq_slice()

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

Definition at line 723 of file vc2enc.c.

Referenced by encode_slices().

◆ encode_slices()

static int encode_slices ( VC2EncContext s)
static

Definition at line 779 of file vc2enc.c.

Referenced by encode_frame().

◆ dwt_plane()

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

Definition at line 839 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 898 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 951 of file vc2enc.c.

◆ vc2_encode_end()

static av_cold int vc2_encode_end ( AVCodecContext avctx)
static

Definition at line 1006 of file vc2enc.c.

◆ vc2_encode_init()

static av_cold int vc2_encode_init ( AVCodecContext avctx)
static

Definition at line 1023 of file vc2enc.c.

Variable Documentation

◆ base_video_fmts

const VC2BaseVideoFormat base_video_fmts[]
static

Definition at line 47 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 78 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 428 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 436 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 1190 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 1207 of file vc2enc.c.

◆ vc2enc_defaults

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

Definition at line 1215 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 1227 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:42
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
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:431
vc2_encode_frame
static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
Definition: vc2enc.c:951
VC2_QM_NB
@ VC2_QM_NB
Definition: vc2enc.c:85
VC2_TRANSFORMS_NB
@ VC2_TRANSFORMS_NB
Definition: vc2enc_dwt.h:39
VC2_QM_FLAT
@ VC2_QM_FLAT
Definition: vc2enc.c:83
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:307
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:434
vc2enc_class
static const AVClass vc2enc_class
Definition: vc2enc.c:1207
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:363
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
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:264
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:1190
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:82
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:432
allowed_pix_fmts
static enum AVPixelFormat allowed_pix_fmts[]
Definition: vc2enc.c:1220
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:436
vc2_encode_init
static av_cold int vc2_encode_init(AVCodecContext *avctx)
Definition: vc2enc.c:1023
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:438
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:117
vc2_encode_end
static av_cold int vc2_encode_end(AVCodecContext *avctx)
Definition: vc2enc.c:1006
vc2enc_defaults
static const FFCodecDefault vc2enc_defaults[]
Definition: vc2enc.c:1215
VC2EncContext
Definition: vc2enc.c:126
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:435
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
VC2_TRANSFORM_HAAR
@ VC2_TRANSFORM_HAAR
Definition: vc2enc_dwt.h:34
VC2ENC_FLAGS
#define VC2ENC_FLAGS
Definition: vc2enc.c:1189
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:81
AV_CLASS_CATEGORY_ENCODER
@ AV_CLASS_CATEGORY_ENCODER
Definition: log.h:34
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
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