Go to the documentation of this file.
30 #include "config_components.h"
68 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
72 for (
int f_code = 1; f_code <=
MAX_FCODE; f_code++) {
80 bit_size = f_code - 1;
106 for (
int slevel = -64; slevel < 64; slevel++) {
107 if (slevel == 0)
continue;
109 for (
int last = 0; last <= 1; last++) {
111 int level = slevel < 0 ? -slevel : slevel;
112 int sign = slevel < 0 ? 1 : 0;
115 len_tab[
index] = 100;
170 int bit_size = f_code - 1;
171 int range = 1 << bit_size;
189 #if CONFIG_H263_ENCODER // Snow and SVQ1 need the above
190 static const uint8_t wrong_run[102] = {
191 1, 2, 3, 5, 4, 10, 9, 8,
192 11, 15, 17, 16, 23, 22, 21, 20,
193 19, 18, 25, 24, 27, 26, 11, 7,
194 6, 1, 2, 13, 2, 2, 2, 2,
195 6, 12, 3, 9, 1, 3, 4, 3,
196 7, 4, 1, 1, 5, 5, 14, 6,
197 1, 7, 1, 8, 1, 1, 1, 1,
198 10, 1, 1, 5, 9, 17, 25, 24,
199 29, 33, 32, 41, 2, 23, 28, 31,
200 3, 22, 30, 4, 27, 40, 8, 26,
201 6, 39, 7, 38, 16, 37, 15, 10,
202 11, 12, 13, 14, 1, 21, 20, 18,
228 int format, coded_frame_rate, coded_frame_rate_base,
i, temp_ref;
229 int best_clock_code=1;
231 int best_error= INT_MAX;
239 div= (
s->c.avctx->time_base.num*1800000LL + 500LL*
s->c.avctx->time_base.den) / ((1000LL+
i)*
s->c.avctx->time_base.den);
241 error=
FFABS(
s->c.avctx->time_base.num*1800000LL - (1000LL+
i)*
s->c.avctx->time_base.den*div);
242 if(
error < best_error){
249 custom_pcf = best_clock_code != 1 || best_divisor != 60;
250 coded_frame_rate= 1800000;
251 coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
254 temp_ref=
s->c.picture_number * (
int64_t)coded_frame_rate *
s->c.avctx->time_base.num /
255 (coded_frame_rate_base * (
int64_t)
s->c.avctx->time_base.den);
296 put_bits(&
s->pb,1,
s->c.h263_slice_structured);
324 put_bits(&
s->pb, 8,
s->c.avctx->sample_aspect_ratio.num);
325 put_bits(&
s->pb, 8,
s->c.avctx->sample_aspect_ratio.den);
341 if(
s->c.h263_slice_structured)
349 if(
s->c.h263_slice_structured){
368 if(
s->c.h263_slice_structured){
373 if(
s->c.mb_num > 1583)
379 int gob_number= mb_line /
s->c.gob_index;
392 int8_t *
const qscale_table =
s->c.cur_pic.qscale_table;
394 for (
int i = 1;
i <
s->c.mb_num;
i++) {
395 if (qscale_table[
s->c.mb_index2xy[
i] ] - qscale_table[
s->c.mb_index2xy[
i-1] ] > 2)
396 qscale_table[
s->c.mb_index2xy[
i] ] = qscale_table[
s->c.mb_index2xy[
i-1] ] + 2;
398 for(
int i =
s->c.mb_num - 2;
i >= 0;
i--) {
399 if (qscale_table[
s->c.mb_index2xy[
i] ] - qscale_table[
s->c.mb_index2xy[
i+1] ] > 2)
400 qscale_table[
s->c.mb_index2xy[
i] ] = qscale_table[
s->c.mb_index2xy[
i+1] ] + 2;
404 for (
int i = 1;
i <
s->c.mb_num;
i++) {
405 int mb_xy =
s->c.mb_index2xy[
i];
407 if (qscale_table[mb_xy] != qscale_table[
s->c.mb_index2xy[
i - 1]] &&
424 int level,
run, last,
i, j, last_index, last_non_zero, sign, slevel,
code;
428 if (
s->c.mb_intra && !
s->c.h263_aic) {
437 else if (
level < 1) {
448 if (
s->c.h263_aic &&
s->c.mb_intra)
451 if(
s->c.alt_inter_vlc && !
s->c.mb_intra){
453 int inter_vlc_bits=0;
457 last_index =
s->c.block_last_index[n];
458 last_non_zero =
i - 1;
459 for (;
i <= last_index;
i++) {
460 j =
s->c.intra_scantable.permutated[
i];
463 run =
i - last_non_zero - 1;
464 last = (
i == last_index);
474 inter_vlc_bits += 1+6+8-1;
477 aic_vlc_bits += 1+6+8-1;
478 wrong_pos +=
run + 1;
480 wrong_pos += wrong_run[aic_code];
485 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
491 last_index =
s->c.block_last_index[n];
492 last_non_zero =
i - 1;
493 for (;
i <= last_index;
i++) {
494 j =
s->c.intra_scantable.permutated[
i];
497 run =
i - last_non_zero - 1;
498 last = (
i == last_index);
508 if(!CONFIG_FLV_ENCODER ||
s->c.h263_flv <= 1){
550 sval = ((
val < 0) ? (
short)(-
val):(
short)
val);
553 while (temp_val != 0) {
554 temp_val = temp_val >> 1;
560 tcode = (sval & (1 << (
i-1))) >> (
i-1);
561 tcode = (tcode << 1) | 1;
570 static int h263_pred_dc(
MPVEncContext *
const s,
int n, int16_t **dc_val_ptr)
577 x = 2 *
s->c.mb_x + (n & 1);
578 y = 2 *
s->c.mb_y + ((n & 2) >> 1);
579 wrap =
s->c.b8_stride;
580 dc_val =
s->c.dc_val[0];
584 wrap =
s->c.mb_stride;
585 dc_val =
s->c.dc_val[n - 4 + 1];
590 a = dc_val[(x - 1) + (y) *
wrap];
591 c = dc_val[(x) + (y - 1) *
wrap];
594 if (
s->c.first_slice_line && n != 3) {
595 if (n != 2)
c = 1024;
596 if (n != 1 &&
s->c.mb_x ==
s->c.resync_mb_x)
a = 1024;
599 if (
a != 1024 &&
c != 1024)
607 *dc_val_ptr = &dc_val[x + y *
wrap];
613 int motion_x,
int motion_y)
615 int cbpc, cbpy,
i, cbp, pred_x, pred_y;
617 int16_t rec_intradc[6];
621 if (!
s->c.mb_intra) {
625 if ((cbp | motion_x | motion_y |
s->dquant | (
s->c.mv_type -
MV_TYPE_16X16)) == 0) {
628 if(interleaved_stats){
639 if(
s->c.alt_inter_vlc==0 || cbpc!=3)
641 if(
s->dquant) cbpc+= 8;
651 if(interleaved_stats){
660 motion_y - pred_y, 1);
663 h263p_encode_umotion(&
s->pb, motion_x - pred_x);
664 h263p_encode_umotion(&
s->pb, motion_y - pred_y);
665 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
677 if(interleaved_stats){
685 motion_x =
s->c.cur_pic.motion_val[0][
s->c.block_index[
i]][0];
686 motion_y =
s->c.cur_pic.motion_val[0][
s->c.block_index[
i]][1];
689 motion_y - pred_y, 1);
692 h263p_encode_umotion(&
s->pb, motion_x - pred_x);
693 h263p_encode_umotion(&
s->pb, motion_y - pred_y);
694 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
701 if(interleaved_stats){
712 int scale =
i < 4 ?
s->c.y_dc_scale :
s->c.c_dc_scale;
722 if (!
s->c.modified_quant) {
725 else if (
level > 127)
737 if (rec_intradc[
i] < 0)
739 else if (rec_intradc[
i] > 2047)
740 rec_intradc[
i] = 2047;
743 *dc_ptr[
i] = rec_intradc[
i];
745 if (
s->c.block_last_index[
i] > 0 ||
746 (
s->c.block_last_index[
i] == 0 &&
level !=0))
752 if (
s->c.block_last_index[
i] >= 1)
759 if(
s->dquant) cbpc+=4;
764 if(
s->dquant) cbpc+=8;
779 if(interleaved_stats){
789 if (
s->c.h263_aic &&
s->c.mb_intra)
793 if(interleaved_stats){
794 if (!
s->c.mb_intra) {
805 const int mb_xy =
s->c.mb_y *
s->c.mb_stride +
s->c.mb_x;
807 if (
s->c.cur_pic.mbskip_table)
808 s->c.cur_pic.mbskip_table[mb_xy] =
s->c.mb_skipped;
812 else if(
s->c.mb_intra)
837 s->c.y_dc_scale_table =
840 s->ac_esc_length= 7+1+6+8;
842 if (
s->c.modified_quant)
849 switch(
s->c.codec_id){
853 if (
s->c.modified_quant) {
854 s->min_qcoeff= -2047;
862 #if CONFIG_FLV_ENCODER
865 if (
s->c.h263_flv > 1) {
866 s->min_qcoeff= -1023;
882 s->encode_mb = h263_encode_mb;
892 mb_pos=
s->c.mb_x +
s->c.mb_width*
s->c.mb_y;
896 #define OFFSET(x) offsetof(MpegEncContext, x)
897 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
898 static const AVOption h263_options[] = {
900 {
"mb_info",
"emit macroblock info for RFC 2190 packetization, the parameter value is the maximum payload size",
FF_MPV_OFFSET(
mb_info),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
906 static const AVClass h263_class = {
909 .option = h263_options,
920 .p.priv_class = &h263_class,
929 static const AVOption h263p_options[] = {
933 {
"structured_slices",
"Write slice start position at every GOB header instead of just GOB number.",
OFFSET(h263_slice_structured),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE},
938 static const AVClass h263p_class = {
941 .option = h263p_options,
952 .p.priv_class = &h263p_class,
static void error(const char *err)
const uint8_t * fcode_tab
smallest fcode needed for each MV
#define CODEC_PIXFMTS(...)
#define MV_TYPE_16X16
1 vector for the whole mb
#define FF_ASPECT_EXTENDED
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define H263_GOB_HEIGHT(h)
static uint8_t uni_h263_inter_rl_len[64 *64 *2 *2]
#define UNI_MPEG4_ENC_INDEX(last, run, level)
static const int8_t mv[256][2]
static void put_sbits(PutBitContext *pb, int n, int32_t value)
void ff_clean_h263_qscales(MPVEncContext *s)
#define CANDIDATE_MB_TYPE_INTER
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
int(* encode_picture_header)(struct MPVMainEncContext *m)
#define FF_MPV_COMMON_MOTION_EST_OPTS
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
#define FF_MPV_COMMON_OPTS
AVCodec p
The public AVCodec.
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
const AVRational ff_h263_pixel_aspect[16]
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Table of number of bits a motion vector component needs.
void ff_h263_encode_init(MPVMainEncContext *m)
static double val(void *priv, double ch)
#define FF_CODEC_ENCODE_CB(func)
void ff_h263_update_motion_val(MpegEncContext *s)
static const int dquant_code[5]
int n
number of entries of table_vlc minus 1
static int ff_thread_once(char *control, void(*routine)(void))
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
#define FF_ARRAY_ELEMS(a)
void ff_h263_encode_gob_header(MPVEncContext *s, int mb_line)
const uint8_t ff_h263_chroma_qscale_table[32]
static int get_rl_index(const RLTable *rl, int last, int run, int level)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const av_cold uint8_t(* ff_h263_get_mv_penalty(void))[MAX_DMV *2+1]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
void ff_h263_encode_mba(MPVEncContext *s)
av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Initialize index_run, max_level and max_run from n, last, table_vlc, table_run and table_level.
#define CODEC_LONG_NAME(str)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
static av_cold void init_mv_penalty_and_fcode(void)
const uint16_t(* table_vlc)[2]
Rational number (pair of numerator and denominator).
static uint8_t uni_h263_intra_aic_rl_len[64 *64 *2 *2]
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
const uint16_t ff_mba_max[6]
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
static int get_p_cbp(MPVEncContext *const s, int16_t block[6][64], int motion_x, int motion_y)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static void put_bits_assume_flushed(const PutBitContext *s)
Inform the compiler that a PutBitContext is flushed (i.e.
const uint8_t ff_h263_cbpy_tab[16][2]
const FFCodec ff_h263p_encoder
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
const uint8_t ff_h263_inter_MCBPC_bits[28]
static void FUNC() pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
#define CANDIDATE_MB_TYPE_INTER4V
static int get_bits_diff(MPVEncContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
const FFCodec ff_h263_encoder
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
void ff_h263_update_mb(MPVEncContext *s)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const uint16_t ff_h263_format[8][2]
const char * name
Name of the codec implementation.
av_const int ff_h263_aspect_to_info(AVRational aspect)
int ff_flv_encode_picture_header(MPVMainEncContext *const m)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_cold void h263_encode_init_static(void)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const uint8_t ff_aic_dc_scale_table[32]
const uint8_t ff_mvtab[33][2]
const uint8_t ff_h263_intra_MCBPC_bits[9]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your see the OFFSET() macro
const uint8_t ff_h263_intra_MCBPC_code[9]
static uint8_t umv_fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need in umv.
@ AV_OPT_TYPE_INT
Underlying C type is int.
static av_const int sign_extend(int val, unsigned bits)
const uint8_t ff_mba_length[7]
const uint8_t ff_h263_inter_MCBPC_code[28]
@ AV_PICTURE_TYPE_P
Predicted.
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static void ff_h263_encode_motion_vector(MPVEncContext *s, int x, int y, int f_code)
The exact code depends on how similar the blocks are and how related they are to the block
av_cold void ff_h263_init_rl_inter(void)
MPVEncContext s
The main slicecontext.
#define MB_TYPE_FORWARD_MV
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.