FFmpeg
Macros | Functions | Variables
mpeg4videoenc.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "codec_internal.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "h263.h"
#include "h263enc.h"
#include "mpeg4video.h"
#include "mpeg4videodata.h"
#include "mpeg4videodefs.h"
#include "mpeg4videoenc.h"
#include "mpegvideoenc.h"
#include "profiles.h"
#include "version.h"

Go to the source code of this file.

Macros

#define UNI_MPEG4_ENC_INDEX(last, run, level)   ((last) * 128 * 64 + (run) * 128 + (level))
 
#define OFFSET(x)   offsetof(MpegEncContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static int get_block_rate (MpegEncContext *s, int16_t block[64], int block_last_index, uint8_t scantable[64])
 Return the number of bits that encoding the 8x8 block in block would need. More...
 
static void restore_ac_coeffs (MpegEncContext *s, int16_t block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6])
 Restore the ac coefficients in block that have been changed by decide_ac_pred(). More...
 
static int decide_ac_pred (MpegEncContext *s, int16_t block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6])
 Return the optimal value (0 or 1) for the ac_pred element for the given MB in MPEG-4. More...
 
void ff_clean_mpeg4_qscales (MpegEncContext *s)
 modify mb_type & qscale so that encoding is actually possible in MPEG-4 More...
 
static void mpeg4_encode_dc (PutBitContext *s, int level, int n)
 Encode the dc value. More...
 
static int mpeg4_get_dc_length (int level, int n)
 
static void mpeg4_encode_block (MpegEncContext *s, int16_t *block, int n, int intra_dc, uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
 Encode an 8x8 block. More...
 
static int mpeg4_get_block_length (MpegEncContext *s, int16_t *block, int n, int intra_dc, uint8_t *scan_table)
 
static void mpeg4_encode_blocks (MpegEncContext *s, int16_t block[6][64], int intra_dc[6], uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
 
static int get_b_cbp (MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y, int mb_type)
 
void ff_mpeg4_encode_mb (MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
 
void ff_mpeg4_stuffing (PutBitContext *pbc)
 add MPEG-4 stuffing bits (01...1) More...
 
void ff_set_mpeg4_time (MpegEncContext *s)
 
static void mpeg4_encode_gop_header (MpegEncContext *s)
 
static void mpeg4_encode_visual_object_header (MpegEncContext *s)
 
static void mpeg4_encode_vol_header (MpegEncContext *s, int vo_number, int vol_number)
 
int ff_mpeg4_encode_picture_header (MpegEncContext *s)
 
static av_cold void init_uni_dc_tab (void)
 
static av_cold void init_uni_mpeg4_rl_tab (RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab)
 
static av_cold void mpeg4_encode_init_static (void)
 
static av_cold int encode_init (AVCodecContext *avctx)
 
void ff_mpeg4_init_partitions (MpegEncContext *s)
 
void ff_mpeg4_merge_partitions (MpegEncContext *s)
 
void ff_mpeg4_encode_video_packet_header (MpegEncContext *s)
 

Variables

static uint8_t uni_DCtab_lum_len [512]
 
static uint8_t uni_DCtab_chrom_len [512]
 
static uint16_t uni_DCtab_lum_bits [512]
 
static uint16_t uni_DCtab_chrom_bits [512]
 
static uint32_t uni_mpeg4_intra_rl_bits [64 *64 *2 *2]
 
static uint8_t uni_mpeg4_intra_rl_len [64 *64 *2 *2]
 
static uint32_t uni_mpeg4_inter_rl_bits [64 *64 *2 *2]
 
static uint8_t uni_mpeg4_inter_rl_len [64 *64 *2 *2]
 
static const int dquant_code [5] = { 1, 0, 9, 2, 3 }
 
static const AVOption options []
 
static const AVClass mpeg4enc_class
 
const FFCodec ff_mpeg4_encoder
 

Macro Definition Documentation

◆ UNI_MPEG4_ENC_INDEX

#define UNI_MPEG4_ENC_INDEX (   last,
  run,
  level 
)    ((last) * 128 * 64 + (run) * 128 + (level))

Definition at line 57 of file mpeg4videoenc.c.

◆ OFFSET

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

Definition at line 1375 of file mpeg4videoenc.c.

◆ VE

Definition at line 1376 of file mpeg4videoenc.c.

Function Documentation

◆ get_block_rate()

static int get_block_rate ( MpegEncContext s,
int16_t  block[64],
int  block_last_index,
uint8_t  scantable[64] 
)
inlinestatic

Return the number of bits that encoding the 8x8 block in block would need.

Parameters
[in]block_last_indexlast index in scantable order that refers to a non zero element in block.

Definition at line 73 of file mpeg4videoenc.c.

Referenced by decide_ac_pred().

◆ restore_ac_coeffs()

static void restore_ac_coeffs ( MpegEncContext s,
int16_t  block[6][64],
const int  dir[6],
uint8_t *  st[6],
const int  zigzag_last_index[6] 
)
inlinestatic

Restore the ac coefficients in block that have been changed by decide_ac_pred().

This function also restores s->block_last_index.

Parameters
[in,out]blockMB coefficients, these will be restored
[in]dirac prediction direction for each 8x8 block
[out]stscantable for each 8x8 block
[in]zigzag_last_indexindex referring to the last non zero coefficient in zigzag order

Definition at line 108 of file mpeg4videoenc.c.

Referenced by decide_ac_pred(), and ff_mpeg4_encode_mb().

◆ decide_ac_pred()

static int decide_ac_pred ( MpegEncContext s,
int16_t  block[6][64],
const int  dir[6],
uint8_t *  st[6],
int  zigzag_last_index[6] 
)
inlinestatic

Return the optimal value (0 or 1) for the ac_pred element for the given MB in MPEG-4.

This function will also update s->block_last_index and s->ac_val.

Parameters
[in,out]blockMB coefficients, these will be updated if 1 is returned
[in]dirac prediction direction for each 8x8 block
[out]stscantable for each 8x8 block
[out]zigzag_last_indexindex referring to the last non zero coefficient in zigzag order

Definition at line 139 of file mpeg4videoenc.c.

Referenced by ff_mpeg4_encode_mb().

◆ ff_clean_mpeg4_qscales()

void ff_clean_mpeg4_qscales ( MpegEncContext s)

modify mb_type & qscale so that encoding is actually possible in MPEG-4

Definition at line 222 of file mpeg4videoenc.c.

Referenced by estimate_qp().

◆ mpeg4_encode_dc()

static void mpeg4_encode_dc ( PutBitContext s,
int  level,
int  n 
)
inlinestatic

Encode the dc value.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)

Definition at line 266 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_block().

◆ mpeg4_get_dc_length()

static int mpeg4_get_dc_length ( int  level,
int  n 
)
inlinestatic

Definition at line 279 of file mpeg4videoenc.c.

Referenced by mpeg4_get_block_length().

◆ mpeg4_encode_block()

static void mpeg4_encode_block ( MpegEncContext s,
int16_t *  block,
int  n,
int  intra_dc,
uint8_t *  scan_table,
PutBitContext dc_pb,
PutBitContext ac_pb 
)
inlinestatic

Encode an 8x8 block.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)

Definition at line 291 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks().

◆ mpeg4_get_block_length()

static int mpeg4_get_block_length ( MpegEncContext s,
int16_t *  block,
int  n,
int  intra_dc,
uint8_t *  scan_table 
)
static

Definition at line 352 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks().

◆ mpeg4_encode_blocks()

static void mpeg4_encode_blocks ( MpegEncContext s,
int16_t  block[6][64],
int  intra_dc[6],
uint8_t **  scan_table,
PutBitContext dc_pb,
PutBitContext ac_pb 
)
inlinestatic

Definition at line 406 of file mpeg4videoenc.c.

Referenced by ff_mpeg4_encode_mb().

◆ get_b_cbp()

static int get_b_cbp ( MpegEncContext s,
int16_t  block[6][64],
int  motion_x,
int  motion_y,
int  mb_type 
)
inlinestatic

Definition at line 440 of file mpeg4videoenc.c.

Referenced by ff_mpeg4_encode_mb().

◆ ff_mpeg4_encode_mb()

void ff_mpeg4_encode_mb ( MpegEncContext s,
int16_t  block[6][64],
int  motion_x,
int  motion_y 
)

Definition at line 484 of file mpeg4videoenc.c.

Referenced by encode_mb_internal().

◆ ff_mpeg4_stuffing()

void ff_mpeg4_stuffing ( PutBitContext pbc)

add MPEG-4 stuffing bits (01...1)

Definition at line 864 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_gop_header(), mpeg4_encode_visual_object_header(), mpeg4_encode_vol_header(), and write_slice_end().

◆ ff_set_mpeg4_time()

void ff_set_mpeg4_time ( MpegEncContext s)

Definition at line 874 of file mpeg4videoenc.c.

Referenced by encode_picture().

◆ mpeg4_encode_gop_header()

static void mpeg4_encode_gop_header ( MpegEncContext s)
static

Definition at line 884 of file mpeg4videoenc.c.

Referenced by ff_mpeg4_encode_picture_header().

◆ mpeg4_encode_visual_object_header()

static void mpeg4_encode_visual_object_header ( MpegEncContext s)
static

Definition at line 914 of file mpeg4videoenc.c.

Referenced by encode_init(), and ff_mpeg4_encode_picture_header().

◆ mpeg4_encode_vol_header()

static void mpeg4_encode_vol_header ( MpegEncContext s,
int  vo_number,
int  vol_number 
)
static

Definition at line 958 of file mpeg4videoenc.c.

Referenced by encode_init(), and ff_mpeg4_encode_picture_header().

◆ ff_mpeg4_encode_picture_header()

int ff_mpeg4_encode_picture_header ( MpegEncContext s)

Definition at line 1059 of file mpeg4videoenc.c.

Referenced by encode_picture().

◆ init_uni_dc_tab()

static av_cold void init_uni_dc_tab ( void  )
static

Definition at line 1119 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_init_static().

◆ init_uni_mpeg4_rl_tab()

static av_cold void init_uni_mpeg4_rl_tab ( RLTable rl,
uint32_t *  bits_tab,
uint8_t *  len_tab 
)
static

Definition at line 1174 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_init_static().

◆ mpeg4_encode_init_static()

static av_cold void mpeg4_encode_init_static ( void  )
static

Definition at line 1269 of file mpeg4videoenc.c.

Referenced by encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext avctx)
static

Definition at line 1279 of file mpeg4videoenc.c.

◆ ff_mpeg4_init_partitions()

void ff_mpeg4_init_partitions ( MpegEncContext s)

Definition at line 1324 of file mpeg4videoenc.c.

Referenced by encode_thread().

◆ ff_mpeg4_merge_partitions()

void ff_mpeg4_merge_partitions ( MpegEncContext s)

Definition at line 1337 of file mpeg4videoenc.c.

Referenced by write_slice_end().

◆ ff_mpeg4_encode_video_packet_header()

void ff_mpeg4_encode_video_packet_header ( MpegEncContext s)

Definition at line 1363 of file mpeg4videoenc.c.

Referenced by encode_thread().

Variable Documentation

◆ uni_DCtab_lum_len

uint8_t uni_DCtab_lum_len[512]
static

Definition at line 43 of file mpeg4videoenc.c.

Referenced by encode_init(), init_uni_dc_tab(), mpeg4_encode_dc(), and mpeg4_get_dc_length().

◆ uni_DCtab_chrom_len

uint8_t uni_DCtab_chrom_len[512]
static

Definition at line 44 of file mpeg4videoenc.c.

Referenced by init_uni_dc_tab(), mpeg4_encode_dc(), and mpeg4_get_dc_length().

◆ uni_DCtab_lum_bits

uint16_t uni_DCtab_lum_bits[512]
static

Definition at line 45 of file mpeg4videoenc.c.

Referenced by init_uni_dc_tab(), and mpeg4_encode_dc().

◆ uni_DCtab_chrom_bits

uint16_t uni_DCtab_chrom_bits[512]
static

Definition at line 46 of file mpeg4videoenc.c.

Referenced by init_uni_dc_tab(), and mpeg4_encode_dc().

◆ uni_mpeg4_intra_rl_bits

uint32_t uni_mpeg4_intra_rl_bits[64 *64 *2 *2]
static

Definition at line 50 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_block(), and mpeg4_encode_init_static().

◆ uni_mpeg4_intra_rl_len

uint8_t uni_mpeg4_intra_rl_len[64 *64 *2 *2]
static

◆ uni_mpeg4_inter_rl_bits

uint32_t uni_mpeg4_inter_rl_bits[64 *64 *2 *2]
static

Definition at line 52 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_block(), and mpeg4_encode_init_static().

◆ uni_mpeg4_inter_rl_len

uint8_t uni_mpeg4_inter_rl_len[64 *64 *2 *2]
static

◆ dquant_code

const int dquant_code[5] = { 1, 0, 9, 2, 3 }
static

Definition at line 482 of file mpeg4videoenc.c.

Referenced by ff_mpeg4_encode_mb().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "mpeg_quant", "Use MPEG quantizers instead of H.263",
OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, VE },
{ NULL },
}

Definition at line 1377 of file mpeg4videoenc.c.

◆ mpeg4enc_class

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

Definition at line 1389 of file mpeg4videoenc.c.

◆ ff_mpeg4_encoder

const FFCodec ff_mpeg4_encoder
Initial value:
= {
.p.name = "mpeg4",
CODEC_LONG_NAME("MPEG-4 part 2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(MpegEncContext),
.p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.priv_class = &mpeg4enc_class,
}

Definition at line 1396 of file mpeg4videoenc.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
OFFSET
#define OFFSET(x)
Definition: mpeg4videoenc.c:1375
FF_MPV_COMMON_MOTION_EST_OPTS
#define FF_MPV_COMMON_MOTION_EST_OPTS
Definition: mpegvideoenc.h:108
ff_mpv_encode_picture
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
Definition: mpegvideo_enc.c:1747
FF_MPV_COMMON_OPTS
#define FF_MPV_COMMON_OPTS
Definition: mpegvideoenc.h:65
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
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:156
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
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_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
ff_mpv_encode_end
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
Definition: mpegvideo_enc.c:980
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:111
FF_MPEG4_PROFILE_OPTS
#define FF_MPEG4_PROFILE_OPTS
Definition: profiles.h:40
VE
#define VE
Definition: mpeg4videoenc.c:1376
mpeg4enc_class
static const AVClass mpeg4enc_class
Definition: mpeg4videoenc.c:1389
options
static const AVOption options[]
Definition: mpeg4videoenc.c:1377
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: mpeg4videoenc.c:1279
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_CODEC_CAP_DELAY
#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: codec.h:76
FF_MPV_COMMON_BFRAME_OPTS
#define FF_MPV_COMMON_BFRAME_OPTS
Definition: mpegvideoenc.h:103
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67