00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include "global.h"
00034
00035
00036
00037
00038 void putseq()
00039 {
00040
00041 int i, j, k, f, f0, n, np, nb;
00042 int ipflag;
00043 int sxf = 0, sxb = 0, syf = 0, syb = 0;
00044 motion_comp_s mc_data;
00045
00046 for(k = 0; k < processors; k++)
00047 ratectl_init_seq(ratectl[k]);
00048
00049
00050 if(end_frame == 0x7fffffff)
00051 frames_scaled = end_frame;
00052 else
00053 frames_scaled = (end_frame - start_frame) *
00054 frame_rate /
00055 input_frame_rate;
00056
00057
00058
00059
00060
00061
00062
00063 if(!seq_header_every_gop) putseqhdr();
00064
00065
00066
00067
00068
00069
00070
00071
00072 for(i = 0;
00073 i < frames_scaled;
00074 i++)
00075 {
00076
00077 if(i != 0 && verbose)
00078 {
00079 if(end_frame == 0x7fffffff)
00080 fprintf(stderr,"Encoding frame %d. bitrate achieved: %d \r",
00081 frame0 + i + 1,
00082 (int)((float)ftell(outfile) / ((float)i / frame_rate)) * 8);
00083 else
00084 fprintf(stderr,"%5d %13d%% %17d %23d \r",
00085 frame0 + i + 1,
00086 (int)((float)i / frames_scaled * 100),
00087 (int)((float)ftell(outfile) / ((float)i / frame_rate)) * 8,
00088 (int)((float)ftell(outfile) / ((float)i / frames_scaled)));
00089 }
00090 fflush(stderr);
00091
00092
00093
00094
00095
00096
00097 f0 = N*((i+(M-1))/N) - (M-1);
00098
00099 if (f0<0)
00100 f0=0;
00101
00102 if(i == 0 || (i - 1) % M == 0)
00103 {
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 for (j=0; j<3; j++)
00116 {
00117 unsigned char *tmp;
00118 oldorgframe[j] = neworgframe[j];
00119 tmp = oldrefframe[j];
00120 oldrefframe[j] = newrefframe[j];
00121 newrefframe[j] = tmp;
00122 }
00123
00124
00125
00126
00127
00128
00129 cur_picture.curorg = neworgframe;
00130 cur_picture.curref = newrefframe;
00131
00132
00133
00134
00135 f = (i==0) ? 0 : i+M-1;
00136 if (f>=end_frame)
00137 f = end_frame - 1;
00138
00139 if (i==f0)
00140 {
00141
00142 cur_picture.pict_type = I_TYPE;
00143
00144 cur_picture.forw_hor_f_code =
00145 cur_picture.forw_vert_f_code = 15;
00146 cur_picture.back_hor_f_code =
00147 cur_picture.back_vert_f_code = 15;
00148
00149
00150
00151
00152
00153 n = (i==0) ? N-(M-1) : N;
00154
00155
00156 if (n > end_frame-f0)
00157 n = end_frame-f0;
00158
00159
00160 if (i==0)
00161 np = (n + 2*(M-1))/M - 1;
00162 else
00163 np = (n + (M-1))/M - 1;
00164
00165
00166 nb = n - np - 1;
00167
00168 for(k = 0; k < processors; k++)
00169 ratectl_init_GOP(ratectl[k], np, nb);
00170
00171
00172
00173
00174
00175
00176 if(seq_header_every_gop) putseqhdr();
00177 putgophdr(f0, i == 0);
00178 }
00179 else
00180 {
00181
00182 cur_picture.pict_type = P_TYPE;
00183 cur_picture.forw_hor_f_code = motion_data[0].forw_hor_f_code;
00184 cur_picture.forw_vert_f_code = motion_data[0].forw_vert_f_code;
00185 cur_picture.back_hor_f_code =
00186 cur_picture.back_vert_f_code = 15;
00187 sxf = motion_data[0].sxf;
00188 syf = motion_data[0].syf;
00189 }
00190 }
00191 else
00192 {
00193
00194
00195
00196
00197 cur_picture.curorg = auxorgframe;
00198 cur_picture.curref = auxframe;
00199
00200
00201 f = i - 1;
00202 cur_picture.pict_type = B_TYPE;
00203 n = (i-2)%M + 1;
00204 cur_picture.forw_hor_f_code = motion_data[n].forw_hor_f_code;
00205 cur_picture.forw_vert_f_code = motion_data[n].forw_vert_f_code;
00206 cur_picture.back_hor_f_code = motion_data[n].back_hor_f_code;
00207 cur_picture.back_vert_f_code = motion_data[n].back_vert_f_code;
00208 sxf = motion_data[n].sxf;
00209 syf = motion_data[n].syf;
00210 sxb = motion_data[n].sxb;
00211 syb = motion_data[n].syb;
00212 }
00213
00214 cur_picture.temp_ref = f - f0;
00215 cur_picture.frame_pred_dct = frame_pred_dct_tab[cur_picture.pict_type - 1];
00216 cur_picture.q_scale_type = qscale_tab[cur_picture.pict_type - 1];
00217 cur_picture.intravlc = intravlc_tab[cur_picture.pict_type - 1];
00218 cur_picture.altscan = altscan_tab[cur_picture.pict_type - 1];
00219
00220
00221 readframe(f + frame0, cur_picture.curorg);
00222 if(!frames_scaled) break;
00223
00224
00225 mc_data.oldorg = oldorgframe;
00226 mc_data.neworg = neworgframe;
00227 mc_data.oldref = oldrefframe;
00228 mc_data.newref = newrefframe;
00229 mc_data.cur = cur_picture.curorg;
00230 mc_data.curref = cur_picture.curref;
00231 mc_data.sxf = sxf;
00232 mc_data.syf = syf;
00233 mc_data.sxb = sxb;
00234 mc_data.syb = syb;
00235
00236 if (fieldpic)
00237 {
00238
00239 cur_picture.topfirst = opt_topfirst;
00240 if (!quiet)
00241 {
00242 fprintf(stderr,"\nfirst field (%s) ",
00243 cur_picture.topfirst ? "top" : "bot");
00244 fflush(stderr);
00245 }
00246
00247 cur_picture.pict_struct = cur_picture.topfirst ? TOP_FIELD : BOTTOM_FIELD;
00248
00249 fast_motion_data(cur_picture.curorg[0], cur_picture.pict_struct);
00250 motion_estimation(&cur_picture, &mc_data,0,0);
00251
00252 predict(&cur_picture,oldrefframe,newrefframe,predframe,0);
00253 dct_type_estimation(&cur_picture,predframe[0],cur_picture.curorg[0]);
00254 transform(&cur_picture,predframe,cur_picture.curorg);
00255
00256 putpict(&cur_picture);
00257 #ifndef OUTPUT_STAT
00258 if( cur_picture.pict_type!=B_TYPE)
00259 {
00260 #endif
00261 iquantize( &cur_picture );
00262 itransform(&cur_picture,predframe,cur_picture.curref);
00263
00264
00265
00266
00267 #ifndef OUTPUT_STAT
00268 }
00269 #endif
00270 if (!quiet)
00271 {
00272 fprintf(stderr,"second field (%s) ",cur_picture.topfirst ? "bot" : "top");
00273 fflush(stderr);
00274 }
00275
00276 cur_picture.pict_struct = cur_picture.topfirst ? BOTTOM_FIELD : TOP_FIELD;
00277
00278 ipflag = (cur_picture.pict_type==I_TYPE);
00279 if (ipflag)
00280 {
00281
00282 cur_picture.pict_type = P_TYPE;
00283 cur_picture.forw_hor_f_code = motion_data[0].forw_hor_f_code;
00284 cur_picture.forw_vert_f_code = motion_data[0].forw_vert_f_code;
00285 cur_picture.back_hor_f_code =
00286 cur_picture.back_vert_f_code = 15;
00287 sxf = motion_data[0].sxf;
00288 syf = motion_data[0].syf;
00289 }
00290
00291 motion_estimation(&cur_picture, &mc_data ,1,ipflag);
00292
00293 predict(&cur_picture,oldrefframe,newrefframe,predframe,1);
00294 dct_type_estimation(&cur_picture,predframe[0],cur_picture.curorg[0]);
00295 transform(&cur_picture,predframe,cur_picture.curorg);
00296
00297 putpict(&cur_picture);
00298
00299 #ifndef OUTPUT_STAT
00300 if( cur_picture.pict_type!=B_TYPE)
00301 {
00302 #endif
00303 iquantize( &cur_picture );
00304 itransform(&cur_picture,predframe,cur_picture.curref);
00305
00306
00307
00308
00309 #ifndef OUTPUT_STAT
00310 }
00311 #endif
00312
00313 }
00314 else
00315 {
00316
00317 cur_picture.pict_struct = FRAME_PICTURE;
00318 fast_motion_data(cur_picture.curorg[0], cur_picture.pict_struct);
00319
00320
00321
00322
00323
00324
00325
00326
00327 motion_estimation(&cur_picture,&mc_data,0,0);
00328
00329
00330 predict(&cur_picture, oldrefframe,newrefframe,predframe,0);
00331
00332 dct_type_estimation(&cur_picture,predframe[0],cur_picture.curorg[0]);
00333
00334
00335 transform(&cur_picture,predframe,cur_picture.curorg);
00336
00337
00338
00339 putpict(&cur_picture);
00340
00341
00342 #ifndef OUTPUT_STAT
00343 if( cur_picture.pict_type!=B_TYPE)
00344 {
00345 #endif
00346 iquantize( &cur_picture );
00347
00348 itransform(&cur_picture,predframe,cur_picture.curref);
00349
00350
00351
00352
00353
00354 #ifndef OUTPUT_STAT
00355 }
00356 #endif
00357 }
00358 writeframe(f + frame0, cur_picture.curref);
00359
00360
00361 }
00362 putseqend();
00363 if(verbose) fprintf(stderr, "\nDone. Be sure to visit heroinewarrior.com for updates.\n");
00364 }