Commit b056e73c authored by Michael Niedermayer's avatar Michael Niedermayer

h263+ custom pcf support

Originally committed as revision 2868 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 361b1b86
...@@ -197,15 +197,36 @@ void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number) ...@@ -197,15 +197,36 @@ void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
void h263_encode_picture_header(MpegEncContext * s, int picture_number) void h263_encode_picture_header(MpegEncContext * s, int picture_number)
{ {
int format; int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
int best_clock_code=1;
int best_divisor=60;
int best_error= INT_MAX;
if(s->h263_plus){
for(i=0; i<2; i++){
int div, error;
div= (s->avctx->frame_rate_base*1800000LL + 500LL*s->avctx->frame_rate) / ((1000LL+i)*s->avctx->frame_rate);
div= clip(1, div, 127);
error= ABS(s->avctx->frame_rate_base*1800000LL - (1000LL+i)*s->avctx->frame_rate*div);
if(error < best_error){
best_error= error;
best_divisor= div;
best_clock_code= i;
}
}
}
s->custom_pcf= best_clock_code!=1 || best_divisor!=60;
coded_frame_rate= 1800000;
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
align_put_bits(&s->pb); align_put_bits(&s->pb);
/* Update the pointer to last GOB */ /* Update the pointer to last GOB */
s->ptr_lastgob = pbBufPtr(&s->pb); s->ptr_lastgob = pbBufPtr(&s->pb);
put_bits(&s->pb, 22, 0x20); /* PSC */ put_bits(&s->pb, 22, 0x20); /* PSC */
put_bits(&s->pb, 8, ((s->picture_number * 30000LL * s->avctx->frame_rate_base) / temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->frame_rate_base /
(1001LL *s->avctx->frame_rate)) & 0xff); /* TemporalReference */ (coded_frame_rate_base * (int64_t)s->avctx->frame_rate);
put_bits(&s->pb, 8, temp_ref & 0xff); /* TemporalReference */
put_bits(&s->pb, 1, 1); /* marker */ put_bits(&s->pb, 1, 1); /* marker */
put_bits(&s->pb, 1, 0); /* h263 id */ put_bits(&s->pb, 1, 0); /* h263 id */
...@@ -228,16 +249,18 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number) ...@@ -228,16 +249,18 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits(&s->pb, 5, s->qscale); put_bits(&s->pb, 5, s->qscale);
put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
} else { } else {
int ufep=1;
/* H.263v2 */ /* H.263v2 */
/* H.263 Plus PTYPE */ /* H.263 Plus PTYPE */
put_bits(&s->pb, 3, 7); put_bits(&s->pb, 3, 7);
put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */
if (format == 7) if (format == 7)
put_bits(&s->pb,3,6); /* Custom Source Format */ put_bits(&s->pb,3,6); /* Custom Source Format */
else else
put_bits(&s->pb, 3, format); put_bits(&s->pb, 3, format);
put_bits(&s->pb,1,0); /* Custom PCF: off */ put_bits(&s->pb,1, s->custom_pcf);
put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
put_bits(&s->pb,1,0); /* SAC: off */ put_bits(&s->pb,1,0); /* SAC: off */
put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
...@@ -275,6 +298,13 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number) ...@@ -275,6 +298,13 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
} }
} }
if(s->custom_pcf){
if(ufep){
put_bits(&s->pb, 1, best_clock_code);
put_bits(&s->pb, 7, best_divisor);
}
put_bits(&s->pb, 2, (temp_ref>>8)&3);
}
/* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
if (s->umvplus) if (s->umvplus)
...@@ -4961,9 +4991,7 @@ int h263_decode_picture_header(MpegEncContext *s) ...@@ -4961,9 +4991,7 @@ int h263_decode_picture_header(MpegEncContext *s)
/* OPPTYPE */ /* OPPTYPE */
format = get_bits(&s->gb, 3); format = get_bits(&s->gb, 3);
dprintf("ufep=1, format: %d\n", format); dprintf("ufep=1, format: %d\n", format);
if (get_bits1(&s->gb) != 0) { s->custom_pcf= get_bits1(&s->gb);
av_log(s->avctx, AV_LOG_ERROR, "Custom PCF not supported\n");
}
s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
if (get_bits1(&s->gb) != 0) { if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
...@@ -5040,10 +5068,33 @@ int h263_decode_picture_header(MpegEncContext *s) ...@@ -5040,10 +5068,33 @@ int h263_decode_picture_header(MpegEncContext *s)
} }
if ((width == 0) || (height == 0)) if ((width == 0) || (height == 0))
return -1; return -1;
s->avctx->frame_rate = 30000;
s->avctx->frame_rate_base= 1001;
s->width = width; s->width = width;
s->height = height; s->height = height;
if(s->custom_pcf){
int gcd;
s->avctx->frame_rate= 1800000;
s->avctx->frame_rate_base= 1000 + get_bits1(&s->gb);
s->avctx->frame_rate_base*= get_bits(&s->gb, 7);
if(s->avctx->frame_rate_base == 0){
av_log(s, AV_LOG_ERROR, "zero framerate\n");
return -1;
}
gcd= ff_gcd(s->avctx->frame_rate, s->avctx->frame_rate_base);
s->avctx->frame_rate /= gcd;
s->avctx->frame_rate_base /= gcd;
// av_log(s->avctx, AV_LOG_DEBUG, "%d/%d\n", s->avctx->frame_rate, s->avctx->frame_rate_base);
}else{
s->avctx->frame_rate = 30000;
s->avctx->frame_rate_base= 1001;
}
}
if(s->custom_pcf){
skip_bits(&s->gb, 2); //extended Temporal reference
}
if (ufep) {
if (s->umvplus) { if (s->umvplus) {
if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
skip_bits1(&s->gb); skip_bits1(&s->gb);
...@@ -5090,7 +5141,7 @@ int h263_decode_picture_header(MpegEncContext *s) ...@@ -5090,7 +5141,7 @@ int h263_decode_picture_header(MpegEncContext *s)
} }
if(s->avctx->debug&FF_DEBUG_PICT_INFO){ if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s\n", av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
s->qscale, av_get_pict_type_char(s->pict_type), s->qscale, av_get_pict_type_char(s->pict_type),
s->gb.size_in_bits, 1-s->no_rounding, s->gb.size_in_bits, 1-s->no_rounding,
s->obmc ? " AP" : "", s->obmc ? " AP" : "",
...@@ -5101,7 +5152,8 @@ int h263_decode_picture_header(MpegEncContext *s) ...@@ -5101,7 +5152,8 @@ int h263_decode_picture_header(MpegEncContext *s)
s->alt_inter_vlc ? " AIV" : "", s->alt_inter_vlc ? " AIV" : "",
s->modified_quant ? " MQ" : "", s->modified_quant ? " MQ" : "",
s->loop_filter ? " LOOP" : "", s->loop_filter ? " LOOP" : "",
s->h263_slice_structured ? " SS" : "" s->h263_slice_structured ? " SS" : "",
s->avctx->frame_rate, s->avctx->frame_rate_base
); );
} }
#if 1 #if 1
......
...@@ -537,6 +537,7 @@ typedef struct MpegEncContext { ...@@ -537,6 +537,7 @@ typedef struct MpegEncContext {
int alt_inter_vlc; ///< alternative inter vlc int alt_inter_vlc; ///< alternative inter vlc
int modified_quant; int modified_quant;
int loop_filter; int loop_filter;
int custom_pcf;
/* mpeg4 specific */ /* mpeg4 specific */
int time_increment_resolution; int time_increment_resolution;
......
...@@ -26,7 +26,7 @@ stddev: 8.10 PSNR:29.94 bytes:7602176 ...@@ -26,7 +26,7 @@ stddev: 8.10 PSNR:29.94 bytes:7602176
48bc3eb55962ebb5a78359727d2bf4d8 *./data/a-h263.avi 48bc3eb55962ebb5a78359727d2bf4d8 *./data/a-h263.avi
545df74e0aa443499600faedd10a7065 *./data/out.yuv 545df74e0aa443499600faedd10a7065 *./data/out.yuv
stddev: 8.18 PSNR:29.86 bytes:7602176 stddev: 8.18 PSNR:29.86 bytes:7602176
a35a0d81d47e4e0c96a18ec67306db32 *./data/a-h263p.avi a1b02aeff25b40cca5d22fcf26dcc36d *./data/a-h263p.avi
0eb167c9dfcbeeecbf3debed8af8f811 *./data/out.yuv 0eb167c9dfcbeeecbf3debed8af8f811 *./data/out.yuv
stddev: 2.08 PSNR:41.74 bytes:7602176 stddev: 2.08 PSNR:41.74 bytes:7602176
3f7cb6411a099cdeda089fa9f720f17a *./data/a-odivx.mp4 3f7cb6411a099cdeda089fa9f720f17a *./data/a-odivx.mp4
......
...@@ -26,7 +26,7 @@ stddev: 5.29 PSNR:33.65 bytes:7602176 ...@@ -26,7 +26,7 @@ stddev: 5.29 PSNR:33.65 bytes:7602176
bc321858c3b669ac2c2f47eca275c7d5 *./data/a-h263.avi bc321858c3b669ac2c2f47eca275c7d5 *./data/a-h263.avi
8bcc9f78373ec424e864b40734e124ba *./data/out.yuv 8bcc9f78373ec424e864b40734e124ba *./data/out.yuv
stddev: 5.41 PSNR:33.45 bytes:7602176 stddev: 5.41 PSNR:33.45 bytes:7602176
d669d8ac80c4f25e2008ce31ea386465 *./data/a-h263p.avi a5384185eca920b9f00d3716c38d118d *./data/a-h263p.avi
7d39d1f272205a6a231d0e0baf32ff9d *./data/out.yuv 7d39d1f272205a6a231d0e0baf32ff9d *./data/out.yuv
stddev: 1.91 PSNR:42.49 bytes:7602176 stddev: 1.91 PSNR:42.49 bytes:7602176
cc1373233f8d1334091b8d3594f240e0 *./data/a-odivx.mp4 cc1373233f8d1334091b8d3594f240e0 *./data/a-odivx.mp4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment