FFmpeg
Loading...
Searching...
No Matches
mpeg4videoenc.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "codec_internal.h"
#include "mpegvideo.h"
#include "h263.h"
#include "h263enc.h"
#include "mathops.h"
#include "mpeg4video.h"
#include "mpeg4videodata.h"
#include "mpeg4videodefs.h"
#include "mpeg4videoenc.h"
#include "mpegvideoenc.h"
#include "profiles.h"
#include "put_bits.h"
#include "version.h"

Go to the source code of this file.

Data Structures

struct  Mpeg4EncContext
 

Macros

#define UNI_MPEG4_ENC_INDEX(last, run, level)
 
#define VLC_NUM_CODES   102
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static Mpeg4EncContextmainctx_to_mpeg4 (MPVMainEncContext *m)
 
static int get_block_rate (MPVEncContext *const s, int16_t block[64], int block_last_index, const uint8_t scantable[64])
 Return the number of bits that encoding the 8x8 block in block would need.
 
static void restore_ac_coeffs (MPVEncContext *const s, int16_t block[6][64], const int dir[6], const uint8_t *st[6], const int zigzag_last_index[6])
 Restore the ac coefficients in block that have been changed by decide_ac_pred().
 
static int mpeg4_pred_dc (MpegEncContext *s, int n, int *dir_ptr)
 Predict the dc.
 
static int decide_ac_pred (MPVEncContext *const s, int16_t block[6][64], const int dir[6], const 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.
 
void ff_clean_mpeg4_qscales (MPVEncContext *const s)
 modify mb_type & qscale so that encoding is actually possible in MPEG-4
 
static void mpeg4_encode_dc (PutBitContext *s, int level, int n)
 Encode the dc value.
 
static void mpeg4_encode_ac_coeffs (const int16_t block[64], const int last_index, int i, const uint8_t *const scan_table, PutBitContext *const ac_pb, const uint32_t *const bits_tab, const uint8_t *const len_tab)
 Encode the AC coefficients of an 8x8 block.
 
static void mpeg4_encode_blocks_inter (MPVEncContext *const s, const int16_t block[6][64], PutBitContext *ac_pb)
 
static void mpeg4_encode_blocks_intra (MPVEncContext *const s, const int16_t block[6][64], const int intra_dc[6], const uint8_t *const *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
 
static int get_b_cbp (MPVEncContext *const s, int16_t block[6][64], int motion_x, int motion_y, int mb_type)
 
static void mpeg4_encode_mb (MPVEncContext *const s, int16_t block[][64], int motion_x, int motion_y)
 
void ff_mpeg4_stuffing (PutBitContext *pbc)
 add MPEG-4 stuffing bits (01...1)
 
void ff_set_mpeg4_time (MPVEncContext *const s)
 
static void mpeg4_encode_gop_header (MPVMainEncContext *const m)
 
static void mpeg4_encode_visual_object_header (MPVMainEncContext *const m)
 
static void mpeg4_encode_vol_header (Mpeg4EncContext *const m4, int vo_number, int vol_number)
 
static int mpeg4_encode_picture_header (MPVMainEncContext *const m)
 
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 (MPVEncContext *const s)
 
void ff_mpeg4_merge_partitions (MPVEncContext *const s)
 
void ff_mpeg4_encode_video_packet_header (MPVEncContext *const s)
 

Variables

static uint8_t fcode_tab [MAX_MV *2+1]
 Minimal fcode that a motion vector component would need.
 
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 )
Value:
((last) * 128 * 64 + (run) * 128 + (level))
uint8_t run
Definition svq3.c:207
uint8_t level
Definition svq3.c:208

Definition at line 64 of file mpeg4videoenc.c.

Referenced by init_uni_mpeg4_rl_tab(), and mpeg4_encode_ac_coeffs().

◆ VLC_NUM_CODES

#define VLC_NUM_CODES   102

Referenced by init_uni_mpeg4_rl_tab().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 1338 of file mpeg4videoenc.c.

◆ VE

Definition at line 1339 of file mpeg4videoenc.c.

Function Documentation

◆ mainctx_to_mpeg4()

static Mpeg4EncContext * mainctx_to_mpeg4 ( MPVMainEncContext * m)
inlinestatic

Definition at line 82 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_picture_header().

◆ get_block_rate()

static int get_block_rate ( MPVEncContext *const s,
int16_t block[64],
int block_last_index,
const 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 91 of file mpeg4videoenc.c.

Referenced by decide_ac_pred().

◆ restore_ac_coeffs()

static void restore_ac_coeffs ( MPVEncContext *const s,
int16_t block[6][64],
const int dir[6],
const 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->c.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 126 of file mpeg4videoenc.c.

Referenced by decide_ac_pred(), and mpeg4_encode_mb().

◆ mpeg4_pred_dc()

static int mpeg4_pred_dc ( MpegEncContext * s,
int n,
int * dir_ptr )
static

Predict the dc.

Parameters
nblock index (0-3 are luma, 4-5 are chroma)
dir_ptrpointer to an integer where the prediction direction will be stored

Definition at line 154 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ decide_ac_pred()

static int decide_ac_pred ( MPVEncContext *const s,
int16_t block[6][64],
const int dir[6],
const 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->c.block_last_index and s->c.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 187 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ ff_clean_mpeg4_qscales()

void ff_clean_mpeg4_qscales ( MPVEncContext *const s)

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

Definition at line 270 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 312 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks_intra().

◆ mpeg4_encode_ac_coeffs()

static void mpeg4_encode_ac_coeffs ( const int16_t block[64],
const int last_index,
int i,
const uint8_t *const scan_table,
PutBitContext *const ac_pb,
const uint32_t *const bits_tab,
const uint8_t *const len_tab )
inlinestatic

Encode the AC coefficients of an 8x8 block.

Definition at line 328 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks_inter(), and mpeg4_encode_blocks_intra().

◆ mpeg4_encode_blocks_inter()

static void mpeg4_encode_blocks_inter ( MPVEncContext *const s,
const int16_t block[6][64],
PutBitContext * ac_pb )
static

Definition at line 371 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ mpeg4_encode_blocks_intra()

static void mpeg4_encode_blocks_intra ( MPVEncContext *const s,
const int16_t block[6][64],
const int intra_dc[6],
const uint8_t *const * scan_table,
PutBitContext * dc_pb,
PutBitContext * ac_pb )
static

Definition at line 387 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ get_b_cbp()

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

Definition at line 408 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ mpeg4_encode_mb()

static void mpeg4_encode_mb ( MPVEncContext *const s,
int16_t block[][64],
int motion_x,
int motion_y )
static

Definition at line 452 of file mpeg4videoenc.c.

Referenced by encode_init().

◆ ff_mpeg4_stuffing()

void ff_mpeg4_stuffing ( PutBitContext * pbc)

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

Definition at line 835 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 ( MPVEncContext *const s)

Definition at line 843 of file mpeg4videoenc.c.

Referenced by encode_picture().

◆ mpeg4_encode_gop_header()

static void mpeg4_encode_gop_header ( MPVMainEncContext *const m)
static

Definition at line 853 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_picture_header().

◆ mpeg4_encode_visual_object_header()

static void mpeg4_encode_visual_object_header ( MPVMainEncContext *const m)
static

Definition at line 883 of file mpeg4videoenc.c.

Referenced by encode_init(), and mpeg4_encode_picture_header().

◆ mpeg4_encode_vol_header()

static void mpeg4_encode_vol_header ( Mpeg4EncContext *const m4,
int vo_number,
int vol_number )
static

Definition at line 926 of file mpeg4videoenc.c.

Referenced by encode_init(), and mpeg4_encode_picture_header().

◆ mpeg4_encode_picture_header()

static int mpeg4_encode_picture_header ( MPVMainEncContext *const m)
static

Definition at line 1017 of file mpeg4videoenc.c.

Referenced by encode_init().

◆ init_uni_dc_tab()

static av_cold void init_uni_dc_tab ( void )
static

Definition at line 1079 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 1134 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 1212 of file mpeg4videoenc.c.

Referenced by encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext * avctx)
static

Definition at line 1225 of file mpeg4videoenc.c.

◆ ff_mpeg4_init_partitions()

void ff_mpeg4_init_partitions ( MPVEncContext *const s)

Definition at line 1287 of file mpeg4videoenc.c.

Referenced by encode_thread().

◆ ff_mpeg4_merge_partitions()

void ff_mpeg4_merge_partitions ( MPVEncContext *const s)

Definition at line 1300 of file mpeg4videoenc.c.

Referenced by write_slice_end().

◆ ff_mpeg4_encode_video_packet_header()

void ff_mpeg4_encode_video_packet_header ( MPVEncContext *const s)

Definition at line 1326 of file mpeg4videoenc.c.

Referenced by encode_thread().

Variable Documentation

◆ fcode_tab

uint8_t fcode_tab[MAX_MV *2+1]
static

Minimal fcode that a motion vector component would need.

Definition at line 45 of file mpeg4videoenc.c.

Referenced by encode_init(), ff_get_best_fcode(), and mpeg4_encode_init_static().

◆ uni_DCtab_lum_len

uint8_t uni_DCtab_lum_len[512]
static

Definition at line 50 of file mpeg4videoenc.c.

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

◆ uni_DCtab_chrom_len

uint8_t uni_DCtab_chrom_len[512]
static

Definition at line 51 of file mpeg4videoenc.c.

Referenced by init_uni_dc_tab(), and mpeg4_encode_dc().

◆ uni_DCtab_lum_bits

uint16_t uni_DCtab_lum_bits[512]
static

Definition at line 52 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 53 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 57 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks_intra(), 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 59 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_blocks_inter(), 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 450 of file mpeg4videoenc.c.

Referenced by mpeg4_encode_mb().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "data_partitioning", "Use data partitioning.", FF_MPV_OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(c.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 },
}
#define VE
Definition amfenc_av1.c:30
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ 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
#define FF_MPV_OFFSET(x)
#define FF_MPV_COMMON_OPTS
#define FF_MPV_COMMON_BFRAME_OPTS
#define FF_MPV_COMMON_MOTION_EST_OPTS
#define FF_MPEG4_PROFILE_OPTS
Definition profiles.h:42
static double c[64]

Definition at line 1340 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,
}
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 1352 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(Mpeg4EncContext),
.color_ranges = AVCOL_RANGE_MPEG,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.priv_class = &mpeg4enc_class,
}
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
#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_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#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_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static const AVClass mpeg4enc_class
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
@ 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

Definition at line 1359 of file mpeg4videoenc.c.