summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/mpegvideo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/mpegvideo.c')
-rw-r--r--src/libffmpeg/libavcodec/mpegvideo.c299
1 files changed, 250 insertions, 49 deletions
diff --git a/src/libffmpeg/libavcodec/mpegvideo.c b/src/libffmpeg/libavcodec/mpegvideo.c
index 8206df470..d721647a5 100644
--- a/src/libffmpeg/libavcodec/mpegvideo.c
+++ b/src/libffmpeg/libavcodec/mpegvideo.c
@@ -20,6 +20,7 @@
*/
#include <ctype.h>
+#include <limits.h>
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
@@ -80,12 +81,15 @@ static const uint8_t simple_mmx_permutation[64]={
};
static const uint8_t h263_chroma_roundtab[16] = {
+// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
};
static UINT16 (*default_mv_penalty)[MAX_MV*2+1]=NULL;
static UINT8 default_fcode_tab[MAX_MV*2+1];
+enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
+
static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64],
const UINT16 *quant_matrix, int bias, int qmin, int qmax)
{
@@ -230,6 +234,8 @@ int DCT_common_init(MpegEncContext *s)
MPV_common_init_ppc(s);
#endif
+ s->fast_dct_quantize= s->dct_quantize;
+
if(s->flags&CODEC_FLAG_TRELLIS_QUANT){
s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_*
}
@@ -286,7 +292,7 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
if(r<0 || !pic->age || !pic->type || !pic->data[0]){
- fprintf(stderr, "get_buffer() failed (%d %d %d %X)\n", r, pic->age, pic->type, (int)pic->data[0]);
+ fprintf(stderr, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
return -1;
}
@@ -309,6 +315,7 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
CHECKED_ALLOCZ(pic->mb_var , s->mb_num * sizeof(INT16))
CHECKED_ALLOCZ(pic->mc_mb_var, s->mb_num * sizeof(INT16))
CHECKED_ALLOCZ(pic->mb_mean , s->mb_num * sizeof(INT8))
+ CHECKED_ALLOCZ(pic->mb_cmp_score, s->mb_num * sizeof(int32_t))
}
CHECKED_ALLOCZ(pic->mbskip_table , s->mb_num * sizeof(UINT8)+1) //the +1 is for the slice end check
@@ -316,6 +323,12 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
pic->qstride= s->mb_width;
}
+ //it might be nicer if the application would keep track of these but it would require a API change
+ memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
+ s->prev_pict_types[0]= s->pict_type;
+ if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE)
+ pic->age= INT_MAX; // skiped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway
+
return 0;
fail: //for the CHECKED_ALLOCZ macro
return -1;
@@ -334,6 +347,7 @@ static void free_picture(MpegEncContext *s, Picture *pic){
av_freep(&pic->mb_var);
av_freep(&pic->mc_mb_var);
av_freep(&pic->mb_mean);
+ av_freep(&pic->mb_cmp_score);
av_freep(&pic->mbskip_table);
av_freep(&pic->qscale_table);
@@ -472,6 +486,7 @@ int MPV_common_init(MpegEncContext *s)
/* init macroblock skip table */
CHECKED_ALLOCZ(s->mbskip_table, s->mb_num+1);
//Note the +1 is for a quicker mpeg4 slice_end detection
+ CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
s->block= s->blocks[0];
@@ -511,6 +526,7 @@ void MPV_common_end(MpegEncContext *s)
av_freep(&s->me.score_map);
av_freep(&s->mbskip_table);
+ av_freep(&s->prev_pict_types);
av_freep(&s->bitstream_buffer);
av_freep(&s->tex_pb_buffer);
av_freep(&s->pb2_buffer);
@@ -609,6 +625,7 @@ int MPV_encode_init(AVCodecContext *avctx)
avctx->delay=0;
s->low_delay=1;
break;
+#ifdef CONFIG_RISKY
case CODEC_ID_H263:
if (h263_get_picture_format(s->width, s->height) == 7) {
printf("Input picture size isn't suitable for h263 codec! try h263+\n");
@@ -688,6 +705,7 @@ int MPV_encode_init(AVCodecContext *avctx)
avctx->delay=0;
s->low_delay=1;
break;
+#endif
default:
return -1;
}
@@ -725,24 +743,29 @@ int MPV_encode_init(AVCodecContext *avctx)
ff_init_me(s);
#ifdef CONFIG_ENCODERS
+#ifdef CONFIG_RISKY
if (s->out_format == FMT_H263)
h263_encode_init(s);
- else if (s->out_format == FMT_MPEG1)
- ff_mpeg1_encode_init(s);
if(s->msmpeg4_version)
ff_msmpeg4_encode_init(s);
#endif
+ if (s->out_format == FMT_MPEG1)
+ ff_mpeg1_encode_init(s);
+#endif
/* init default q matrix */
for(i=0;i<64;i++) {
int j= s->idct_permutation[i];
+#ifdef CONFIG_RISKY
if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
}else if(s->out_format == FMT_H263){
s->intra_matrix[j] =
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }else{ /* mpeg1 */
+ }else
+#endif
+ { /* mpeg1 */
s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
}
@@ -787,6 +810,44 @@ int MPV_encode_end(AVCodecContext *avctx)
return 0;
}
+void init_rl(RLTable *rl)
+{
+ INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
+ UINT8 index_run[MAX_RUN+1];
+ int last, run, level, start, end, i;
+
+ /* compute max_level[], max_run[] and index_run[] */
+ for(last=0;last<2;last++) {
+ if (last == 0) {
+ start = 0;
+ end = rl->last;
+ } else {
+ start = rl->last;
+ end = rl->n;
+ }
+
+ memset(max_level, 0, MAX_RUN + 1);
+ memset(max_run, 0, MAX_LEVEL + 1);
+ memset(index_run, rl->n, MAX_RUN + 1);
+ for(i=start;i<end;i++) {
+ run = rl->table_run[i];
+ level = rl->table_level[i];
+ if (index_run[run] == rl->n)
+ index_run[run] = i;
+ if (level > max_level[run])
+ max_level[run] = level;
+ if (run > max_run[level])
+ max_run[level] = run;
+ }
+ rl->max_level[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
+ rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
+ memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
+ rl->index_run[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
+ }
+}
+
/* draw the edges of width 'w' of an image of size width, height */
//FIXME check that this is ok for mpeg4 interlaced
static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w)
@@ -1292,11 +1353,10 @@ static inline void gmc1_motion(MpegEncContext *s,
dest_y+=dest_offset;
if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->h_edge_pos
- || src_y + (motion_y&15) + 16 > s->v_edge_pos){
+ if(src_x<0 || src_y<0 || src_x + 17 >= s->h_edge_pos
+ || src_y + 17 >= s->v_edge_pos){
ff_emulated_edge_mc(s, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer;
- emu=1;
}
}
@@ -1331,9 +1391,13 @@ static inline void gmc1_motion(MpegEncContext *s,
offset = (src_y * uvlinesize) + src_x + (src_offset>>1);
ptr = ref_picture[1] + offset;
- if(emu){
- ff_emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
+ if(s->flags&CODEC_FLAG_EMU_EDGE){
+ if(src_x<0 || src_y<0 || src_x + 9 >= s->h_edge_pos>>1
+ || src_y + 9 >= s->v_edge_pos>>1){
+ ff_emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
+ ptr= s->edge_emu_buffer;
+ emu=1;
+ }
}
s->dsp.gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
@@ -1656,6 +1720,14 @@ static inline void qpel_motion(MpegEncContext *s,
pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
}
+inline int ff_h263_round_chroma(int x){
+ if (x >= 0)
+ return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
+ else {
+ x = -x;
+ return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
+ }
+}
static inline void MPV_motion(MpegEncContext *s,
UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
@@ -1672,6 +1744,7 @@ static inline void MPV_motion(MpegEncContext *s,
switch(s->mv_type) {
case MV_TYPE_16X16:
+#ifdef CONFIG_RISKY
if(s->mcsel){
if(s->real_sprite_warping_points==1){
gmc1_motion(s, dest_y, dest_cb, dest_cr, 0,
@@ -1689,7 +1762,9 @@ static inline void MPV_motion(MpegEncContext *s,
ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else{
+ }else
+#endif
+ {
mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
ref_picture, 0,
0, pix_op,
@@ -1766,20 +1841,8 @@ static inline void MPV_motion(MpegEncContext *s,
if(s->flags&CODEC_FLAG_GRAY) break;
/* In case of 8X8, we construct a single chroma motion vector
with a special rounding */
- for(i=0;i<4;i++) {
- }
- if (mx >= 0)
- mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1));
- else {
- mx = -mx;
- mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1));
- }
- if (my >= 0)
- my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1));
- else {
- my = -my;
- my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1));
- }
+ mx= ff_h263_round_chroma(mx);
+ my= ff_h263_round_chroma(my);
dxy = ((my & 1) << 1) | (mx & 1);
mx >>= 1;
my >>= 1;
@@ -2010,14 +2073,13 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
if(*mbskip_ptr >99) *mbskip_ptr= 99;
/* if previous was skipped too, then nothing to do ! */
- if (*mbskip_ptr >= age){
-//if(s->pict_type!=B_TYPE && s->mb_x==0) printf("\n");
-//if(s->pict_type!=B_TYPE) printf("%d%d ", *mbskip_ptr, age);
- if(s->pict_type!=B_TYPE) return;
- if(s->avctx->draw_horiz_band==NULL && *mbskip_ptr > age) return;
- /* we dont draw complete frames here so we cant skip */
+ if (*mbskip_ptr >= age && s->current_picture.reference){
+ return;
}
- } else {
+ } else if(!s->current_picture.reference){
+ (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */
+ if(*mbskip_ptr >99) *mbskip_ptr= 99;
+ } else{
*mbskip_ptr = 0; /* not skipped */
}
}else
@@ -2088,9 +2150,12 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
add_dct(s, block[4], 4, dest_cb, s->uvlinesize);
add_dct(s, block[5], 5, dest_cr, s->uvlinesize);
}
- } else{
+ }
+#ifdef CONFIG_RISKY
+ else{
ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
}
+#endif
} else {
/* dct only in intra block */
if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){
@@ -2585,7 +2650,7 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
s->block_last_index[4]=
s->block_last_index[5]= 0;
s->block[4][0]=
- s->block[5][0]= 128;
+ s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale;
}
#ifdef CONFIG_ENCODERS
@@ -2593,6 +2658,7 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
switch(s->codec_id){ //FIXME funct ptr could be slightly faster
case CODEC_ID_MPEG1VIDEO:
mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
+#ifdef CONFIG_RISKY
case CODEC_ID_MPEG4:
mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
case CODEC_ID_MSMPEG4V2:
@@ -2601,18 +2667,48 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
case CODEC_ID_WMV2:
ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MJPEG:
- mjpeg_encode_mb(s, s->block); break;
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_RV10:
h263_encode_mb(s, s->block, motion_x, motion_y); break;
+#endif
+ case CODEC_ID_MJPEG:
+ mjpeg_encode_mb(s, s->block); break;
default:
assert(0);
}
#endif
}
+/**
+ * combines the (truncated) bitstream to a complete frame
+ * @returns -1 if no complete frame could be created
+ */
+int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){
+ ParseContext *pc= &s->parse_context;
+
+ pc->last_index= pc->index;
+
+ if(next==-1){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, *buf_size);
+ pc->index += *buf_size;
+ return -1;
+ }
+
+ if(pc->index){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
+ pc->index = 0;
+ *buf= pc->buffer;
+ *buf_size= pc->last_index + next;
+ }
+
+ return 0;
+}
+
void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length)
{
int bytes= length>>4;
@@ -2769,10 +2865,12 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->current_picture.mb_var_sum = 0;
s->current_picture.mc_mb_var_sum = 0;
+#ifdef CONFIG_RISKY
/* we need to initialize some time vars before we can encode b-frames */
if (s->h263_pred && !s->h263_msmpeg4)
ff_set_mpeg4_time(s, s->picture_number);
-
+#endif
+
s->scene_change_score=0;
s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration
@@ -2789,6 +2887,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->no_rounding ^= 1;
}
/* Estimate motion for every MB */
+ s->mb_intra=0; //for the rate distoration & bit compare functions
if(s->pict_type != I_TYPE){
if(s->pict_type != B_TYPE){
if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){
@@ -2880,6 +2979,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->frame_qscale = ff_rate_estimate_qscale(s);
if(s->adaptive_quant){
+#ifdef CONFIG_RISKY
switch(s->codec_id){
case CODEC_ID_MPEG4:
ff_clean_mpeg4_qscales(s);
@@ -2889,6 +2989,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
ff_clean_h263_qscales(s);
break;
}
+#endif
s->qscale= s->current_picture.qscale_table[0];
}else
@@ -2918,6 +3019,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
case FMT_MJPEG:
mjpeg_picture_header(s);
break;
+#ifdef CONFIG_RISKY
case FMT_H263:
if (s->codec_id == CODEC_ID_WMV2)
ff_wmv2_encode_picture_header(s, picture_number);
@@ -2930,6 +3032,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
else
h263_encode_picture_header(s, picture_number);
break;
+#endif
case FMT_MPEG1:
mpeg1_encode_picture_header(s, picture_number);
break;
@@ -2957,11 +3060,13 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->last_mv[0][0][0] = 0;
s->last_mv[0][0][1] = 0;
+#ifdef CONFIG_RISKY
if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P)
s->gob_index = ff_h263_get_gob_height(s);
if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_init_partitions(s);
+#endif
s->resync_mb_x=0;
s->resync_mb_y=0;
@@ -2979,7 +3084,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2);
s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x];
+ int mb_type= s->mb_type[mb_y * s->mb_width + mb_x];
const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1;
// int d;
int dmin=10000000;
@@ -2994,6 +3099,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->block_index[5]++;
/* write gob / video packet header */
+#ifdef CONFIG_RISKY
if(s->rtp_mode){
int current_packet_size, is_gob_start;
@@ -3034,6 +3140,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->resync_mb_y=mb_y;
}
}
+#endif
if( (s->resync_mb_x == s->mb_x)
&& s->resync_mb_y+1 == s->mb_y){
@@ -3108,7 +3215,9 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
s->mb_intra= 0;
+#ifdef CONFIG_RISKY
ff_mpeg4_set_direct_mv(s, mx, my);
+#endif
encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb,
&dmin, &next_block, mx, my);
}
@@ -3145,8 +3254,93 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->last_bits= get_bit_count(&s->pb);
} else {
int motion_x, motion_y;
+ int intra_score;
+ int inter_score= s->current_picture.mb_cmp_score[mb_x + mb_y*s->mb_width];
+
+ if(!(s->flags&CODEC_FLAG_HQ) && s->pict_type==P_TYPE){
+ /* get luma score */
+ if((s->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
+ intra_score= (s->current_picture.mb_var[mb_x + mb_y*s->mb_width]<<8) - 500; //FIXME dont scale it down so we dont have to fix it
+ }else{
+ uint8_t *dest_y;
+
+ int mean= s->current_picture.mb_mean[mb_x + mb_y*s->mb_width]; //FIXME
+ mean*= 0x01010101;
+
+ dest_y = s->new_picture.data[0] + (mb_y * 16 * s->linesize ) + mb_x * 16;
+
+ for(i=0; i<16; i++){
+ *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 0]) = mean;
+ *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 4]) = mean;
+ *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 8]) = mean;
+ *(uint32_t*)(&s->me.scratchpad[i*s->linesize+12]) = mean;
+ }
+
+ s->mb_intra=1;
+ intra_score= s->dsp.mb_cmp[0](s, s->me.scratchpad, dest_y, s->linesize);
+
+/* printf("intra:%7d inter:%7d var:%7d mc_var.%7d\n", intra_score>>8, inter_score>>8,
+ s->current_picture.mb_var[mb_x + mb_y*s->mb_width],
+ s->current_picture.mc_mb_var[mb_x + mb_y*s->mb_width]);*/
+ }
+
+ /* get chroma score */
+ if(s->avctx->mb_cmp&FF_CMP_CHROMA){
+ int i;
+
+ s->mb_intra=1;
+ for(i=1; i<3; i++){
+ uint8_t *dest_c;
+ int mean;
+
+ if(s->out_format == FMT_H263){
+ mean= (s->dc_val[i][mb_x + (mb_y+1)*(s->mb_width+2)] + 4)>>3; //FIXME not exact but simple ;)
+ }else{
+ mean= (s->last_dc[i] + 4)>>3;
+ }
+ dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
+
+ mean*= 0x01010101;
+ for(i=0; i<8; i++){
+ *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 0]) = mean;
+ *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 4]) = mean;
+ }
+
+ intra_score+= s->dsp.mb_cmp[1](s, s->me.scratchpad, dest_c, s->uvlinesize);
+ }
+ }
+
+ /* bias */
+ switch(s->avctx->mb_cmp&0xFF){
+ default:
+ case FF_CMP_SAD:
+ intra_score+= 32*s->qscale;
+ break;
+ case FF_CMP_SSE:
+ intra_score+= 24*s->qscale*s->qscale;
+ break;
+ case FF_CMP_SATD:
+ intra_score+= 96*s->qscale;
+ break;
+ case FF_CMP_DCT:
+ intra_score+= 48*s->qscale;
+ break;
+ case FF_CMP_BIT:
+ intra_score+= 16;
+ break;
+ case FF_CMP_PSNR:
+ case FF_CMP_RD:
+ intra_score+= (s->qscale*s->qscale*109*8 + 64)>>7;
+ break;
+ }
+
+ if(intra_score < inter_score)
+ mb_type= MB_TYPE_INTRA;
+ }
+
s->mv_type=MV_TYPE_16X16;
// only one MB-Type possible
+
switch(mb_type){
case MB_TYPE_INTRA:
s->mv_dir = MV_DIR_FORWARD;
@@ -3175,7 +3369,9 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->mb_intra= 0;
motion_x=s->b_direct_mv_table[xy][0];
motion_y=s->b_direct_mv_table[xy][1];
+#ifdef CONFIG_RISKY
ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
+#endif
break;
case MB_TYPE_BIDIR:
s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
@@ -3253,6 +3449,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
}
emms_c();
+#ifdef CONFIG_RISKY
if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_merge_partitions(s);
@@ -3261,6 +3458,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
if(s->codec_id==CODEC_ID_MPEG4)
ff_mpeg4_stuffing(&s->pb);
+#endif
//if (s->gob_number)
// fprintf(stderr,"\nNumber of GOB: %d", s->gob_number);
@@ -3376,7 +3574,7 @@ static int dct_quantize_trellis_c(MpegEncContext *s,
return last_non_zero;
}
- lambda= (qscale*qscale*64*82 + 50)/100; //FIXME finetune
+ lambda= (qscale*qscale*64*105 + 64)>>7; //FIXME finetune
score_tab[0]= 0;
for(i=0; i<=last_non_zero - start_i; i++){
@@ -3783,6 +3981,8 @@ AVCodec mpeg1video_encoder = {
MPV_encode_end,
};
+#ifdef CONFIG_RISKY
+
AVCodec h263_encoder = {
"h263",
CODEC_TYPE_VIDEO,
@@ -3813,16 +4013,6 @@ AVCodec rv10_encoder = {
MPV_encode_end,
};
-AVCodec mjpeg_encoder = {
- "mjpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
AVCodec mpeg4_encoder = {
"mpeg4",
CODEC_TYPE_VIDEO,
@@ -3873,3 +4063,14 @@ AVCodec wmv1_encoder = {
MPV_encode_end,
};
+#endif
+
+AVCodec mjpeg_encoder = {
+ "mjpeg",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MJPEG,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+};