FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/crc.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/timer.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 NB_Y_COEFF   15
 
#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 int encode_plane (FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index)
 
static int 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 encode_init (AVCodecContext *avctx)
 
static void encode_slice_header (FFV1Context *f, FFV1Context *fs)
 
static void choose_rct_params (FFV1Context *fs, const uint8_t *src[3], const int stride[3], int w, int h)
 
static int encode_slice (AVCodecContext *c, void *arg)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int encode_close (AVCodecContext *avctx)
 

Variables

static const int8_t quant5_10bit [256]
 
static const int8_t quant5 [256]
 
static const int8_t quant9_10bit [256]
 
static const int8_t quant11 [256]
 
static const uint8_t ver2_state [256]
 
static const AVOption options []
 
static const AVClass ffv1_class
 
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

#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 C
#define S(s, c, i)
static struct @197 state
if(ret< 0)
Definition: vf_mcdeint.c:280
#define put_rac(C, S, B)
Definition: vf_geq.c:46

Referenced by encode_frame(), encode_header(), encode_line(), encode_q_branch(), encode_q_branch2(), encode_slice(), encode_slice_header(), encode_subband_c0run(), put_symbol(), put_symbol2(), put_symbol_inline(), write_extradata(), and write_header().

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

Referenced by sort_stt().

#define STATS_OUT_SIZE   1024 * 1024 * 6

Referenced by encode_frame(), and encode_init().

#define NB_Y_COEFF   15

Referenced by choose_rct_params().

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

Definition at line 1344 of file ffv1enc.c.

Definition at line 1345 of file ffv1enc.c.

Function Documentation

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

Definition at line 138 of file ffv1enc.c.

Referenced by encode_init().

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 180 of file ffv1enc.c.

Referenced by encode_line(), and put_symbol().

static av_noinline void put_symbol ( RangeCoder c,
uint8_t state,
int  v,
int  is_signed 
)
static
static void put_vlc_symbol ( PutBitContext pb,
VlcState *const  state,
int  v,
int  bits 
)
inlinestatic

Definition at line 235 of file ffv1enc.c.

Referenced by 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 266 of file ffv1enc.c.

Referenced by encode_plane(), and encode_rgb_frame().

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

Definition at line 368 of file ffv1enc.c.

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

Definition at line 408 of file ffv1enc.c.

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

Definition at line 470 of file ffv1enc.c.

Referenced by write_quant_tables().

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

Definition at line 485 of file ffv1enc.c.

Referenced by write_extradata(), and write_header().

static void write_header ( FFV1Context f)
static

Definition at line 493 of file ffv1enc.c.

Referenced by encode_frame().

static int write_extradata ( FFV1Context f)
static

Definition at line 540 of file ffv1enc.c.

Referenced by encode_init().

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

Definition at line 616 of file ffv1enc.c.

Referenced by encode_init().

static av_cold int encode_init ( AVCodecContext avctx)
static

Definition at line 664 of file ffv1enc.c.

static void encode_slice_header ( FFV1Context f,
FFV1Context fs 
)
static

Definition at line 1002 of file ffv1enc.c.

Referenced by encode_slice().

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

Definition at line 1035 of file ffv1enc.c.

Referenced by encode_slice().

static int encode_slice ( AVCodecContext c,
void arg 
)
static

Definition at line 1117 of file ffv1enc.c.

Referenced by encode_frame().

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

Definition at line 1190 of file ffv1enc.c.

static av_cold int encode_close ( AVCodecContext avctx)
static

Definition at line 1338 of file ffv1enc.c.

Variable Documentation

const int8_t quant5_10bit[256]
static
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0,
}

Definition at line 43 of file ffv1enc.c.

Referenced by encode_init().

const int8_t quant5[256]
static
Initial value:
= {
0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1,
}

Definition at line 62 of file ffv1enc.c.

Referenced by encode_init().

const int8_t quant9_10bit[256]
static
Initial value:
= {
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -0, -0, -0, -0,
}

Definition at line 81 of file ffv1enc.c.

Referenced by encode_init().

const int8_t quant11[256]
static
Initial value:
= {
0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -4, -4,
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -1,
}

Definition at line 100 of file ffv1enc.c.

Referenced by encode_init().

const uint8_t ver2_state[256]
static
Initial value:
= {
0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49,
59, 25, 26, 26, 27, 31, 33, 33, 33, 34, 34, 37, 67, 38, 39, 39,
40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52,
53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69,
87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97,
85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125,
115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129,
165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148,
147, 155, 151, 149, 151, 150, 152, 157, 153, 154, 156, 168, 158, 162, 161, 160,
172, 163, 169, 164, 166, 184, 167, 170, 177, 174, 171, 173, 182, 176, 180, 178,
175, 189, 179, 181, 186, 183, 192, 185, 200, 187, 191, 188, 190, 197, 193, 196,
197, 194, 195, 196, 198, 202, 199, 201, 210, 203, 207, 204, 205, 206, 208, 214,
209, 211, 221, 212, 213, 215, 224, 216, 217, 218, 219, 220, 222, 228, 223, 225,
226, 224, 227, 229, 240, 230, 231, 232, 233, 234, 235, 236, 238, 239, 237, 242,
241, 243, 242, 244, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255,
}

Definition at line 119 of file ffv1enc.c.

Referenced by encode_init().

const AVOption options[]
static
Initial value:
= {
{ "slicecrc", "Protect slices with CRCs", OFFSET(ec), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define VE
Definition: ffv1enc.c:1345
#define OFFSET(x)
Definition: ffv1enc.c:1344

Definition at line 1346 of file ffv1enc.c.

const AVClass ffv1_class
static
Initial value:
= {
.class_name = "ffv1 encoder",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
av_default_item_name
static const AVOption options[]
Definition: ffv1enc.c:1346

Definition at line 1351 of file ffv1enc.c.

const AVCodecDefault ffv1_defaults[]
static
Initial value:
= {
{ "coder", "-1" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 1358 of file ffv1enc.c.

AVCodec ff_ffv1_encoder
Initial value:
= {
.name = "ffv1",
.long_name = NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
.priv_data_size = sizeof(FFV1Context),
.encode2 = encode_frame,
.close = encode_close,
.pix_fmts = (const enum AVPixelFormat[]) {
},
.defaults = ffv1_defaults,
.priv_class = &ffv1_class,
}
static const AVCodecDefault ffv1_defaults[]
Definition: ffv1enc.c:1358
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:415
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:411
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:412
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:68
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:396
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:882
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:103
static av_cold int encode_init(AVCodecContext *avctx)
Definition: ffv1enc.c:664
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:408
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:395
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:393
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:414
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:281
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:416
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:383
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:378
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: ffv1enc.c:1190
static av_cold int encode_close(AVCodecContext *avctx)
Definition: ffv1enc.c:1338
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:364
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:413
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:379
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:391
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:924
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:280
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:357
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:380
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:69
static const AVClass ffv1_class
Definition: ffv1enc.c:1351
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:377
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:381
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
Y , 8bpp.
Definition: pixfmt.h:71
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:410
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:70
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:101
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:392
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:361

Definition at line 1363 of file ffv1enc.c.