Libav
Macros | Functions | Variables
ffv1enc.c File Reference

FF Video Codec 1 (a lossless codec) encoder. More...

#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/pixdesc.h"
#include "libavutil/crc.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "internal.h"
#include "put_bits.h"
#include "rangecoder.h"
#include "golomb.h"
#include "mathops.h"
#include "ffv1.h"

Go to the source code of this file.

Macros

#define put_rac(C, S, B)
 
#define COST(old, new)
 
#define COST2(old, new)   COST(old, new) + COST(256 - (old), 256 - (new))
 
#define STATS_OUT_SIZE   1024 * 1024 * 6
 
#define OFFSET(x)   offsetof(FFV1Context, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void find_best_state (uint8_t best_state[256][256], const uint8_t one_state[256])
 
static av_always_inline av_flatten void put_symbol_inline (RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2])
 
static av_noinline void put_symbol (RangeCoder *c, uint8_t *state, int v, int is_signed)
 
static void put_vlc_symbol (PutBitContext *pb, VlcState *const state, int v, int bits)
 
static av_always_inline int encode_line (FFV1Context *s, int w, int16_t *sample[3], int plane_index, int bits)
 
static void encode_plane (FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index)
 
static void encode_rgb_frame (FFV1Context *s, const uint8_t *src[3], int w, int h, const int stride[3])
 
static void write_quant_table (RangeCoder *c, int16_t *quant_table)
 
static void write_quant_tables (RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
 
static void write_header (FFV1Context *f)
 
static int write_extradata (FFV1Context *f)
 
static int sort_stt (FFV1Context *s, uint8_t stt[256])
 
static av_cold int init_slices_state (FFV1Context *f)
 
static av_cold int ffv1_encode_init (AVCodecContext *avctx)
 
static void encode_slice_header (FFV1Context *f, FFV1Context *fs)
 
static int encode_slice (AVCodecContext *c, void *arg)
 
static int ffv1_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int ffv1_encode_close (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
class {
      class_name = "ffv1 encoder"
 
      item_name = av_default_item_name
 
      option = options
 
      version = LIBAVUTIL_VERSION_INT
 
}; 
 
static const AVCodecDefault ffv1_defaults []
 
AVCodec ff_ffv1_encoder
 

Detailed Description

FF Video Codec 1 (a lossless codec) encoder.

Definition in file ffv1enc.c.

Macro Definition Documentation

◆ put_rac

#define put_rac (   C,
  S,
  B 
)
Value:
do { \
if (rc_stat) { \
rc_stat[*(S)][B]++; \
rc_stat2[(S) - state][B]++; \
} \
put_rac(C, S, B); \
} while (0)
#define B
Definition: huffyuv.h:49
#define S(s, c, i)
static struct @174 state

Referenced by encode_slice(), ffv1_encode_frame(), main(), put_symbol_inline(), write_extradata(), and write_header().

◆ COST

#define COST (   old,
  new 
)
Value:
s->rc_stat[old][0] * -log2((256 - (new)) / 256.0) + \
s->rc_stat[old][1] * -log2((new) / 256.0)
#define log2(x)
Definition: libm.h:111

◆ COST2

#define COST2 (   old,
  new 
)    COST(old, new) + COST(256 - (old), 256 - (new))

Referenced by sort_stt().

◆ STATS_OUT_SIZE

#define STATS_OUT_SIZE   1024 * 1024 * 6

◆ OFFSET

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

Definition at line 1068 of file ffv1enc.c.

◆ VE

Definition at line 1069 of file ffv1enc.c.

Function Documentation

◆ find_best_state()

static void find_best_state ( uint8_t  best_state[256][256],
const uint8_t  one_state[256] 
)
static

Definition at line 43 of file ffv1enc.c.

Referenced by ffv1_encode_init().

◆ put_symbol_inline()

static av_always_inline av_flatten void put_symbol_inline ( RangeCoder c,
uint8_t state,
int  v,
int  is_signed,
uint64_t  rc_stat[256][2],
uint64_t  rc_stat2[32][2] 
)
static

Definition at line 85 of file ffv1enc.c.

Referenced by encode_line(), and put_symbol().

◆ put_symbol()

static av_noinline void put_symbol ( RangeCoder c,
uint8_t state,
int  v,
int  is_signed 
)
static

Definition at line 133 of file ffv1enc.c.

Referenced by encode_slice_header(), write_extradata(), write_header(), and write_quant_table().

◆ put_vlc_symbol()

static void put_vlc_symbol ( PutBitContext pb,
VlcState *const  state,
int  v,
int  bits 
)
inlinestatic

Definition at line 139 of file ffv1enc.c.

Referenced by encode_line().

◆ encode_line()

static av_always_inline int encode_line ( FFV1Context s,
int  w,
int16_t *  sample[3],
int  plane_index,
int  bits 
)
static

Definition at line 163 of file ffv1enc.c.

Referenced by encode_plane(), and encode_rgb_frame().

◆ encode_plane()

static void encode_plane ( FFV1Context s,
uint8_t src,
int  w,
int  h,
int  stride,
int  plane_index 
)
static

Definition at line 253 of file ffv1enc.c.

Referenced by encode_slice().

◆ encode_rgb_frame()

static void encode_rgb_frame ( FFV1Context s,
const uint8_t src[3],
int  w,
int  h,
const int  stride[3] 
)
static

Definition at line 289 of file ffv1enc.c.

Referenced by encode_slice().

◆ write_quant_table()

static void write_quant_table ( RangeCoder c,
int16_t *  quant_table 
)
static

Definition at line 350 of file ffv1enc.c.

Referenced by write_quant_tables().

◆ write_quant_tables()

static void write_quant_tables ( RangeCoder c,
int16_t  quant_table[MAX_CONTEXT_INPUTS][256] 
)
static

Definition at line 365 of file ffv1enc.c.

Referenced by write_extradata(), and write_header().

◆ write_header()

static void write_header ( FFV1Context f)
static

◆ write_extradata()

static int write_extradata ( FFV1Context f)
static

Definition at line 401 of file ffv1enc.c.

Referenced by ffv1_encode_init().

◆ sort_stt()

static int sort_stt ( FFV1Context s,
uint8_t  stt[256] 
)
static

Definition at line 474 of file ffv1enc.c.

Referenced by ffv1_encode_init().

◆ init_slices_state()

static av_cold int init_slices_state ( FFV1Context f)
static

Definition at line 522 of file ffv1enc.c.

Referenced by ffv1_encode_init().

◆ ffv1_encode_init()

static av_cold int ffv1_encode_init ( AVCodecContext avctx)
static

Definition at line 533 of file ffv1enc.c.

◆ encode_slice_header()

static void encode_slice_header ( FFV1Context f,
FFV1Context fs 
)
static

Definition at line 844 of file ffv1enc.c.

Referenced by encode_slice().

◆ encode_slice()

static int encode_slice ( AVCodecContext c,
void arg 
)
static

Definition at line 870 of file ffv1enc.c.

Referenced by ffv1_encode_frame().

◆ ffv1_encode_frame()

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

Definition at line 925 of file ffv1enc.c.

◆ ffv1_encode_close()

static av_cold int ffv1_encode_close ( AVCodecContext avctx)
static

Definition at line 1062 of file ffv1enc.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "slicecrc", "Protect slices with CRCs", OFFSET(ec), AV_OPT_TYPE_INT,
{ .i64 = -1 }, -1, 1, VE },
{ "coder", "Coder type", OFFSET(ac), AV_OPT_TYPE_INT,
{ .i64 = AC_GOLOMB_RICE }, 0, 2, VE, "coder" },
{ "rice", "Golomb rice", 0, AV_OPT_TYPE_CONST,
{ .i64 = AC_GOLOMB_RICE }, INT_MIN, INT_MAX, VE, "coder" },
{ "range_def", "Range with default table", 0, AV_OPT_TYPE_CONST,
{ .i64 = AC_RANGE_DEFAULT_TAB }, INT_MIN, INT_MAX, VE, "coder" },
{ "range_tab", "Range with custom table", 0, AV_OPT_TYPE_CONST,
{ .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, "coder" },
{ "context", "Context model", OFFSET(context_model), AV_OPT_TYPE_INT,
{ .i64 = 0 }, 0, 1, VE },
{ NULL }
}
#define AC_RANGE_CUSTOM_TAB
Definition: ffv1.h:41
#define VE
Definition: ffv1enc.c:1069
NULL
Definition: eval.c:55
#define AC_GOLOMB_RICE
Definition: ffv1.h:39
#define AC_RANGE_DEFAULT_TAB
Definition: ffv1.h:40
#define OFFSET(x)
Definition: ffv1enc.c:1068

Definition at line 1070 of file ffv1enc.c.

◆ class_name

class_name = "ffv1 encoder"
private

Definition at line 1088 of file ffv1enc.c.

Referenced by av_opt_show2().

◆ item_name

item_name = av_default_item_name
private

Definition at line 1089 of file ffv1enc.c.

◆ option

option = options
private

Definition at line 1090 of file ffv1enc.c.

Referenced by open_input_file(), and open_output_file().

◆ version

version = LIBAVUTIL_VERSION_INT
private

◆ @16

const { ... }

◆ ffv1_defaults

const AVCodecDefault ffv1_defaults[]
static
Initial value:
= {
{ "coder", "-1" },
{ NULL },
}
NULL
Definition: eval.c:55

Definition at line 1095 of file ffv1enc.c.

◆ ff_ffv1_encoder

AVCodec ff_ffv1_encoder
Initial value:
= {
.name = "ffv1",
.long_name = NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
.priv_data_size = sizeof(FFV1Context),
.encode2 = ffv1_encode_frame,
.capabilities = AV_CODEC_CAP_SLICE_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) {
},
.defaults = ffv1_defaults,
.priv_class = &class,
}
static const AVCodecDefault ffv1_defaults[]
Definition: ffv1enc.c:1095
static av_cold int ffv1_encode_init(AVCodecContext *avctx)
Definition: ffv1enc.c:533
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:64
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:271
static int ffv1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: ffv1enc.c:925
static av_cold int ffv1_encode_close(AVCodecContext *avctx)
Definition: ffv1enc.c:1062
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:98
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:270
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:268
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:169
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:265
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:261
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:247
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:262
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:266
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:897
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:170
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:242
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:263
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:65
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:260
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:257
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:264
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
Y , 8bpp.
Definition: pixfmt.h:67
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:66
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:267

Definition at line 1101 of file ffv1enc.c.