FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
cinepakenc.c File Reference
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "elbg.h"
#include "encode.h"

Go to the source code of this file.

Data Structures

struct  mb_info
 
struct  strip_info
 
struct  CinepakEncContext
 

Macros

#define CVID_HEADER_SIZE   10
 
#define STRIP_HEADER_SIZE   12
 
#define CHUNK_HEADER_SIZE   4
 
#define MB_SIZE   4
 
#define MB_AREA   (MB_SIZE * MB_SIZE)
 
#define VECTOR_MAX   6
 
#define CODEBOOK_MAX   256
 
#define MAX_STRIPS   32
 
#define MIN_STRIPS   1
 
#define OFFSET(x)   offsetof(CinepakEncContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define CERTAIN(x)   ((x) != ENC_UNCERTAIN)
 
#define SMALLEST_CODEBOOK   1
 

Enumerations

enum  CinepakMode { MODE_V1_ONLY = 0, MODE_V1_V4, MODE_MC, MODE_COUNT }
 
enum  mb_encoding { ENC_V1, ENC_V4, ENC_SKIP, ENC_UNCERTAIN }
 

Functions

static av_cold int cinepak_encode_init (AVCodecContext *avctx)
 
static int64_t calculate_mode_score (CinepakEncContext *s, int h, strip_info *info, int report, int *training_set_v1_shrunk, int *training_set_v4_shrunk)
 
static int write_chunk_header (unsigned char *buf, int chunk_type, int chunk_size)
 
static int encode_codebook (CinepakEncContext *s, int *codebook, int size, int chunk_type_yuv, int chunk_type_gray, unsigned char *buf)
 
static void get_sub_picture (CinepakEncContext *s, int x, int y, uint8_t *const in_data[4], const int in_linesize[4], uint8_t *out_data[4], int out_linesize[4])
 
static void decode_v1_vector (CinepakEncContext *s, uint8_t *data[4], int linesize[4], int v1_vector, strip_info *info)
 
static void decode_v4_vector (CinepakEncContext *s, uint8_t *data[4], int linesize[4], int *v4_vector, strip_info *info)
 
static void copy_mb (CinepakEncContext *s, uint8_t *a_data[4], int a_linesize[4], uint8_t *b_data[4], int b_linesize[4])
 
static int encode_mode (CinepakEncContext *s, int h, uint8_t *scratch_data[4], int scratch_linesize[4], uint8_t *last_data[4], int last_linesize[4], strip_info *info, unsigned char *buf)
 
static int compute_mb_distortion (CinepakEncContext *s, uint8_t *a_data[4], int a_linesize[4], uint8_t *b_data[4], int b_linesize[4])
 
static int quantize (CinepakEncContext *s, int h, uint8_t *data[4], int linesize[4], int v1mode, strip_info *info, mb_encoding encoding)
 
static void calculate_skip_errors (CinepakEncContext *s, int h, uint8_t *last_data[4], int last_linesize[4], uint8_t *data[4], int linesize[4], strip_info *info)
 
static void write_strip_keyframe (unsigned char *buf, int keyframe)
 
static void write_strip_header (CinepakEncContext *s, int y, int h, int keyframe, unsigned char *buf, int strip_size)
 
static int rd_strip (CinepakEncContext *s, int y, int h, int keyframe, uint8_t *last_data[4], int last_linesize[4], uint8_t *data[4], int linesize[4], uint8_t *scratch_data[4], int scratch_linesize[4], unsigned char *buf, int64_t *best_score, int *no_skip)
 
static int write_cvid_header (CinepakEncContext *s, unsigned char *buf, int num_strips, int data_size, int isakeyframe)
 
static int rd_frame (CinepakEncContext *s, const AVFrame *frame, int isakeyframe, unsigned char *buf, int buf_size, int *got_keyframe)
 
static int cinepak_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static av_cold int cinepak_encode_end (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass cinepak_class
 
const FFCodec ff_cinepak_encoder
 

Macro Definition Documentation

◆ CVID_HEADER_SIZE

#define CVID_HEADER_SIZE   10

Definition at line 51 of file cinepakenc.c.

◆ STRIP_HEADER_SIZE

#define STRIP_HEADER_SIZE   12

Definition at line 52 of file cinepakenc.c.

◆ CHUNK_HEADER_SIZE

#define CHUNK_HEADER_SIZE   4

Definition at line 53 of file cinepakenc.c.

◆ MB_SIZE

#define MB_SIZE   4

Definition at line 55 of file cinepakenc.c.

◆ MB_AREA

#define MB_AREA   (MB_SIZE * MB_SIZE)

Definition at line 56 of file cinepakenc.c.

◆ VECTOR_MAX

#define VECTOR_MAX   6

Definition at line 58 of file cinepakenc.c.

◆ CODEBOOK_MAX

#define CODEBOOK_MAX   256

Definition at line 59 of file cinepakenc.c.

◆ MAX_STRIPS

#define MAX_STRIPS   32

Definition at line 61 of file cinepakenc.c.

◆ MIN_STRIPS

#define MIN_STRIPS   1

Definition at line 62 of file cinepakenc.c.

◆ OFFSET

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

Definition at line 133 of file cinepakenc.c.

◆ VE

Definition at line 134 of file cinepakenc.c.

◆ CERTAIN

#define CERTAIN (   x)    ((x) != ENC_UNCERTAIN)

Definition at line 698 of file cinepakenc.c.

◆ SMALLEST_CODEBOOK

#define SMALLEST_CODEBOOK   1

Enumeration Type Documentation

◆ CinepakMode

Enumerator
MODE_V1_ONLY 
MODE_V1_V4 
MODE_MC 
MODE_COUNT 

Definition at line 72 of file cinepakenc.c.

◆ mb_encoding

Enumerator
ENC_V1 
ENC_V4 
ENC_SKIP 
ENC_UNCERTAIN 

Definition at line 80 of file cinepakenc.c.

Function Documentation

◆ cinepak_encode_init()

static av_cold int cinepak_encode_init ( AVCodecContext avctx)
static

Definition at line 156 of file cinepakenc.c.

◆ calculate_mode_score()

static int64_t calculate_mode_score ( CinepakEncContext s,
int  h,
strip_info info,
int  report,
int training_set_v1_shrunk,
int training_set_v4_shrunk 
)
static

Definition at line 258 of file cinepakenc.c.

Referenced by rd_strip().

◆ write_chunk_header()

static int write_chunk_header ( unsigned char *  buf,
int  chunk_type,
int  chunk_size 
)
static

Definition at line 376 of file cinepakenc.c.

Referenced by encode_codebook(), and encode_mode().

◆ encode_codebook()

static int encode_codebook ( CinepakEncContext s,
int codebook,
int  size,
int  chunk_type_yuv,
int  chunk_type_gray,
unsigned char *  buf 
)
static

Definition at line 383 of file cinepakenc.c.

Referenced by encode_mode().

◆ get_sub_picture()

static void get_sub_picture ( CinepakEncContext s,
int  x,
int  y,
uint8_t *const  in_data[4],
const int  in_linesize[4],
uint8_t *  out_data[4],
int  out_linesize[4] 
)
static

Definition at line 431 of file cinepakenc.c.

Referenced by calculate_skip_errors(), encode_mode(), quantize(), and rd_frame().

◆ decode_v1_vector()

static void decode_v1_vector ( CinepakEncContext s,
uint8_t *  data[4],
int  linesize[4],
int  v1_vector,
strip_info info 
)
static

Definition at line 448 of file cinepakenc.c.

Referenced by encode_mode(), and quantize().

◆ decode_v4_vector()

static void decode_v4_vector ( CinepakEncContext s,
uint8_t *  data[4],
int  linesize[4],
int v4_vector,
strip_info info 
)
static

Definition at line 487 of file cinepakenc.c.

Referenced by encode_mode(), and quantize().

◆ copy_mb()

static void copy_mb ( CinepakEncContext s,
uint8_t *  a_data[4],
int  a_linesize[4],
uint8_t *  b_data[4],
int  b_linesize[4] 
)
static

Definition at line 507 of file cinepakenc.c.

Referenced by encode_mode(), and mjpeg_decode_scan().

◆ encode_mode()

static int encode_mode ( CinepakEncContext s,
int  h,
uint8_t *  scratch_data[4],
int  scratch_linesize[4],
uint8_t *  last_data[4],
int  last_linesize[4],
strip_info info,
unsigned char *  buf 
)
static

Definition at line 526 of file cinepakenc.c.

Referenced by rd_strip().

◆ compute_mb_distortion()

static int compute_mb_distortion ( CinepakEncContext s,
uint8_t *  a_data[4],
int  a_linesize[4],
uint8_t *  b_data[4],
int  b_linesize[4] 
)
static

Definition at line 672 of file cinepakenc.c.

Referenced by calculate_skip_errors(), and quantize().

◆ quantize()

static int quantize ( CinepakEncContext s,
int  h,
uint8_t *  data[4],
int  linesize[4],
int  v1mode,
strip_info info,
mb_encoding  encoding 
)
static

Definition at line 699 of file cinepakenc.c.

Referenced by aptx_quantize_difference(), and rd_strip().

◆ calculate_skip_errors()

static void calculate_skip_errors ( CinepakEncContext s,
int  h,
uint8_t *  last_data[4],
int  last_linesize[4],
uint8_t *  data[4],
int  linesize[4],
strip_info info 
)
static

Definition at line 814 of file cinepakenc.c.

Referenced by rd_strip().

◆ write_strip_keyframe()

static void write_strip_keyframe ( unsigned char *  buf,
int  keyframe 
)
static

Definition at line 837 of file cinepakenc.c.

Referenced by rd_frame(), and write_strip_header().

◆ write_strip_header()

static void write_strip_header ( CinepakEncContext s,
int  y,
int  h,
int  keyframe,
unsigned char *  buf,
int  strip_size 
)
static

Definition at line 847 of file cinepakenc.c.

Referenced by rd_strip().

◆ rd_strip()

static int rd_strip ( CinepakEncContext s,
int  y,
int  h,
int  keyframe,
uint8_t *  last_data[4],
int  last_linesize[4],
uint8_t *  data[4],
int  linesize[4],
uint8_t *  scratch_data[4],
int  scratch_linesize[4],
unsigned char *  buf,
int64_t best_score,
int no_skip 
)
static

Definition at line 860 of file cinepakenc.c.

Referenced by rd_frame().

◆ write_cvid_header()

static int write_cvid_header ( CinepakEncContext s,
unsigned char *  buf,
int  num_strips,
int  data_size,
int  isakeyframe 
)
static

Definition at line 996 of file cinepakenc.c.

Referenced by rd_frame().

◆ rd_frame()

static int rd_frame ( CinepakEncContext s,
const AVFrame frame,
int  isakeyframe,
unsigned char *  buf,
int  buf_size,
int got_keyframe 
)
static

Definition at line 1008 of file cinepakenc.c.

Referenced by cinepak_encode_frame().

◆ cinepak_encode_frame()

static int cinepak_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int got_packet 
)
static

Definition at line 1168 of file cinepakenc.c.

◆ cinepak_encode_end()

static av_cold int cinepak_encode_end ( AVCodecContext avctx)
static

Definition at line 1194 of file cinepakenc.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "max_extra_cb_iterations", "Max extra codebook recalculation passes, more is better and slower",
OFFSET(max_extra_cb_iterations), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, VE },
{ "skip_empty_cb", "Avoid wasting bytes, ignore vintage MacOS decoder",
OFFSET(skip_empty_cb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "max_strips", "Limit strips/frame, vintage compatible is 1..3, otherwise the more the better",
OFFSET(max_max_strips), AV_OPT_TYPE_INT, { .i64 = 3 }, MIN_STRIPS, MAX_STRIPS, VE },
{ "min_strips", "Enforce min strips/frame, more is worse and faster, must be <= max_strips",
OFFSET(min_min_strips), AV_OPT_TYPE_INT, { .i64 = MIN_STRIPS }, MIN_STRIPS, MAX_STRIPS, VE },
{ "strip_number_adaptivity", "How fast the strip number adapts, more is slightly better, much slower",
OFFSET(strip_number_delta_range), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_STRIPS - MIN_STRIPS, VE },
{ NULL },
}

Definition at line 135 of file cinepakenc.c.

◆ cinepak_class

const AVClass cinepak_class
static
Initial value:
= {
.class_name = "cinepak",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 149 of file cinepakenc.c.

◆ ff_cinepak_encoder

const FFCodec ff_cinepak_encoder
Initial value:
= {
.p.name = "cinepak",
CODEC_LONG_NAME("Cinepak"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(CinepakEncContext),
.p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE },
.p.priv_class = &cinepak_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1217 of file cinepakenc.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
options
static const AVOption options[]
Definition: cinepakenc.c:135
OFFSET
#define OFFSET(x)
Definition: cinepakenc.c:133
cinepak_encode_init
static av_cold int cinepak_encode_init(AVCodecContext *avctx)
Definition: cinepakenc.c:156
cinepak_encode_end
static av_cold int cinepak_encode_end(AVCodecContext *avctx)
Definition: cinepakenc.c:1194
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:296
VE
#define VE
Definition: cinepakenc.c:134
MAX_STRIPS
#define MAX_STRIPS
Definition: cinepakenc.c:61
CinepakEncContext
Definition: cinepakenc.c:105
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:159
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_CINEPAK
@ AV_CODEC_ID_CINEPAK
Definition: codec_id.h:95
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
cinepak_class
static const AVClass cinepak_class
Definition: cinepakenc.c:149
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
cinepak_encode_frame
static int cinepak_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: cinepakenc.c:1168
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
MIN_STRIPS
#define MIN_STRIPS
Definition: cinepakenc.c:62