put sequence header if needed */
| 189 | |
| 190 | /* put sequence header if needed */ |
| 191 | static void mpeg1_encode_sequence_header(MpegEncContext *s) |
| 192 | { |
| 193 | unsigned int vbv_buffer_size; |
| 194 | unsigned int fps, v; |
| 195 | int i; |
| 196 | uint64_t time_code; |
| 197 | float best_aspect_error= 1E10; |
| 198 | float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); |
| 199 | int constraint_parameter_flag; |
| 200 | |
| 201 | if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) |
| 202 | |
| 203 | if (s->current_picture.key_frame) { |
| 204 | AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; |
| 205 | |
| 206 | /* mpeg1 header repeated every gop */ |
| 207 | put_header(s, SEQ_START_CODE); |
| 208 | |
| 209 | put_sbits(&s->pb, 12, s->width ); |
| 210 | put_sbits(&s->pb, 12, s->height); |
| 211 | |
| 212 | for(i=1; i<15; i++){ |
| 213 | float error= aspect_ratio; |
| 214 | if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) |
| 215 | error-= 1.0/ff_mpeg1_aspect[i]; |
| 216 | else |
| 217 | error-= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width; |
| 218 | |
| 219 | error= FFABS(error); |
| 220 | |
| 221 | if(error < best_aspect_error){ |
| 222 | best_aspect_error= error; |
| 223 | s->aspect_ratio_info= i; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | put_bits(&s->pb, 4, s->aspect_ratio_info); |
| 228 | put_bits(&s->pb, 4, s->frame_rate_index); |
| 229 | |
| 230 | if(s->avctx->rc_max_rate){ |
| 231 | v = (s->avctx->rc_max_rate + 399) / 400; |
| 232 | if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) |
| 233 | v = 0x3ffff; |
| 234 | }else{ |
| 235 | v= 0x3FFFF; |
| 236 | } |
| 237 | |
| 238 | if(s->avctx->rc_buffer_size) |
| 239 | vbv_buffer_size = s->avctx->rc_buffer_size; |
| 240 | else |
| 241 | /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ |
| 242 | vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; |
| 243 | vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; |
| 244 | |
| 245 | put_sbits(&s->pb, 18, v); |
| 246 | put_bits(&s->pb, 1, 1); /* marker */ |
| 247 | put_sbits(&s->pb, 10, vbv_buffer_size); |
| 248 |
no test coverage detected