changeset 288:981b0b3c95dd libavformat

AVRational sample_aspect_ratio aspect ratio in JPEG JFIF is SAR not DAR ! removed nonsense SAR guessing code various related cleanups bugs?
author michael
date Mon, 20 Oct 2003 20:23:46 +0000
parents 0b3ec5cba845
children 4baa098c12c3
files dv.c yuv4mpeg.c
diffstat 2 files changed, 9 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/dv.c	Mon Oct 20 10:33:13 2003 +0000
+++ b/dv.c	Mon Oct 20 20:23:46 2003 +0000
@@ -556,10 +556,12 @@
         avctx->height = sys->height;
         avctx->pix_fmt = sys->pix_fmt;
         vsc_pack = dv_extract_pack(frame, dv_video_control);
+        /* MN: someone please fill in the correct SAR for dv, i dont have the standard doc so i cant, allthough its very likely the same as MPEG4 (12:11 10:11 16:11 40:33) */
         if (vsc_pack && (vsc_pack[2] & 0x07) == (apt?0x02:0x07))
-            avctx->aspect_ratio = 16.0 / 9.0;
+            avctx->sample_aspect_ratio = (AVRational){16,9};
         else
-            avctx->aspect_ratio = 4.0 / 3.0;
+            avctx->sample_aspect_ratio = (AVRational){4,3};
+        avctx->sample_aspect_ratio = av_div_q(avctx->sample_aspect_ratio, (AVRational){sys->width,sys->height});
 	size = sys->frame_size;
     }
     return size;
@@ -660,7 +662,7 @@
     c->has_audio = c->has_video = 0;
     c->start_time = time(NULL);
     c->aspect = 0; /* 4:3 is the default */
-    if ((int)(vst->codec.aspect_ratio * 10) == 17) /* 16:9 */ 
+    if ((int)(av_q2d(vst->codec.sample_aspect_ratio) * vst->codec.width / vst->codec.height * 10) == 17) /* 16:9 */ 
         c->aspect = 0x07;
 
     if (fifo_init(&c->audio_data, 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0)
--- a/yuv4mpeg.c	Mon Oct 20 10:33:13 2003 +0000
+++ b/yuv4mpeg.c	Mon Oct 20 20:23:46 2003 +0000
@@ -24,18 +24,11 @@
 
 #ifdef CONFIG_ENCODERS
 
-
-static struct { int n; int d;} SAR[] = {{10, 11}, /*  4:3 NTSC */
-	                                {59, 54}, /*  4:3 PAL  */
-	                                {40, 33}, /* 16:9 NTSC */
-				       {118, 81}, /* 16:9 PAL  */
-					{ 1,  1}};/* should always be the last */
-
 static int yuv4_generate_header(AVFormatContext *s, char* buf)
 {
     AVStream *st;
     int width, height;
-    int raten, rated, aspectn, aspectd, n, i;
+    int raten, rated, aspectn, aspectd, n;
     char inter;
 
     st = s->streams[0];
@@ -44,13 +37,8 @@
 
     av_reduce(&raten, &rated, st->codec.frame_rate, st->codec.frame_rate_base, (1UL<<31)-1);
     
-    for (i=0; i<sizeof(SAR)/sizeof(SAR[0])-1; i++) {
-       if (ABS(st->codec.aspect_ratio -
-	       (float)SAR[i].n/SAR[i].d * (float)width/height) < 0.05)
-		  break;
-    }
-    aspectn = SAR[i].n;
-    aspectd = SAR[i].d;
+    aspectn = st->codec.sample_aspect_ratio.num;
+    aspectd = st->codec.sample_aspect_ratio.den;
     
     inter = 'p'; /* progressive is the default */
     if (st->codec.coded_frame && st->codec.coded_frame->interlaced_frame) {
@@ -200,6 +188,7 @@
     st->codec.pix_fmt = PIX_FMT_YUV420P;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_RAWVIDEO;
+    st->codec.sample_aspect_ratio= (AVRational){aspectn, aspectd};
 
     return 0;
 }