45 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
67 for(j=1; j<=block_last_index; j++){
68 const int index= scantable[j];
72 if((level&(~127)) == 0){
134 int16_t *ac_val, *ac_val1;
144 if(s->
mb_y==0 || s->
qscale == qscale_table[xy] || n==2 || n==3){
166 if(s->
mb_x==0 || s->
qscale == qscale_table[xy] || n==1 || n==3){
187 if(block[n][ st[n][i] ])
break;
214 for(i=0; i<s->
mb_num; i++){
216 odd += qscale_table[mb_xy]&1;
219 if(2*odd > s->
mb_num) odd=1;
222 for(i=0; i<s->
mb_num; i++){
224 if((qscale_table[mb_xy]&1) != odd)
225 qscale_table[mb_xy]++;
226 if(qscale_table[mb_xy] > 31)
227 qscale_table[mb_xy]= 31;
230 for(i=1; i<s->
mb_num; i++){
277 level = (-
level) ^ ((1 << size) - 1);
300 int i, last_non_zero;
308 if(last_index<1)
return;
313 if(last_index<0)
return;
320 last_non_zero = i - 1;
321 for (; i < last_index; i++) {
322 int level = block[ scan_table[i] ];
324 int run = i - last_non_zero - 1;
326 if((level&(~127)) == 0){
328 put_bits(ac_pb, len_tab[index], bits_tab[index]);
330 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
336 int level = block[ scan_table[i] ];
337 int run = i - last_non_zero - 1;
339 if((level&(~127)) == 0){
341 put_bits(ac_pb, len_tab[index], bits_tab[index]);
343 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
351 int i, last_non_zero;
359 if(last_index<1)
return len;
363 if(last_index<0)
return 0;
369 last_non_zero = i - 1;
370 for (; i < last_index; i++) {
371 int level = block[ scan_table[i] ];
373 int run = i - last_non_zero - 1;
375 if((level&(~127)) == 0){
377 len += len_tab[
index];
379 len += 7+2+1+6+1+12+1;
385 int level = block[ scan_table[i] ];
386 int run = i - last_non_zero - 1;
388 if((level&(~127)) == 0){
390 len += len_tab[
index];
392 len += 7+2+1+6+1+12+1;
405 for (i = 0; i < 6; i++) {
410 for (i = 0; i < 6; i++) {
416 for (i = 0; i < 6; i++) {
421 for (i = 0; i < 6; i++) {
429 int motion_x,
int motion_y,
int mb_type)
437 for (i = 0; i < 6; i++)
445 if ((motion_x | motion_y | s->
dquant | mb_type) == 0)
448 zero_score *= lambda;
449 if (zero_score <= score)
453 for (i = 0; i < 6; i++) {
460 for (i = 0; i < 6; i++) {
473 int motion_x,
int motion_y)
475 int cbpc, cbpy, pred_x, pred_y;
485 static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0};
486 int mb_type= mb_type_table[s->
mv_dir];
515 cbp=
get_b_cbp(s, block, motion_x, motion_y, mb_type);
517 if ((cbp | motion_x | motion_y | mb_type) ==0) {
523 if(interleaved_stats){
551 if(interleaved_stats){
561 assert(mb_type > 0 && mb_type < 4);
607 if(interleaved_stats){
613 if(interleaved_stats){
618 cbp=
get_p_cbp(s, block, motion_x, motion_y);
645 b_pic = pic->
f.
data[0] + offset;
661 if(interleaved_stats){
691 if(interleaved_stats){
699 motion_y - pred_y, s->
f_code);
715 if(interleaved_stats){
727 s->
mv[0][0][1] - pred_y, s->
f_code);
729 s->
mv[0][1][1] - pred_y, s->
f_code);
742 if(interleaved_stats){
755 if(interleaved_stats){
761 if(interleaved_stats){
770 int zigzag_last_index[6];
771 uint8_t *scan_table[6];
787 for (i = 0; i < 6; i++) {
815 if(interleaved_stats){
821 if(interleaved_stats){
840 if(length)
put_bits(pbc, length, (1<<length)-1);
854 int hours, minutes, seconds;
866 minutes= seconds/60; seconds %= 60;
867 hours= minutes/60; minutes %= 60;
884 int profile_and_level_indication;
890 profile_and_level_indication= 0xF0;
892 profile_and_level_indication= 0x00;
896 profile_and_level_indication |= s->
avctx->
level;
898 profile_and_level_indication |= 1;
901 if(profile_and_level_indication>>4 == 0xF){
912 put_bits(&s->
pb, 8, profile_and_level_indication);
989 if (vo_ver_id == 1) {
1013 if (vo_ver_id != 1){
1033 int time_div, time_mod;
1056 assert(time_incr >= 0);
1088 int level, uni_code, uni_len;
1090 for(level=-256; level<256; level++){
1101 l= (-
level) ^ ((1 << size) - 1);
1110 uni_code<<=
size; uni_code|=l;
1113 uni_code<<=1; uni_code|=1;
1125 uni_code<<=
size; uni_code|=l;
1128 uni_code<<=1; uni_code|=1;
1139 int slevel,
run, last;
1144 for(slevel=-64; slevel<64; slevel++){
1145 if(slevel==0)
continue;
1146 for(run=0; run<64; run++){
1147 for(last=0; last<=1; last++){
1149 int level= slevel < 0 ? -slevel : slevel;
1150 int sign= slevel < 0 ? 1 : 0;
1154 len_tab[
index]= 100;
1160 bits=bits*2+sign; len++;
1162 if(code!=rl->
n && len < len_tab[index]){
1176 bits=bits*2+sign; len++;
1178 if(code!=rl->
n && len < len_tab[index]){
1186 bits=bits*4+2; len+=2;
1193 bits=bits*2+sign; len++;
1195 if(code!=rl->
n && len < len_tab[index]){
1203 bits=bits*4+3; len+=2;
1204 bits=bits*2+last; len++;
1205 bits=bits*64+
run; len+=6;
1206 bits=bits*2+1; len++;
1207 bits=bits*4096+(slevel&0xfff); len+=12;
1208 bits=bits*2+1; len++;
1210 if(len < len_tab[index]){
1223 static int done = 0;
1270 int size= end - start;
1271 int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start;
1272 int tex_size= (size - 2*pb_size)&(~3);
1308 int mb_num_bits= av_log2(s->
mb_num - 1) + 1;
1318 #define OFFSET(x) offsetof(MpegEncContext, x)
1319 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1321 {
"data_partitioning",
"Use data partitioning.",
OFFSET(data_partitioning),
AV_OPT_TYPE_INT, { 0 }, 0, 1,
VE },
1322 {
"alternate_scan",
"Enable alternate scantable.",
OFFSET(alternate_scan),
AV_OPT_TYPE_INT, { 0 }, 0, 1,
VE },
static void mpeg4_encode_visual_object_header(MpegEncContext *s)
static void restore_ac_coeffs(MpegEncContext *s, DCTELEM 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().
ScanTable intra_v_scantable
RLTable ff_mpeg4_rl_intra
const uint8_t ff_mpeg4_c_dc_scale_table[32]
int time_increment_bits
number of bits to represent the fractional part of time
struct MpegEncContext MpegEncContext
MpegEncContext.
#define MV_TYPE_FIELD
2 vectors, one per field
static uint8_t uni_mpeg4_intra_rl_len[64 *64 *2 *2]
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG1 & B-frame MPEG4
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is acually possible in mpeg4
#define CODEC_FLAG_CBP_RD
Use rate distortion optimization for cbp.
#define CANDIDATE_MB_TYPE_BIDIR
int MPV_encode_init(AVCodecContext *avctx)
int16_t(*[3] ac_val)[16]
used for for mpeg4 AC prediction, all 3 arrays must be continuous
#define FF_COMPLIANCE_VERY_STRICT
Strictly conform to an older more strict version of the spec or reference software.
const uint8_t ff_h263_intra_MCBPC_code[9]
const uint8_t ff_h263_cbpy_tab[16][2]
static void skip_put_bits(PutBitContext *s, int n)
Skip the given number of bits.
void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int min_qcoeff
minimum encodable coefficient
#define FF_ASPECT_EXTENDED
static uint32_t uni_mpeg4_intra_rl_bits[64 *64 *2 *2]
uint8_t * intra_ac_vlc_length
#define UNI_AC_ENC_INDEX(run, level)
int mb_num
number of MBs of a picture
static int get_p_cbp(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
int time_base
time in seconds of last I,P,S Frame
static void init_uni_dc_tab(void)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define FF_BUG_MS
Work around various bugs in Microsoft's broken decoders.
void ff_mpeg4_stuffing(PutBitContext *pbc)
add mpeg4 stuffing bits (01...1)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static uint8_t uni_DCtab_chrom_len[512]
int8_t * max_run[2]
encoding & decoding
int64_t time
time of current frame
static void mpeg4_encode_block(MpegEncContext *s, DCTELEM *block, int n, int intra_dc, uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
Encode an 8x8 block.
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4) ...
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
PutBitContext pb2
used for data partitioned VOPs
const uint8_t ff_h263_intra_MCBPC_bits[9]
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
int misc_bits
cbp, mb_type
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
const uint8_t ff_h263_inter_MCBPC_bits[28]
int resync_marker
could this stream contain resync markers
Picture current_picture
copy of the current picture structure.
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
int8_t * max_level[2]
encoding & decoding
uint8_t idct_permutation[64]
idct input permutation.
int flags2
AVCodecContext.flags2.
int max_qcoeff
maximum encodable coefficient
static const int dquant_code[5]
void mpeg4_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y)
static uint32_t uni_mpeg4_inter_rl_bits[64 *64 *2 *2]
static int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level, int *dir_ptr, int encoding)
Predict the dc.
int dquant
qscale difference to prev qscale
#define UNI_MPEG4_ENC_INDEX(last, run, level)
static int init(AVCodecParserContext *s)
#define ROUNDED_DIV(a, b)
static void mpeg4_encode_gop_header(MpegEncContext *s)
static int get_bits_diff(MpegEncContext *s)
void ff_mpeg4_init_partitions(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_DIRECT
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
uint8_t * inter_ac_vlc_last_length
void ff_mpeg4_merge_partitions(MpegEncContext *s)
int mb_skipped
MUST BE SET only during DECODING.
int strict_std_compliance
strictly follow the std (MPEG4, ...)
int MPV_encode_end(AVCodecContext *avctx)
int partitioned_frame
is current frame partitioned
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
const char * name
Name of the codec implementation.
int quarter_sample
1->qpel, 0->half pel ME/MC
uint16_t * mb_type
Table for candidate MB types for encoding.
av_const int ff_h263_aspect_to_info(AVRational aspect)
Return the 4 bit value that specifies the given aspect ratio.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
int low_delay
no reordering needed / has no b-frames
#define CODEC_FLAG_AC_PRED
H.263 advanced intra coding / MPEG-4 AC prediction.
void(* clear_block)(DCTELEM *block)
static int put_bits_count(PutBitContext *s)
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is acually possible in h263 (limit difference to -2..2)
uint8_t * intra_ac_vlc_last_length
#define ADV_SIMPLE_VO_TYPE
const uint8_t ff_mpeg4_DCtab_lum[13][2]
uint8_t ff_mpeg4_static_rl_table_store[3][2][2 *MAX_RUN+MAX_LEVEL+3]
int n
number of entries of table_vlc minus 1
void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
const uint8_t ff_mpeg4_y_dc_scale_table[32]
const uint16_t(* table_vlc)[2]
Picture new_picture
copy of the source picture structure for encoding.
static uint8_t uni_mpeg4_inter_rl_len[64 *64 *2 *2]
static int get_b_cbp(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y, int mb_type)
int type
type of the buffer (to keep track of who has to deallocate data[*])
Picture * current_picture_ptr
pointer to the current picture
#define FF_PROFILE_UNKNOWN
static const AVClass mpeg4enc_class
static uint16_t uni_DCtab_lum_bits[512]
static uint16_t uni_DCtab_chrom_bits[512]
static uint8_t uni_DCtab_lum_len[512]
int block_last_index[12]
last non zero coefficient in block
static int decide_ac_pred(MpegEncContext *s, DCTELEM 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 mpeg4.
const uint8_t ff_h263_inter_MCBPC_code[28]
int ac_esc_length
num of bits needed to encode the longest esc
static void set_put_bits_buffer_size(PutBitContext *s, int size)
Change the end of the buffer.
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
int block_index[6]
index to current MB in block based arrays with edges
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
#define MV_TYPE_16X16
1 vector for the whole mb
uint8_t * luma_dc_vlc_length
static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab)
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
main external API structure.
static void close(AVCodecParserContext *s)
ScanTable intra_scantable
int height
picture size. must be a multiple of 16
int16_t(*[2] motion_val)[2]
motion vector table
int data_partitioning
data partitioning flag from header
uint8_t * inter_ac_vlc_length
uint16_t * intra_matrix
custom intra quantization matrix
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
ScanTable intra_h_scantable
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static av_cold int encode_init(AVCodecContext *avctx)
static void ff_h263_encode_motion_vector(MpegEncContext *s, int x, int y, int f_code)
DSPContext dsp
pointers for accelerated dsp functions
int f_code
forward MV resolution
static void mpeg4_encode_blocks(MpegEncContext *s, DCTELEM block[6][64], int intra_dc[6], uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
static int mpeg4_get_block_length(MpegEncContext *s, DCTELEM *block, int n, int intra_dc, uint8_t *scan_table)
uint16_t * inter_matrix
custom inter quantization matrix
int max_b_frames
max number of b-frames for encoding
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
DCTELEM(* block)[64]
points to one of the following blocks
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
int8_t * qscale_table
QP table.
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
struct AVCodecContext * avctx
#define CODEC_FLAG_CLOSED_GOP
PutBitContext pb
bit output
#define VISUAL_OBJ_STARTCODE
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
static int get_block_rate(MpegEncContext *s, DCTELEM block[64], int block_last_index, uint8_t scantable[64])
Return the number of bits that encoding the 8x8 block in block would need.
static const AVOption options[]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int get_rl_index(const RLTable *rl, int last, int run, int level)
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
int last_bits
temp var used for calculating the above vars
int top_field_first
If the content is interlaced, is top field displayed first.
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
PutBitContext tex_pb
used for data partitioned VOPs
Picture next_picture
copy of the next picture structure.
int linesize
line size, in bytes, may be different from width
uint8_t * mbskip_table
mbskip_table[mb]>=1 if MB didn't change stride= mb_width = (width+15)>>4
Picture ** reordered_input_picture
pointer to the next pictures in codedorder for encoding
int flags
AVCodecContext.flags (HQ, MV4, ...)
int workaround_bugs
workaround bugs in encoders which cannot be detected automatically
static int mpeg4_get_dc_length(int level, int n)
void ff_set_mpeg4_time(MpegEncContext *s)
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define FF_BUFFER_TYPE_SHARED
Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared...
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
int b_code
backward MV resolution for B Frames (mpeg4)
static void mpeg4_encode_dc(PutBitContext *s, int level, int n)
Encode the dc value.
static void mpeg4_encode_vol_header(MpegEncContext *s, int vo_number, int vol_number)