1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

H261 fixing and cleaning:

-corrected wrong value in mv data
 -set correct mb_type after adjusting index
 -don't use H263 loop filter when the loop filter flag is set but when
  using the H261 encoder
 -use the same unquantizer as H263 (which is optimized btw)
 -removed unused members in H261Context
patch by (Maarten Daniels <maarten.daniels >at< luc >dot< ac >dot< be>)

regression test checksum update by me

Originally committed as revision 3669 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Maarten Daniels 2004-11-12 01:21:34 +00:00 committed by Michael Niedermayer
parent 5b6d559680
commit ccff9da62a
5 changed files with 18 additions and 91 deletions

View File

@ -53,8 +53,6 @@ typedef struct H261Context{
int current_mv_x;
int current_mv_y;
int gob_number;
int bits_left; //8 - nr of bits left of the following frame in the last byte in this frame
int last_bits; //bits left of the following frame in the last byte in this frame
int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
}H261Context;
@ -176,7 +174,7 @@ static void h261_encode_motion(H261Context * h, int val){
put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
}
else{
if(val > 16)
if(val > 15)
val -=32;
if(val < -16)
val+=32;
@ -847,24 +845,12 @@ static int h261_decode_gob(H261Context *h){
}
static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
int vop_found, i, j, bits_left, last_bits;
int vop_found, i, j;
uint32_t state;
H261Context *h = avctx->priv_data;
if(h){
bits_left = h->bits_left;
last_bits = h->last_bits;
}
else{
bits_left = 0;
last_bits = 0;
}
vop_found= pc->frame_start_found;
state= pc->state;
if(bits_left!=0 && !vop_found)
state = state << (8-bits_left) | last_bits;
i=0;
if(!vop_found){
for(i=0; i<buf_size; i++){

View File

@ -67,7 +67,7 @@ const uint8_t h261_mv_tab[17][2] = {
static const int mvmap[17] =
{
0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, 16
0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
};
//H.261 VLC table for coded block pattern

View File

@ -53,10 +53,6 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h263_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h261_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h261_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
#ifdef CONFIG_ENCODERS
static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
@ -219,8 +215,6 @@ int DCT_common_init(MpegEncContext *s)
{
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
s->dct_unquantize_h261_intra = dct_unquantize_h261_intra_c;
s->dct_unquantize_h261_inter = dct_unquantize_h261_inter_c;
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
@ -1482,12 +1476,9 @@ alloc:
if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){
s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
}else if(s->out_format == FMT_H263){
}else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
}else if(s->out_format == FMT_H261){
s->dct_unquantize_intra = s->dct_unquantize_h261_intra;
s->dct_unquantize_inter = s->dct_unquantize_h261_inter;
}else{
s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
@ -4517,6 +4508,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if(s->codec_id == CODEC_ID_H261){
ff_h261_reorder_mb_index(s);
xy= s->mb_y*s->mb_stride + s->mb_x;
mb_type= s->mb_type[xy];
}
/* write gob / video packet header */
@ -4990,8 +4982,10 @@ static int encode_thread(AVCodecContext *c, void *arg){
s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
s->dest[2], w>>1, h>>1, s->uvlinesize);
}
if(s->loop_filter)
ff_h263_loop_filter(s);
if(s->loop_filter){
if(s->out_format == FMT_H263)
ff_h263_loop_filter(s);
}
//printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb));
}
}
@ -6250,59 +6244,6 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
}
}
static void dct_unquantize_h261_intra_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, even;
int nCoeffs;
assert(s->block_last_index[n]>=0);
if (n < 4)
block[0] = block[0] * s->y_dc_scale;
else
block[0] = block[0] * s->c_dc_scale;
even = (qscale & 1)^1;
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
for(i=1; i<=nCoeffs; i++){
level = block[i];
if (level){
if (level < 0){
level = qscale * ((level << 1) - 1) + even;
}else{
level = qscale * ((level << 1) + 1) - even;
}
}
block[i] = level;
}
}
static void dct_unquantize_h261_inter_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, even;
int nCoeffs;
assert(s->block_last_index[n]>=0);
even = (qscale & 1)^1;
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
for(i=0; i<=nCoeffs; i++){
level = block[i];
if (level){
if (level < 0){
level = qscale * ((level << 1) - 1) + even;
}else{
level = qscale * ((level << 1) + 1) - even;
}
}
block[i] = level;
}
}
static const AVOption mpeg4_options[] =
{
AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000),

View File

@ -35,10 +35,10 @@ a5bd577163968edab00058f2c8d5efab *./data/a-wmv2.avi
682132 ./data/a-wmv2.avi
09253222ab4eb95628c931a86006a2b1 *./data/out.yuv
stddev: 8.02 PSNR:30.04 bytes:7602176
c12437d78325d6634ff77a49bf1869e8 *./data/a-h261.avi
779222 ./data/a-h261.avi
1dd0be7be463c1a338d1b848e926a0b8 *./data/out.yuv
stddev: 9.17 PSNR:28.87 bytes:7602176
bcf34887269746ac7973f88cde336609 *./data/a-h261.avi
735098 ./data/a-h261.avi
0a6e6dd4f09df9fe77ff29581c1a39c3 *./data/out.yuv
stddev: 9.14 PSNR:28.90 bytes:7602176
fa556e599181bf9328a811a1ce9aa022 *./data/a-h263.avi
682226 ./data/a-h263.avi
f2b7fcff9de17f5aecfeb1090fe1963b *./data/out.yuv

View File

@ -35,10 +35,10 @@ stddev: 5.33 PSNR:33.58 bytes:7602176
129214 ./data/a-wmv2.avi
f80d2809e79af3ebcfe831deab9af03c *./data/out.yuv
stddev: 5.33 PSNR:33.58 bytes:7602176
41050f885f7ea9594643e5dbf8ea30da *./data/a-h261.avi
193452 ./data/a-h261.avi
c74fbf0b0faf1124e172413c059ab45a *./data/out.yuv
stddev: 6.40 PSNR:31.99 bytes:7602176
631f4daabb4f639e8dec18bbb58dae79 *./data/a-h261.avi
191124 ./data/a-h261.avi
452714d0883f555e831888de0be1fc49 *./data/out.yuv
stddev: 6.39 PSNR:32.00 bytes:7602176
ef053b1fec77a49eb8a27510b81e4041 *./data/a-h263.avi
159596 ./data/a-h263.avi
7ec66fb7dd4e5dddd3820c668d6636aa *./data/out.yuv