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

Go to the source code of this file.

Data Structures

struct  ProresContext
 

Macros

#define DEFAULT_SLICE_MB_WIDTH   8
 
#define QSCALE(qmat, ind, val)   ((val) / ((qmat)[ind]))
 
#define TO_GOLOMB(val)   (((val) * 2) ^ ((val) >> 31))
 
#define DIFF_SIGN(val, sign)   (((val) >> 31) ^ (sign))
 
#define IS_NEGATIVE(val)   ((((val) >> 31) ^ -1) + 1)
 
#define TO_GOLOMB2(val, sign)   ((val)==0 ? 0 : ((val) << 1) + (sign))
 
#define FIRST_DC_CB   0xB8
 
#define OFFSET(x)   offsetof(ProresContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void encode_codeword (PutBitContext *pb, int val, int codebook)
 
static av_always_inline int get_level (int val)
 
static void encode_dc_coeffs (PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat)
 
static void encode_ac_coeffs (PutBitContext *pb, int16_t *in, int blocks_per_slice, int *qmat, const uint8_t ff_prores_scan[64])
 
static void get (uint8_t *pixels, int stride, int16_t *block)
 
static void fdct_get (FDCTDSPContext *fdsp, uint8_t *pixels, int stride, int16_t *block)
 
static void calc_plane_dct (FDCTDSPContext *fdsp, uint8_t *src, int16_t *blocks, int src_stride, int mb_count, int chroma, int is_422)
 
static int encode_slice_plane (int16_t *blocks, int mb_count, uint8_t *buf, unsigned buf_size, int *qmat, int sub_sample_chroma, const uint8_t ff_prores_scan[64])
 
static av_always_inline unsigned encode_slice_data (AVCodecContext *avctx, int16_t *blocks_y, int16_t *blocks_u, int16_t *blocks_v, unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned *y_data_size, unsigned *u_data_size, unsigned *v_data_size, int qp)
 
static void put_alpha_diff (PutBitContext *pb, int cur, int prev)
 
static void put_alpha_run (PutBitContext *pb, int run)
 
static av_always_inline int encode_alpha_slice_data (AVCodecContext *avctx, int8_t *src_a, unsigned mb_count, uint8_t *buf, unsigned data_size, unsigned *a_data_size)
 
static void subimage_with_fill_template (uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_alpha_plane, int is_interlaced, int is_top_field)
 
static void subimage_with_fill (uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
 
static void subimage_alpha_with_fill (uint16_t *src, unsigned x, unsigned y, unsigned stride, unsigned width, unsigned height, uint16_t *dst, unsigned dst_width, unsigned dst_height, int is_interlaced, int is_top_field)
 
static int encode_slice (AVCodecContext *avctx, const AVFrame *pic, int mb_x, int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size, int unsafe, int *qp, int is_interlaced, int is_top_field)
 
static int prores_encode_picture (AVCodecContext *avctx, const AVFrame *pic, uint8_t *buf, const int buf_size, const int picture_index, const int is_top_field)
 
static int prores_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static void scale_mat (const uint8_t *src, int *dst, int scale)
 
static av_cold int prores_encode_init (AVCodecContext *avctx)
 
static av_cold int prores_encode_close (AVCodecContext *avctx)
 

Variables

static const AVProfile profiles []
 
static const int qp_start_table [] = { 8, 3, 2, 1, 1, 1}
 
static const int qp_end_table [] = { 13, 9, 6, 6, 5, 4}
 
static const int bitrate_table [] = { 1000, 2100, 3500, 5400, 7000, 10000}
 
static const int valid_primaries []
 
static const int valid_trc []
 
static const int valid_colorspace []
 
static const uint8_t QMAT_LUMA [6][64]
 
static const uint8_t QMAT_CHROMA [6][64]
 
static const uint8_t dc_codebook [7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}
 
static const uint8_t run_to_cb [16]
 
static const uint8_t lev_to_cb [10]
 
static const AVOption options []
 
static const AVClass prores_enc_class
 
static enum AVPixelFormat pix_fmts []
 
const FFCodec ff_prores_aw_encoder
 
const FFCodec ff_prores_encoder
 

Detailed Description

Apple ProRes encoder (Anatoliy Wasserman version) Known FOURCCs: 'ap4h' (444), 'apch' (HQ), 'apcn' (422), 'apcs' (LT), 'acpo' (Proxy)

Definition in file proresenc_anatoliy.c.

Macro Definition Documentation

◆ DEFAULT_SLICE_MB_WIDTH

#define DEFAULT_SLICE_MB_WIDTH   8

Definition at line 43 of file proresenc_anatoliy.c.

◆ QSCALE

#define QSCALE (   qmat,
  ind,
  val 
)    ((val) / ((qmat)[ind]))

Definition at line 230 of file proresenc_anatoliy.c.

◆ TO_GOLOMB

#define TO_GOLOMB (   val)    (((val) * 2) ^ ((val) >> 31))

Definition at line 231 of file proresenc_anatoliy.c.

◆ DIFF_SIGN

#define DIFF_SIGN (   val,
  sign 
)    (((val) >> 31) ^ (sign))

Definition at line 232 of file proresenc_anatoliy.c.

◆ IS_NEGATIVE

#define IS_NEGATIVE (   val)    ((((val) >> 31) ^ -1) + 1)

Definition at line 233 of file proresenc_anatoliy.c.

◆ TO_GOLOMB2

#define TO_GOLOMB2 (   val,
  sign 
)    ((val)==0 ? 0 : ((val) << 1) + (sign))

Definition at line 234 of file proresenc_anatoliy.c.

◆ FIRST_DC_CB

#define FIRST_DC_CB   0xB8

Definition at line 242 of file proresenc_anatoliy.c.

◆ OFFSET

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

Definition at line 923 of file proresenc_anatoliy.c.

◆ VE

Definition at line 924 of file proresenc_anatoliy.c.

Function Documentation

◆ encode_codeword()

static void encode_codeword ( PutBitContext pb,
int  val,
int  codebook 
)
static

Definition at line 202 of file proresenc_anatoliy.c.

Referenced by encode_ac_coeffs(), and encode_dc_coeffs().

◆ get_level()

static av_always_inline int get_level ( int  val)
static

Definition at line 236 of file proresenc_anatoliy.c.

Referenced by encode_ac_coeffs(), and encode_dc_coeffs().

◆ encode_dc_coeffs()

static void encode_dc_coeffs ( PutBitContext pb,
int16_t *  in,
int  blocks_per_slice,
int qmat 
)
static

Definition at line 246 of file proresenc_anatoliy.c.

Referenced by encode_slice_plane().

◆ encode_ac_coeffs()

static void encode_ac_coeffs ( PutBitContext pb,
int16_t *  in,
int  blocks_per_slice,
int qmat,
const uint8_t  ff_prores_scan[64] 
)
static

Definition at line 277 of file proresenc_anatoliy.c.

Referenced by encode_slice_plane().

◆ get()

static void get ( uint8_t *  pixels,
int  stride,
int16_t *  block 
)
static

◆ fdct_get()

static void fdct_get ( FDCTDSPContext fdsp,
uint8_t *  pixels,
int  stride,
int16_t *  block 
)
static

Definition at line 320 of file proresenc_anatoliy.c.

Referenced by calc_plane_dct().

◆ calc_plane_dct()

static void calc_plane_dct ( FDCTDSPContext fdsp,
uint8_t *  src,
int16_t *  blocks,
int  src_stride,
int  mb_count,
int  chroma,
int  is_422 
)
static

Definition at line 326 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ encode_slice_plane()

static int encode_slice_plane ( int16_t *  blocks,
int  mb_count,
uint8_t *  buf,
unsigned  buf_size,
int qmat,
int  sub_sample_chroma,
const uint8_t  ff_prores_scan[64] 
)
static

Definition at line 363 of file proresenc_anatoliy.c.

Referenced by encode_slice_data().

◆ encode_slice_data()

static av_always_inline unsigned encode_slice_data ( AVCodecContext avctx,
int16_t *  blocks_y,
int16_t *  blocks_u,
int16_t *  blocks_v,
unsigned  mb_count,
uint8_t *  buf,
unsigned  data_size,
unsigned *  y_data_size,
unsigned *  u_data_size,
unsigned *  v_data_size,
int  qp 
)
static

Definition at line 379 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ put_alpha_diff()

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

Definition at line 402 of file proresenc_anatoliy.c.

Referenced by encode_alpha_slice_data().

◆ put_alpha_run()

static void put_alpha_run ( PutBitContext pb,
int  run 
)
inlinestatic

Definition at line 422 of file proresenc_anatoliy.c.

Referenced by encode_alpha_slice_data().

◆ encode_alpha_slice_data()

static av_always_inline int encode_alpha_slice_data ( AVCodecContext avctx,
int8_t *  src_a,
unsigned  mb_count,
uint8_t *  buf,
unsigned  data_size,
unsigned *  a_data_size 
)
static

Definition at line 435 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ subimage_with_fill_template()

static void subimage_with_fill_template ( uint16_t *  src,
unsigned  x,
unsigned  y,
unsigned  stride,
unsigned  width,
unsigned  height,
uint16_t *  dst,
unsigned  dst_width,
unsigned  dst_height,
int  is_alpha_plane,
int  is_interlaced,
int  is_top_field 
)
inlinestatic

Definition at line 476 of file proresenc_anatoliy.c.

Referenced by subimage_alpha_with_fill(), and subimage_with_fill().

◆ subimage_with_fill()

static void subimage_with_fill ( uint16_t *  src,
unsigned  x,
unsigned  y,
unsigned  stride,
unsigned  width,
unsigned  height,
uint16_t *  dst,
unsigned  dst_width,
unsigned  dst_height,
int  is_interlaced,
int  is_top_field 
)
static

Definition at line 524 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ subimage_alpha_with_fill()

static void subimage_alpha_with_fill ( uint16_t *  src,
unsigned  x,
unsigned  y,
unsigned  stride,
unsigned  width,
unsigned  height,
uint16_t *  dst,
unsigned  dst_width,
unsigned  dst_height,
int  is_interlaced,
int  is_top_field 
)
static

Definition at line 532 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ encode_slice()

static int encode_slice ( AVCodecContext avctx,
const AVFrame pic,
int  mb_x,
int  mb_y,
unsigned  mb_count,
uint8_t *  buf,
unsigned  data_size,
int  unsafe,
int qp,
int  is_interlaced,
int  is_top_field 
)
static

Definition at line 539 of file proresenc_anatoliy.c.

Referenced by prores_encode_picture().

◆ prores_encode_picture()

static int prores_encode_picture ( AVCodecContext avctx,
const AVFrame pic,
uint8_t *  buf,
const int  buf_size,
const int  picture_index,
const int  is_top_field 
)
static

Definition at line 657 of file proresenc_anatoliy.c.

Referenced by prores_encode_frame().

◆ prores_encode_frame()

static int prores_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pict,
int got_packet 
)
static

Definition at line 721 of file proresenc_anatoliy.c.

◆ scale_mat()

static void scale_mat ( const uint8_t *  src,
int dst,
int  scale 
)
static

Definition at line 805 of file proresenc_anatoliy.c.

Referenced by prores_encode_init().

◆ prores_encode_init()

static av_cold int prores_encode_init ( AVCodecContext avctx)
static

Definition at line 812 of file proresenc_anatoliy.c.

◆ prores_encode_close()

static av_cold int prores_encode_close ( AVCodecContext avctx)
static

Definition at line 914 of file proresenc_anatoliy.c.

Variable Documentation

◆ profiles

const AVProfile profiles[]
static
Initial value:

Definition at line 45 of file proresenc_anatoliy.c.

Referenced by prores_encode_init().

◆ qp_start_table

const int qp_start_table[] = { 8, 3, 2, 1, 1, 1}
static

Definition at line 55 of file proresenc_anatoliy.c.

Referenced by encode_slice(), and prores_encode_picture().

◆ qp_end_table

const int qp_end_table[] = { 13, 9, 6, 6, 5, 4}
static

Definition at line 56 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ bitrate_table

const int bitrate_table[] = { 1000, 2100, 3500, 5400, 7000, 10000}
static

Definition at line 57 of file proresenc_anatoliy.c.

Referenced by encode_slice().

◆ valid_primaries

const int valid_primaries[]
static

◆ valid_trc

const int valid_trc[]
static

◆ valid_colorspace

const int valid_colorspace[]
static
Initial value:

Definition at line 63 of file proresenc_anatoliy.c.

Referenced by prores_encode_frame().

◆ QMAT_LUMA

const uint8_t QMAT_LUMA[6][64]
static

Definition at line 66 of file proresenc_anatoliy.c.

Referenced by prores_encode_frame(), and prores_encode_init().

◆ QMAT_CHROMA

const uint8_t QMAT_CHROMA[6][64]
static

Definition at line 124 of file proresenc_anatoliy.c.

Referenced by prores_encode_frame(), and prores_encode_init().

◆ dc_codebook

const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}
static

Definition at line 244 of file proresenc_anatoliy.c.

Referenced by encode_dc_coeffs().

◆ run_to_cb

const uint8_t run_to_cb[16]
static
Initial value:
= { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29,
0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C }

Definition at line 272 of file proresenc_anatoliy.c.

Referenced by encode_ac_coeffs().

◆ lev_to_cb

const uint8_t lev_to_cb[10]
static
Initial value:
= { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28,
0x28, 0x28, 0x28, 0x4C }

Definition at line 274 of file proresenc_anatoliy.c.

Referenced by encode_ac_coeffs().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "vendor", "vendor ID", OFFSET(vendor), AV_OPT_TYPE_STRING, { .str = "fmpg" }, 0, 0, VE },
{ NULL }
}

Definition at line 926 of file proresenc_anatoliy.c.

◆ prores_enc_class

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

Definition at line 931 of file proresenc_anatoliy.c.

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ ff_prores_aw_encoder

const FFCodec ff_prores_aw_encoder
Initial value:
= {
.p.name = "prores_aw",
.p.long_name = NULL_IF_CONFIG_SMALL("Apple ProRes"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.pix_fmts = pix_fmts,
.priv_data_size = sizeof(ProresContext),
.p.capabilities = AV_CODEC_CAP_FRAME_THREADS,
.p.priv_class = &prores_enc_class,
}

Definition at line 943 of file proresenc_anatoliy.c.

◆ ff_prores_encoder

const FFCodec ff_prores_encoder
Initial value:
= {
.p.name = "prores",
.p.long_name = NULL_IF_CONFIG_SMALL("Apple ProRes"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.pix_fmts = pix_fmts,
.priv_data_size = sizeof(ProresContext),
.p.capabilities = AV_CODEC_CAP_FRAME_THREADS,
.p.priv_class = &prores_enc_class,
}

Definition at line 959 of file proresenc_anatoliy.c.

FF_PROFILE_PRORES_XQ
#define FF_PROFILE_PRORES_XQ
Definition: avcodec.h:1660
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:39
ff_prores_profiles
const AVProfile ff_prores_profiles[]
Definition: profiles.c:159
options
static const AVOption options[]
Definition: proresenc_anatoliy.c:926
prores_enc_class
static const AVClass prores_enc_class
Definition: proresenc_anatoliy.c:931
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:499
ProresContext
Definition: proresdec.h:38
VE
#define VE
Definition: proresenc_anatoliy.c:924
prores_encode_init
static av_cold int prores_encode_init(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:812
init
static int init
Definition: av_tx.c:47
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:263
FF_PROFILE_PRORES_LT
#define FF_PROFILE_PRORES_LT
Definition: avcodec.h:1656
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:409
AVCOL_PRI_RESERVED0
@ AVCOL_PRI_RESERVED0
Definition: pixfmt.h:472
prores_encode_frame
static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: proresenc_anatoliy.c:721
prores_encode_close
static av_cold int prores_encode_close(AVCodecContext *avctx)
Definition: proresenc_anatoliy.c:914
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:532
FF_PROFILE_UNKNOWN
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1548
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: proresenc_anatoliy.c:938
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:474
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:478
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:479
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:113
AVCOL_TRC_RESERVED0
@ AVCOL_TRC_RESERVED0
Definition: pixfmt.h:497
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:473
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:407
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:482
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:513
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:485
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:117
FF_PROFILE_PRORES_HQ
#define FF_PROFILE_PRORES_HQ
Definition: avcodec.h:1658
FF_PROFILE_PRORES_STANDARD
#define FF_PROFILE_PRORES_STANDARD
Definition: avcodec.h:1657
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:445
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:498
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:536
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: codec_internal.h:31
OFFSET
#define OFFSET(x)
Definition: proresenc_anatoliy.c:923
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:528
FF_PROFILE_PRORES_4444
#define FF_PROFILE_PRORES_4444
Definition: avcodec.h:1659
FF_PROFILE_PRORES_PROXY
#define FF_PROFILE_PRORES_PROXY
Definition: avcodec.h:1655
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:517
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:486
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:527
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:198