comparison mpeg12.c @ 1548:dd544554ed42 libavcodec

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 5d06823e2ee9
children fca47124001d
comparison
equal deleted inserted replaced
1547:0183874861fd 1548:dd544554ed42
188 unsigned int vbv_buffer_size; 188 unsigned int vbv_buffer_size;
189 unsigned int fps, v; 189 unsigned int fps, v;
190 int n, i; 190 int n, i;
191 uint64_t time_code; 191 uint64_t time_code;
192 float best_aspect_error= 1E10; 192 float best_aspect_error= 1E10;
193 float aspect_ratio= s->avctx->aspect_ratio; 193 float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio);
194 int constraint_parameter_flag; 194 int constraint_parameter_flag;
195 195
196 if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA) 196 if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
197 197
198 if (s->current_picture.key_frame) { 198 if (s->current_picture.key_frame) {
199 /* mpeg1 header repeated every gop */ 199 /* mpeg1 header repeated every gop */
200 put_header(s, SEQ_START_CODE); 200 put_header(s, SEQ_START_CODE);
201 201
217 217
218 put_bits(&s->pb, 12, s->width); 218 put_bits(&s->pb, 12, s->width);
219 put_bits(&s->pb, 12, s->height); 219 put_bits(&s->pb, 12, s->height);
220 220
221 for(i=1; i<15; i++){ 221 for(i=1; i<15; i++){
222 float error= mpeg1_aspect[i] - s->width/(s->height*aspect_ratio); 222 float error= mpeg1_aspect[i] - aspect_ratio;
223 error= ABS(error); 223 error= ABS(error);
224 224
225 if(error < best_aspect_error){ 225 if(error < best_aspect_error){
226 best_aspect_error= error; 226 best_aspect_error= error;
227 s->aspect_ratio_info= i; 227 s->aspect_ratio_info= i;
1740 { 1740 {
1741 int horiz_size_ext, vert_size_ext; 1741 int horiz_size_ext, vert_size_ext;
1742 int bit_rate_ext, vbv_buf_ext; 1742 int bit_rate_ext, vbv_buf_ext;
1743 int frame_rate_ext_n, frame_rate_ext_d; 1743 int frame_rate_ext_n, frame_rate_ext_d;
1744 int level, profile; 1744 int level, profile;
1745 float aspect;
1746 1745
1747 skip_bits(&s->gb, 1); /* profil and level esc*/ 1746 skip_bits(&s->gb, 1); /* profil and level esc*/
1748 profile= get_bits(&s->gb, 3); 1747 profile= get_bits(&s->gb, 3);
1749 level= get_bits(&s->gb, 4); 1748 level= get_bits(&s->gb, 4);
1750 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ 1749 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
1772 1771
1773 dprintf("sequence extension\n"); 1772 dprintf("sequence extension\n");
1774 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; 1773 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
1775 s->avctx->sub_id = 2; /* indicates mpeg2 found */ 1774 s->avctx->sub_id = 2; /* indicates mpeg2 found */
1776 1775
1777 aspect= mpeg2_aspect[s->aspect_ratio_info]; 1776 if(s->aspect_ratio_info <= 1)
1778 if(aspect>0.0) s->avctx->aspect_ratio= s->width/(aspect*s->height); 1777 s->avctx->sample_aspect_ratio= mpeg2_aspect[s->aspect_ratio_info];
1779 else if(aspect<0.0) s->avctx->aspect_ratio= -1.0/aspect; 1778 else{
1779 s->avctx->sample_aspect_ratio=
1780 av_div_q(
1781 mpeg2_aspect[s->aspect_ratio_info],
1782 (AVRational){s->width, s->height}
1783 );
1784 }
1780 1785
1781 if(s->avctx->debug & FF_DEBUG_PICT_INFO) 1786 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
1782 printf("profile: %d, level: %d \n", profile, level); 1787 printf("profile: %d, level: %d \n", profile, level);
1783 } 1788 }
1784 1789
1800 skip_bits(&s->gb, 1); //marker 1805 skip_bits(&s->gb, 1); //marker
1801 1806
1802 s1->pan_scan.width= 16*w; 1807 s1->pan_scan.width= 16*w;
1803 s1->pan_scan.height=16*h; 1808 s1->pan_scan.height=16*h;
1804 1809
1805 if(mpeg2_aspect[s->aspect_ratio_info] < 0.0) 1810 if(s->aspect_ratio_info > 1)
1806 s->avctx->aspect_ratio*= (s->width * h)/(float)(s->height * w); 1811 s->avctx->sample_aspect_ratio=
1812 av_div_q(
1813 mpeg2_aspect[s->aspect_ratio_info],
1814 (AVRational){w, h}
1815 );
1807 1816
1808 if(s->avctx->debug & FF_DEBUG_PICT_INFO) 1817 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
1809 printf("sde w:%d, h:%d\n", w, h); 1818 printf("sde w:%d, h:%d\n", w, h);
1810 } 1819 }
1811 1820
2241 width = get_bits(&s->gb, 12); 2250 width = get_bits(&s->gb, 12);
2242 height = get_bits(&s->gb, 12); 2251 height = get_bits(&s->gb, 12);
2243 s->aspect_ratio_info= get_bits(&s->gb, 4); 2252 s->aspect_ratio_info= get_bits(&s->gb, 4);
2244 if(s->codec_id == CODEC_ID_MPEG1VIDEO){ 2253 if(s->codec_id == CODEC_ID_MPEG1VIDEO){
2245 aspect= mpeg1_aspect[s->aspect_ratio_info]; 2254 aspect= mpeg1_aspect[s->aspect_ratio_info];
2246 if(aspect!=0.0) avctx->aspect_ratio= width/(aspect*height); 2255 if(aspect!=0.0) avctx->sample_aspect_ratio= av_d2q(aspect, 30000);
2247 } 2256 }
2248 2257
2249 s->frame_rate_index = get_bits(&s->gb, 4); 2258 s->frame_rate_index = get_bits(&s->gb, 4);
2250 if (s->frame_rate_index == 0) 2259 if (s->frame_rate_index == 0)
2251 return -1; 2260 return -1;