FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
proresenc_kostya.c File Reference
#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "fdctdsp.h"
#include "put_bits.h"
#include "profiles.h"
#include "bytestream.h"
#include "proresdata.h"

Go to the source code of this file.

Data Structures

struct  prores_profile
 
struct  TrellisNode
 
struct  ProresThreadData
 
struct  ProresContext
 

Macros

#define CFACTOR_Y422   2
 
#define CFACTOR_Y444   3
 
#define MAX_MBS_PER_SLICE   8
 
#define MAX_PLANES   4
 
#define NUM_MB_LIMITS   4
 
#define TRELLIS_WIDTH   16
 
#define SCORE_LIMIT   INT_MAX / 2
 
#define MAX_STORED_Q   16
 
#define GET_SIGN(x)   ((x) >> 31)
 
#define MAKE_CODE(x)   ((((x)) * 2) ^ GET_SIGN(x))
 
#define OFFSET(x)   offsetof(ProresContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  {
  PRORES_PROFILE_AUTO = -1, PRORES_PROFILE_PROXY = 0, PRORES_PROFILE_LT, PRORES_PROFILE_STANDARD,
  PRORES_PROFILE_HQ, PRORES_PROFILE_4444, PRORES_PROFILE_4444XQ
}
 
enum  {
  QUANT_MAT_PROXY = 0, QUANT_MAT_PROXY_CHROMA, QUANT_MAT_LT, QUANT_MAT_STANDARD,
  QUANT_MAT_HQ, QUANT_MAT_XQ_LUMA, QUANT_MAT_DEFAULT
}
 

Functions

static void get_slice_data (ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int x, int y, int w, int h, int16_t *blocks, uint16_t *emu_buf, int mbs_per_slice, int blocks_per_mb, int is_chroma)
 
static void get_alpha_data (ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int x, int y, int w, int h, int16_t *blocks, int mbs_per_slice, int abits)
 
static void encode_vlc_codeword (PutBitContext *pb, unsigned codebook, int val)
 Write an unsigned rice/exp golomb codeword. More...
 
static void encode_dcs (PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int scale)
 
static void encode_acs (PutBitContext *pb, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat)
 
static void encode_slice_plane (ProresContext *ctx, PutBitContext *pb, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks, int blocks_per_mb, int plane_size_factor, const int16_t *qmat)
 
static void put_alpha_diff (PutBitContext *pb, int cur, int prev, int abits)
 
static void put_alpha_run (PutBitContext *pb, int run)
 
static void encode_alpha_plane (ProresContext *ctx, PutBitContext *pb, int mbs_per_slice, uint16_t *blocks, int quant)
 
static int encode_slice (AVCodecContext *avctx, const AVFrame *pic, PutBitContext *pb, int sizes[4], int x, int y, int quant, int mbs_per_slice)
 
static int estimate_vlc (unsigned codebook, int val)
 
static int estimate_dcs (int *error, int16_t *blocks, int blocks_per_slice, int scale)
 
static int estimate_acs (int *error, int16_t *blocks, int blocks_per_slice, int plane_size_factor, const uint8_t *scan, const int16_t *qmat)
 
static int estimate_slice_plane (ProresContext *ctx, int *error, int plane, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int blocks_per_mb, int plane_size_factor, const int16_t *qmat, ProresThreadData *td)
 
static int est_alpha_diff (int cur, int prev, int abits)
 
static int estimate_alpha_plane (ProresContext *ctx, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks)
 
static int find_slice_quant (AVCodecContext *avctx, int trellis_node, int x, int y, int mbs_per_slice, ProresThreadData *td)
 
static int find_quant_thread (AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
 
static av_cold int encode_close (AVCodecContext *avctx)
 
static void prores_fdct (FDCTDSPContext *fdsp, const uint16_t *src, ptrdiff_t linesize, int16_t *block)
 
static av_cold int encode_init (AVCodecContext *avctx)
 

Variables

static const uint8_t prores_quant_matrices [][64]
 
static const uint8_t prores_dc_codebook [4]
 
static const uint8_t prores_ac_codebook [7]
 
static const uint8_t prores_run_to_cb_index [16]
 Lookup tables for adaptive switching between codebooks according with previous run/level value. More...
 
static const uint8_t prores_lev_to_cb_index [10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }
 
static const int prores_mb_limits [NUM_MB_LIMITS]
 
static const struct prores_profile prores_profile_info [6]
 
static const AVOption options []
 
static const AVClass proresenc_class
 
const FFCodec ff_prores_ks_encoder
 

Macro Definition Documentation

◆ CFACTOR_Y422

#define CFACTOR_Y422   2

Definition at line 38 of file proresenc_kostya.c.

◆ CFACTOR_Y444

#define CFACTOR_Y444   3

Definition at line 39 of file proresenc_kostya.c.

◆ MAX_MBS_PER_SLICE

#define MAX_MBS_PER_SLICE   8

Definition at line 41 of file proresenc_kostya.c.

◆ MAX_PLANES

#define MAX_PLANES   4

Definition at line 43 of file proresenc_kostya.c.

◆ NUM_MB_LIMITS

#define NUM_MB_LIMITS   4

Definition at line 164 of file proresenc_kostya.c.

◆ TRELLIS_WIDTH

#define TRELLIS_WIDTH   16

Definition at line 237 of file proresenc_kostya.c.

◆ SCORE_LIMIT

#define SCORE_LIMIT   INT_MAX / 2

Definition at line 238 of file proresenc_kostya.c.

◆ MAX_STORED_Q

#define MAX_STORED_Q   16

Definition at line 247 of file proresenc_kostya.c.

◆ GET_SIGN

#define GET_SIGN (   x)    ((x) >> 31)

Definition at line 431 of file proresenc_kostya.c.

◆ MAKE_CODE

#define MAKE_CODE (   x)    ((((x)) * 2) ^ GET_SIGN(x))

Definition at line 432 of file proresenc_kostya.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(ProresContext, x)

Definition at line 1369 of file proresenc_kostya.c.

◆ VE

Definition at line 1370 of file proresenc_kostya.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PRORES_PROFILE_AUTO 
PRORES_PROFILE_PROXY 
PRORES_PROFILE_LT 
PRORES_PROFILE_STANDARD 
PRORES_PROFILE_HQ 
PRORES_PROFILE_4444 
PRORES_PROFILE_4444XQ 

Definition at line 45 of file proresenc_kostya.c.

◆ anonymous enum

anonymous enum
Enumerator
QUANT_MAT_PROXY 
QUANT_MAT_PROXY_CHROMA 
QUANT_MAT_LT 
QUANT_MAT_STANDARD 
QUANT_MAT_HQ 
QUANT_MAT_XQ_LUMA 
QUANT_MAT_DEFAULT 

Definition at line 55 of file proresenc_kostya.c.

Function Documentation

◆ get_slice_data()

static void get_slice_data ( ProresContext ctx,
const uint16_t *  src,
ptrdiff_t  linesize,
int  x,
int  y,
int  w,
int  h,
int16_t *  blocks,
uint16_t *  emu_buf,
int  mbs_per_slice,
int  blocks_per_mb,
int  is_chroma 
)
static

Definition at line 300 of file proresenc_kostya.c.

Referenced by encode_slice(), and find_slice_quant().

◆ get_alpha_data()

static void get_alpha_data ( ProresContext ctx,
const uint16_t *  src,
ptrdiff_t  linesize,
int  x,
int  y,
int  w,
int  h,
int16_t *  blocks,
int  mbs_per_slice,
int  abits 
)
static

Definition at line 371 of file proresenc_kostya.c.

Referenced by encode_slice(), and find_slice_quant().

◆ encode_vlc_codeword()

static void encode_vlc_codeword ( PutBitContext pb,
unsigned  codebook,
int  val 
)
inlinestatic

Write an unsigned rice/exp golomb codeword.

Definition at line 402 of file proresenc_kostya.c.

Referenced by encode_acs(), and encode_dcs().

◆ encode_dcs()

static void encode_dcs ( PutBitContext pb,
int16_t *  blocks,
int  blocks_per_slice,
int  scale 
)
static

Definition at line 434 of file proresenc_kostya.c.

Referenced by encode_slice_plane().

◆ encode_acs()

static void encode_acs ( PutBitContext pb,
int16_t *  blocks,
int  blocks_per_slice,
int  plane_size_factor,
const uint8_t *  scan,
const int16_t *  qmat 
)
static

Definition at line 460 of file proresenc_kostya.c.

Referenced by encode_slice_plane().

◆ encode_slice_plane()

static void encode_slice_plane ( ProresContext ctx,
PutBitContext pb,
const uint16_t *  src,
ptrdiff_t  linesize,
int  mbs_per_slice,
int16_t *  blocks,
int  blocks_per_mb,
int  plane_size_factor,
const int16_t *  qmat 
)
static

Definition at line 494 of file proresenc_kostya.c.

Referenced by encode_slice().

◆ put_alpha_diff()

static void put_alpha_diff ( PutBitContext pb,
int  cur,
int  prev,
int  abits 
)
static

Definition at line 507 of file proresenc_kostya.c.

Referenced by encode_alpha_plane().

◆ put_alpha_run()

static void put_alpha_run ( PutBitContext pb,
int  run 
)
static

Definition at line 526 of file proresenc_kostya.c.

Referenced by encode_alpha_plane().

◆ encode_alpha_plane()

static void encode_alpha_plane ( ProresContext ctx,
PutBitContext pb,
int  mbs_per_slice,
uint16_t *  blocks,
int  quant 
)
static

Definition at line 540 of file proresenc_kostya.c.

Referenced by encode_slice().

◆ encode_slice()

static int encode_slice ( AVCodecContext avctx,
const AVFrame pic,
PutBitContext pb,
int  sizes[4],
int  x,
int  y,
int  quant,
int  mbs_per_slice 
)
static

Definition at line 569 of file proresenc_kostya.c.

Referenced by encode_frame().

◆ estimate_vlc()

static int estimate_vlc ( unsigned  codebook,
int  val 
)
inlinestatic

Definition at line 653 of file proresenc_kostya.c.

Referenced by estimate_acs(), and estimate_dcs().

◆ estimate_dcs()

static int estimate_dcs ( int error,
int16_t *  blocks,
int  blocks_per_slice,
int  scale 
)
static

Definition at line 675 of file proresenc_kostya.c.

Referenced by estimate_slice_plane().

◆ estimate_acs()

static int estimate_acs ( int error,
int16_t *  blocks,
int  blocks_per_slice,
int  plane_size_factor,
const uint8_t *  scan,
const int16_t *  qmat 
)
static

Definition at line 706 of file proresenc_kostya.c.

Referenced by estimate_slice_plane().

◆ estimate_slice_plane()

static int estimate_slice_plane ( ProresContext ctx,
int error,
int  plane,
const uint16_t *  src,
ptrdiff_t  linesize,
int  mbs_per_slice,
int  blocks_per_mb,
int  plane_size_factor,
const int16_t *  qmat,
ProresThreadData td 
)
static

Definition at line 742 of file proresenc_kostya.c.

Referenced by find_slice_quant().

◆ est_alpha_diff()

static int est_alpha_diff ( int  cur,
int  prev,
int  abits 
)
static

Definition at line 760 of file proresenc_kostya.c.

Referenced by estimate_alpha_plane().

◆ estimate_alpha_plane()

static int estimate_alpha_plane ( ProresContext ctx,
const uint16_t *  src,
ptrdiff_t  linesize,
int  mbs_per_slice,
int16_t *  blocks 
)
static

Definition at line 775 of file proresenc_kostya.c.

Referenced by find_slice_quant().

◆ find_slice_quant()

static int find_slice_quant ( AVCodecContext avctx,
int  trellis_node,
int  x,
int  y,
int  mbs_per_slice,
ProresThreadData td 
)
static

Definition at line 817 of file proresenc_kostya.c.

Referenced by find_quant_thread().

◆ find_quant_thread()

static int find_quant_thread ( AVCodecContext avctx,
void *  arg,
int  jobnr,
int  threadnr 
)
static

Definition at line 986 of file proresenc_kostya.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pic,
int got_packet 
)
static

Definition at line 1010 of file proresenc_kostya.c.

◆ encode_close()

static av_cold int encode_close ( AVCodecContext avctx)
static

Definition at line 1170 of file proresenc_kostya.c.

◆ prores_fdct()

static void prores_fdct ( FDCTDSPContext fdsp,
const uint16_t *  src,
ptrdiff_t  linesize,
int16_t *  block 
)
static

Definition at line 1185 of file proresenc_kostya.c.

Referenced by encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext avctx)
static

Definition at line 1199 of file proresenc_kostya.c.

Variable Documentation

◆ prores_quant_matrices

const uint8_t prores_quant_matrices[][64]
static

Definition at line 65 of file proresenc_kostya.c.

Referenced by encode_init().

◆ prores_dc_codebook

const uint8_t prores_dc_codebook[4]
static
Initial value:
= {
0x04,
0x28,
0x4D,
0x70
}

Definition at line 138 of file proresenc_kostya.c.

Referenced by encode_dcs(), and estimate_dcs().

◆ prores_ac_codebook

const uint8_t prores_ac_codebook[7]
static
Initial value:
= {
0x04,
0x28,
0x4C,
0x05,
0x29,
0x06,
0x0A,
}

Definition at line 145 of file proresenc_kostya.c.

Referenced by encode_acs(), and estimate_acs().

◆ prores_run_to_cb_index

const uint8_t prores_run_to_cb_index[16]
static
Initial value:
=
{ 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }

Lookup tables for adaptive switching between codebooks according with previous run/level value.

Definition at line 159 of file proresenc_kostya.c.

Referenced by encode_acs(), and estimate_acs().

◆ prores_lev_to_cb_index

const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }
static

Definition at line 162 of file proresenc_kostya.c.

Referenced by encode_acs(), and estimate_acs().

◆ prores_mb_limits

const int prores_mb_limits[NUM_MB_LIMITS]
static
Initial value:
= {
1620,
2700,
6075,
9216,
}

Definition at line 165 of file proresenc_kostya.c.

Referenced by encode_init().

◆ prores_profile_info

const struct prores_profile prores_profile_info[6]
static

Referenced by encode_init().

◆ options

const AVOption options[]
static

Definition at line 1372 of file proresenc_kostya.c.

◆ proresenc_class

const AVClass proresenc_class
static
Initial value:
= {
.class_name = "ProRes encoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1415 of file proresenc_kostya.c.

◆ ff_prores_ks_encoder

const FFCodec ff_prores_ks_encoder
Initial value:
= {
.p.name = "prores_ks",
CODEC_LONG_NAME("Apple ProRes (iCodec Pro)"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(ProresContext),
.close = encode_close,
.p.pix_fmts = (const enum AVPixelFormat[]) {
},
.p.priv_class = &proresenc_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1422 of file proresenc_kostya.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
Definition: proresenc_kostya.c:1010
ff_prores_profiles
const AVProfile ff_prores_profiles[]
Definition: profiles.c:159
ProresContext
Definition: proresdec.h:38
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:462
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
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:156
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:107
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: proresenc_kostya.c:1199
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:460
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:115
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:111
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:498
options
static const AVOption options[]
Definition: proresenc_kostya.c:1372
proresenc_class
static const AVClass proresenc_class
Definition: proresenc_kostya.c:1415
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: proresenc_kostya.c:1170
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200