FFmpeg
Loading...
Searching...
No Matches
snowenc.c File Reference
#include "libavutil/emms.h"
#include "libavutil/intmath.h"
#include "libavutil/libm.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "internal.h"
#include "me_cmp.h"
#include "qpeldsp.h"
#include "snow_dwt.h"
#include "snow.h"
#include "rangecoder.h"
#include "mathops.h"
#include "mpegvideo.h"
#include "h263enc.h"

Go to the source code of this file.

Data Structures

struct  SnowEncContext
 

Macros

#define FF_ME_ITER   3
 
#define ME_CACHE_SIZE   1024
 
#define PTR_ADD(ptr, off)
 
#define mcf(dx, dy)
 
#define P_LEFT   P[1]
 
#define P_TOP   P[2]
 
#define P_TOPRIGHT   P[3]
 
#define P_MEDIAN   P[4]
 
#define P_MV1   P[9]
 
#define FLAG_QPEL   1
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void init_ref (MotionEstContext *c, const uint8_t *const src[3], uint8_t *const ref[3], uint8_t *const ref2[3], int x, int y, int ref_index)
 
static void put_symbol (RangeCoder *c, uint8_t *state, int v, int is_signed)
 
static void put_symbol2 (RangeCoder *c, uint8_t *state, int v, int log2)
 
static int get_encode_buffer (SnowContext *s, AVFrame *frame)
 
static av_cold int encode_init (AVCodecContext *avctx)
 
static int pix_sum (const uint8_t *pix, int line_size, int w, int h)
 
static int pix_norm1 (const uint8_t *pix, int line_size, int w)
 
static int get_penalty_factor (int lambda, int lambda2, int type)
 
static int encode_q_branch (SnowEncContext *enc, int level, int x, int y)
 
static void encode_q_branch2 (SnowContext *s, int level, int x, int y)
 
static int get_dc (SnowEncContext *enc, int mb_x, int mb_y, int plane_index)
 
static int get_block_bits (SnowContext *s, int x, int y, int w)
 
static int get_block_rd (SnowEncContext *enc, int mb_x, int mb_y, int plane_index, uint8_t(*obmc_edged)[MB_SIZE *2])
 
static int get_4block_rd (SnowEncContext *enc, int mb_x, int mb_y, int plane_index)
 
static int encode_subband_c0run (SnowContext *s, SubBand *b, const IDWTELEM *src, const IDWTELEM *parent, int stride, int orientation)
 
static int encode_subband (SnowContext *s, SubBand *b, const IDWTELEM *src, const IDWTELEM *parent, int stride, int orientation)
 
static av_always_inline int check_block_intra (SnowEncContext *enc, int mb_x, int mb_y, int p[3], uint8_t(*obmc_edged)[MB_SIZE *2], int *best_rd)
 
static av_always_inline int check_block_inter (SnowEncContext *enc, int mb_x, int mb_y, int p0, int p1, uint8_t(*obmc_edged)[MB_SIZE *2], int *best_rd)
 
static av_always_inline int check_4block_inter (SnowEncContext *enc, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd)
 
static void iterative_me (SnowEncContext *enc)
 
static void encode_blocks (SnowEncContext *enc, int search)
 
static void quantize (SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias)
 
static void dequantize (SnowContext *s, SubBand *b, IDWTELEM *src, int stride)
 
static void decorrelate (SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median)
 
static void correlate (SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median)
 
static void encode_qlogs (SnowContext *s)
 
static void encode_header (SnowContext *s)
 
static void update_last_header_values (SnowContext *s)
 
static int qscale2qlog (int qscale)
 
static int ratecontrol_1pass (SnowEncContext *enc, AVFrame *pict)
 
static void calculate_visual_weight (SnowContext *s, Plane *p)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int encode_end (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass snowenc_class
 
const FFCodec ff_snow_encoder
 

Macro Definition Documentation

◆ FF_ME_ITER

#define FF_ME_ITER   3

Definition at line 43 of file snowenc.c.

Referenced by encode_blocks(), and encode_init().

◆ ME_CACHE_SIZE

#define ME_CACHE_SIZE   1024

Definition at line 65 of file snowenc.c.

Referenced by check_4block_inter(), and check_block_inter().

◆ PTR_ADD

#define PTR_ADD ( ptr,
off )
Value:
((ptr) ? (ptr) + (off) : NULL)
#define NULL
Definition coverity.c:32

Definition at line 76 of file snowenc.c.

Referenced by encode_q_branch(), and init_ref().

◆ mcf

#define mcf ( dx,
dy )
Value:
enc->qdsp.put_qpel_pixels_tab [0][dy+dx/4]=\
enc->qdsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\
s->h264qpel.put_h264_qpel_pixels_tab[0][dy+dx/4];\
enc->qdsp.put_qpel_pixels_tab [1][dy+dx/4]=\
enc->qdsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\
s->h264qpel.put_h264_qpel_pixels_tab[1][dy+dx/4];
#define s(width, name)
Definition cbs_vp9.c:198

Referenced by encode_init().

◆ P_LEFT

#define P_LEFT   P[1]

Definition at line 368 of file snowenc.c.

◆ P_TOP

#define P_TOP   P[2]

Definition at line 369 of file snowenc.c.

◆ P_TOPRIGHT

#define P_TOPRIGHT   P[3]

Definition at line 370 of file snowenc.c.

◆ P_MEDIAN

#define P_MEDIAN   P[4]

Definition at line 371 of file snowenc.c.

◆ P_MV1

#define P_MV1   P[9]

Definition at line 372 of file snowenc.c.

◆ FLAG_QPEL

#define FLAG_QPEL   1

Definition at line 373 of file snowenc.c.

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 2112 of file snowenc.c.

◆ VE

Definition at line 2113 of file snowenc.c.

Function Documentation

◆ init_ref()

static void init_ref ( MotionEstContext * c,
const uint8_t *const src[3],
uint8_t *const ref[3],
uint8_t *const ref2[3],
int x,
int y,
int ref_index )
static

Definition at line 78 of file snowenc.c.

Referenced by encode_q_branch().

◆ put_symbol()

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

Definition at line 95 of file snowenc.c.

Referenced by encode_header(), encode_q_branch(), encode_q_branch2(), and encode_qlogs().

◆ put_symbol2()

static void put_symbol2 ( RangeCoder * c,
uint8_t * state,
int v,
int log2 )
inlinestatic

Definition at line 123 of file snowenc.c.

Referenced by encode_subband_c0run().

◆ get_encode_buffer()

static int get_encode_buffer ( SnowContext * s,
AVFrame * frame )
static

Definition at line 142 of file snowenc.c.

Referenced by encode_frame(), and encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext * avctx)
static

Definition at line 164 of file snowenc.c.

◆ pix_sum()

static int pix_sum ( const uint8_t * pix,
int line_size,
int w,
int h )
static

Definition at line 311 of file snowenc.c.

Referenced by encode_q_branch().

◆ pix_norm1()

static int pix_norm1 ( const uint8_t * pix,
int line_size,
int w )
static

Definition at line 327 of file snowenc.c.

Referenced by encode_q_branch().

◆ get_penalty_factor()

static int get_penalty_factor ( int lambda,
int lambda2,
int type )
inlinestatic

Definition at line 343 of file snowenc.c.

Referenced by encode_q_branch(), get_4block_rd(), and get_block_rd().

◆ encode_q_branch()

static int encode_q_branch ( SnowEncContext * enc,
int level,
int x,
int y )
static

Definition at line 375 of file snowenc.c.

Referenced by encode_blocks(), encode_q_branch(), and iterative_me().

◆ encode_q_branch2()

static void encode_q_branch2 ( SnowContext * s,
int level,
int x,
int y )
static

Definition at line 613 of file snowenc.c.

Referenced by encode_blocks(), and encode_q_branch2().

◆ get_dc()

static int get_dc ( SnowEncContext * enc,
int mb_x,
int mb_y,
int plane_index )
static

Definition at line 669 of file snowenc.c.

Referenced by iterative_me().

◆ get_block_bits()

static int get_block_bits ( SnowContext * s,
int x,
int y,
int w )
inlinestatic

Definition at line 734 of file snowenc.c.

Referenced by get_4block_rd(), and get_block_rd().

◆ get_block_rd()

static int get_block_rd ( SnowEncContext * enc,
int mb_x,
int mb_y,
int plane_index,
uint8_t(*) obmc_edged[MB_SIZE *2] )
static

Definition at line 772 of file snowenc.c.

Referenced by check_block_inter(), and check_block_intra().

◆ get_4block_rd()

static int get_4block_rd ( SnowEncContext * enc,
int mb_x,
int mb_y,
int plane_index )
static

Definition at line 876 of file snowenc.c.

Referenced by check_4block_inter(), and iterative_me().

◆ encode_subband_c0run()

static int encode_subband_c0run ( SnowContext * s,
SubBand * b,
const IDWTELEM * src,
const IDWTELEM * parent,
int stride,
int orientation )
static

Definition at line 947 of file snowenc.c.

Referenced by encode_subband().

◆ encode_subband()

static int encode_subband ( SnowContext * s,
SubBand * b,
const IDWTELEM * src,
const IDWTELEM * parent,
int stride,
int orientation )
static

Definition at line 1067 of file snowenc.c.

Referenced by encode_frame().

◆ check_block_intra()

static av_always_inline int check_block_intra ( SnowEncContext * enc,
int mb_x,
int mb_y,
int p[3],
uint8_t(*) obmc_edged[MB_SIZE *2],
int * best_rd )
static

Definition at line 1074 of file snowenc.c.

Referenced by iterative_me().

◆ check_block_inter()

static av_always_inline int check_block_inter ( SnowEncContext * enc,
int mb_x,
int mb_y,
int p0,
int p1,
uint8_t(*) obmc_edged[MB_SIZE *2],
int * best_rd )
static

Definition at line 1105 of file snowenc.c.

Referenced by iterative_me().

◆ check_4block_inter()

static av_always_inline int check_4block_inter ( SnowEncContext * enc,
int mb_x,
int mb_y,
int p0,
int p1,
int ref,
int * best_rd )
static

Definition at line 1141 of file snowenc.c.

Referenced by iterative_me().

◆ iterative_me()

static void iterative_me ( SnowEncContext * enc)
static

Definition at line 1190 of file snowenc.c.

Referenced by encode_blocks().

◆ encode_blocks()

static void encode_blocks ( SnowEncContext * enc,
int search )
static

Definition at line 1419 of file snowenc.c.

Referenced by encode_frame().

◆ quantize()

static void quantize ( SnowContext * s,
SubBand * b,
IDWTELEM * dst,
DWTELEM * src,
int stride,
int bias )
static

Definition at line 1443 of file snowenc.c.

Referenced by encode_frame().

◆ dequantize()

static void dequantize ( SnowContext * s,
SubBand * b,
IDWTELEM * src,
int stride )
static

Definition at line 1504 of file snowenc.c.

Referenced by encode_frame().

◆ decorrelate()

static void decorrelate ( SnowContext * s,
SubBand * b,
IDWTELEM * src,
int stride,
int inverse,
int use_median )
static

◆ correlate()

static void correlate ( SnowContext * s,
SubBand * b,
IDWTELEM * src,
int stride,
int inverse,
int use_median )
static

Definition at line 1550 of file snowenc.c.

Referenced by encode_frame().

◆ encode_qlogs()

static void encode_qlogs ( SnowContext * s)
static

Definition at line 1574 of file snowenc.c.

Referenced by encode_header().

◆ encode_header()

static void encode_header ( SnowContext * s)
static

Definition at line 1587 of file snowenc.c.

Referenced by encode_frame().

◆ update_last_header_values()

static void update_last_header_values ( SnowContext * s)
static

Definition at line 1660 of file snowenc.c.

Referenced by encode_frame().

◆ qscale2qlog()

static int qscale2qlog ( int qscale)
static

< 64 > 60

Definition at line 1680 of file snowenc.c.

Referenced by encode_frame(), and ratecontrol_1pass().

◆ ratecontrol_1pass()

static int ratecontrol_1pass ( SnowEncContext * enc,
AVFrame * pict )
static

Definition at line 1685 of file snowenc.c.

Referenced by encode_frame().

◆ calculate_visual_weight()

static void calculate_visual_weight ( SnowContext * s,
Plane * p )
static

Definition at line 1739 of file snowenc.c.

Referenced by encode_frame().

◆ encode_frame()

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

Definition at line 1769 of file snowenc.c.

◆ encode_end()

static av_cold int encode_end ( AVCodecContext * avctx)
static

Definition at line 2089 of file snowenc.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{"motion_est", "motion estimation algorithm", OFFSET(motion_est), AV_OPT_TYPE_INT, {.i64 = FF_ME_EPZS }, FF_ME_ZERO, FF_ME_ITER, VE, .unit = "motion_est" },
{ "zero", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ZERO }, 0, 0, VE, .unit = "motion_est" },
{ "epzs", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_EPZS }, 0, 0, VE, .unit = "motion_est" },
{ "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, VE, .unit = "motion_est" },
{ "iter", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_ITER }, 0, 0, VE, .unit = "motion_est" },
{ "memc_only", "Only do ME/MC (I frames -> ref, P frame -> ME+MC).", OFFSET(memc_only), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "no_bitstream", "Skip final bitstream writeout.", OFFSET(no_bitstream), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "intra_penalty", "Penalty for intra blocks in block decision", OFFSET(intra_penalty), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "iterative_dia_size", "Dia size for the iterative ME", OFFSET(iterative_dia_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "sc_threshold", "Scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, VE },
{ "pred", "Spatial decomposition type", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 0 }, DWT_97, DWT_53, VE, .unit = "pred" },
{ "dwt97", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "dwt53", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "rc_eq", "Set rate control equation. When computing the expression, besides the standard functions "
"defined in the section 'Expression Evaluation', the following functions are available: "
"bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv "
"fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.",
OFFSET(m.rc_context.rc_eq), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
{ NULL },
}
#define VE
Definition amfenc_av1.c:30
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define FF_ME_EPZS
Definition motion_est.h:43
#define FF_ME_XONE
Definition motion_est.h:44
#define FF_ME_ZERO
Definition motion_est.h:42
static const float pred[4]
Definition siprdata.h:259
#define DWT_97
Definition snow_dwt.h:68
#define DWT_53
Definition snow_dwt.h:69
#define FF_ME_ITER
Definition snowenc.c:43

Definition at line 2114 of file snowenc.c.

◆ snowenc_class

const AVClass snowenc_class
static
Initial value:
= {
.class_name = "snow encoder",
.item_name = av_default_item_name,
.option = options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 2136 of file snowenc.c.

◆ ff_snow_encoder

const FFCodec ff_snow_encoder
Initial value:
= {
.p.name = "snow",
CODEC_LONG_NAME("Snow"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.capabilities = AV_CODEC_CAP_DR1 |
.priv_data_size = sizeof(SnowEncContext),
.close = encode_end,
.color_ranges = AVCOL_RANGE_MPEG,
.p.priv_class = &snowenc_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
static av_cold int encode_init(AVCodecContext *avctx)
Definition asvenc.c:373
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
Definition ffmpeg_enc.c:694
#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:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition codec.h:162
@ AV_CODEC_ID_SNOW
Definition codec_id.h:258
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold int encode_end(AVCodecContext *avctx)
Definition huffyuvenc.c:978
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
static const AVClass snowenc_class
Definition snowenc.c:2136

Definition at line 2143 of file snowenc.c.