summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2002-12-06 16:19:25 +0000
committerMichael Niedermayer <michaelni@gmx.at>2002-12-06 16:19:25 +0000
commit426b80615b530d878a4977db9e132fdd22744368 (patch)
tree977e5613262abd920c832b4efb2ca8da9e6130d7
parent945f15b740a09477f93511a21790863efd24abd6 (diff)
aspect ratio encoding for mpeg1
Originally committed as revision 1319 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/mpeg12.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 51ebc950dc..5058d1d5f5 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -131,8 +131,12 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
{
unsigned int vbv_buffer_size;
unsigned int fps, v;
- int n;
+ int n, i;
UINT64 time_code;
+ float best_aspect_error= 1E10;
+ float aspect_ratio= s->avctx->aspect_ratio;
+
+ if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA)
if (s->current_picture.key_frame) {
/* mpeg1 header repeated every gop */
@@ -154,7 +158,18 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 12, s->width);
put_bits(&s->pb, 12, s->height);
- put_bits(&s->pb, 4, 1); /* 1/1 aspect ratio */
+
+ for(i=1; i<15; i++){
+ float error= mpeg1_aspect[i] - s->width/(s->height*aspect_ratio);
+ error= ABS(error);
+
+ if(error < best_aspect_error){
+ best_aspect_error= error;
+ s->aspect_ratio_info= i;
+ }
+ }
+
+ put_bits(&s->pb, 4, s->aspect_ratio_info);
put_bits(&s->pb, 4, s->frame_rate_index);
v = s->bit_rate / 400;
if (v > 0x3ffff)