summaryrefslogtreecommitdiff
path: root/libavcodec/mpeg12.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2003-10-20 20:23:46 +0000
committerMichael Niedermayer <michaelni@gmx.at>2003-10-20 20:23:46 +0000
commit5ff85f1d8b5721a9e7f0ca6e03f61f5d3a4c3664 (patch)
tree710ea001d862c7bdb29dd0e707f9dd9eee3f2c72 /libavcodec/mpeg12.c
parent9dad924e22dc0e1a09013b588b43051b5baf428d (diff)
AVRational
sample_aspect_ratio aspect ratio in JPEG JFIF is SAR not DAR ! removed nonsense SAR guessing code various related cleanups bugs? Originally committed as revision 2403 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/mpeg12.c')
-rw-r--r--libavcodec/mpeg12.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 015033bf36..f054e00d0d 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -190,10 +190,10 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
int n, i;
uint64_t time_code;
float best_aspect_error= 1E10;
- float aspect_ratio= s->avctx->aspect_ratio;
+ float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio);
int constraint_parameter_flag;
- if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA)
+ if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
if (s->current_picture.key_frame) {
/* mpeg1 header repeated every gop */
@@ -219,7 +219,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 12, s->height);
for(i=1; i<15; i++){
- float error= mpeg1_aspect[i] - s->width/(s->height*aspect_ratio);
+ float error= mpeg1_aspect[i] - aspect_ratio;
error= ABS(error);
if(error < best_aspect_error){
@@ -1742,7 +1742,6 @@ static void mpeg_decode_sequence_extension(MpegEncContext *s)
int bit_rate_ext, vbv_buf_ext;
int frame_rate_ext_n, frame_rate_ext_d;
int level, profile;
- float aspect;
skip_bits(&s->gb, 1); /* profil and level esc*/
profile= get_bits(&s->gb, 3);
@@ -1774,9 +1773,15 @@ static void mpeg_decode_sequence_extension(MpegEncContext *s)
s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
s->avctx->sub_id = 2; /* indicates mpeg2 found */
- aspect= mpeg2_aspect[s->aspect_ratio_info];
- if(aspect>0.0) s->avctx->aspect_ratio= s->width/(aspect*s->height);
- else if(aspect<0.0) s->avctx->aspect_ratio= -1.0/aspect;
+ if(s->aspect_ratio_info <= 1)
+ s->avctx->sample_aspect_ratio= mpeg2_aspect[s->aspect_ratio_info];
+ else{
+ s->avctx->sample_aspect_ratio=
+ av_div_q(
+ mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational){s->width, s->height}
+ );
+ }
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
printf("profile: %d, level: %d \n", profile, level);
@@ -1802,8 +1807,12 @@ static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
s1->pan_scan.width= 16*w;
s1->pan_scan.height=16*h;
- if(mpeg2_aspect[s->aspect_ratio_info] < 0.0)
- s->avctx->aspect_ratio*= (s->width * h)/(float)(s->height * w);
+ if(s->aspect_ratio_info > 1)
+ s->avctx->sample_aspect_ratio=
+ av_div_q(
+ mpeg2_aspect[s->aspect_ratio_info],
+ (AVRational){w, h}
+ );
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
printf("sde w:%d, h:%d\n", w, h);
@@ -2243,7 +2252,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
s->aspect_ratio_info= get_bits(&s->gb, 4);
if(s->codec_id == CODEC_ID_MPEG1VIDEO){
aspect= mpeg1_aspect[s->aspect_ratio_info];
- if(aspect!=0.0) avctx->aspect_ratio= width/(aspect*height);
+ if(aspect!=0.0) avctx->sample_aspect_ratio= av_d2q(aspect, 30000);
}
s->frame_rate_index = get_bits(&s->gb, 4);