]> git.sesse.net Git - x264/blob - x264.c
When evaluating predictors to start fullpel motion search, use subpel positions inste...
[x264] / x264.c
1 /*****************************************************************************
2  * x264: h264 encoder/decoder testing program.
3  *****************************************************************************
4  * Copyright (C) 2003 Laurent Aimar
5  * $Id: x264.c,v 1.1 2004/06/03 19:24:12 fenrir Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #define _LARGEFILE_SOURCE
25 #define _FILE_OFFSET_BITS 64
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <math.h>
31
32 #include <signal.h>
33 #define _GNU_SOURCE
34 #include <getopt.h>
35
36 #ifdef _MSC_VER
37 #include <io.h>     /* _setmode() */
38 #include <fcntl.h>  /* _O_BINARY */
39 #endif
40
41 #ifndef _MSC_VER
42 #include "config.h"
43 #endif
44
45 #include "common/common.h"
46 #include "x264.h"
47 #include "muxers.h"
48
49 #define DATA_MAX 3000000
50 uint8_t data[DATA_MAX];
51
52 /* Ctrl-C handler */
53 static int     b_ctrl_c = 0;
54 static int     b_exit_on_ctrl_c = 0;
55 static void    SigIntHandler( int a )
56 {
57     if( b_exit_on_ctrl_c )
58         exit(0);
59     b_ctrl_c = 1;
60 }
61
62 typedef struct {
63     int b_decompress;
64     int b_progress;
65     int i_seek;
66     hnd_t hin;
67     hnd_t hout;
68 } cli_opt_t;
69
70 /* input file operation function pointers */
71 int (*p_open_infile)( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param );
72 int (*p_get_frame_total)( hnd_t handle );
73 int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame );
74 int (*p_close_infile)( hnd_t handle );
75
76 /* output file operation function pointers */
77 static int (*p_open_outfile)( char *psz_filename, hnd_t *p_handle );
78 static int (*p_set_outfile_param)( hnd_t handle, x264_param_t *p_param );
79 static int (*p_write_nalu)( hnd_t handle, uint8_t *p_nal, int i_size );
80 static int (*p_set_eop)( hnd_t handle, x264_picture_t *p_picture );
81 static int (*p_close_outfile)( hnd_t handle );
82
83 static void Help( x264_param_t *defaults );
84 static int  Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt );
85 static int  Encode( x264_param_t *param, cli_opt_t *opt );
86
87
88 /****************************************************************************
89  * main:
90  ****************************************************************************/
91 int main( int argc, char **argv )
92 {
93     x264_param_t param;
94     cli_opt_t opt;
95
96 #ifdef _MSC_VER
97     _setmode(_fileno(stdin), _O_BINARY);
98     _setmode(_fileno(stdout), _O_BINARY);
99 #endif
100
101     x264_param_default( &param );
102
103     /* Parse command line */
104     if( Parse( argc, argv, &param, &opt ) < 0 )
105         return -1;
106
107     /* Control-C handler */
108     signal( SIGINT, SigIntHandler );
109
110     return Encode( &param, &opt );
111 }
112
113 static const char * const overscan_str[] = { "undef", "show", "crop", NULL };
114 static const char * const vidformat_str[] = { "component", "pal", "ntsc", "secam", "mac", "undef", NULL };
115 static const char * const fullrange_str[] = { "off", "on", NULL };
116 static const char * const colorprim_str[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", NULL };
117 static const char * const transfer_str[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", "log316", NULL };
118 static const char * const colmatrix_str[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m", "YCgCo", NULL };
119
120 static char const *strtable_lookup( const char * const table[], int index )
121 {
122     int i = 0; while( table[i] ) i++;
123     return ( ( index >= 0 && index < i ) ? table[ index ] : "???" );
124 }
125
126 /*****************************************************************************
127  * Help:
128  *****************************************************************************/
129 static void Help( x264_param_t *defaults )
130 {
131     fprintf( stderr,
132              "x264 core:%d%s\n"
133              "Syntax: x264 [options] -o outfile infile [widthxheight]\n"
134              "\n"
135              "Infile can be raw YUV 4:2:0 (in which case resolution is required),\n"
136              "  or YUV4MPEG 4:2:0 (*.y4m),\n"
137              "  or AVI or Avisynth if compiled with AVIS support (%s).\n"
138              "Outfile type is selected by filename:\n"
139              " .264 -> Raw bytestream\n"
140              " .mkv -> Matroska\n"
141              " .mp4 -> MP4 if compiled with GPAC support (%s)\n"
142              "\n"
143              "Options:\n"
144              "\n"
145              "  -h, --help                  Print this help\n"
146              "\n"
147              "Frame-type options:\n"
148              "\n"
149              "  -I, --keyint <integer>      Maximum GOP size [%d]\n"
150              "  -i, --min-keyint <integer>  Minimum GOP size [%d]\n"
151              "      --scenecut <integer>    How aggressively to insert extra I-frames [%d]\n"
152              "  -b, --bframes <integer>     Number of B-frames between I and P [%d]\n"
153              "      --no-b-adapt            Disable adaptive B-frame decision\n"
154              "      --b-bias <integer>      Influences how often B-frames are used [%d]\n"
155              "      --b-pyramid             Keep some B-frames as references\n"
156              "\n"
157              "      --no-cabac              Disable CABAC\n"
158              "  -r, --ref <integer>         Number of reference frames [%d]\n"
159              "      --nf                    Disable loop filter\n"
160              "  -f, --filter <alpha:beta>   Loop filter AlphaC0 and Beta parameters [%d:%d]\n"
161              "\n"
162              "Ratecontrol:\n"
163              "\n"
164              "  -q, --qp <integer>          Set QP (0=lossless) [%d]\n"
165              "  -B, --bitrate <integer>     Set bitrate\n"
166              "      --crf <integer>         Quality-based VBR (nominal QP)\n"
167              "      --qpmin <integer>       Set min QP [%d]\n"
168              "      --qpmax <integer>       Set max QP [%d]\n"
169              "      --qpstep <integer>      Set max QP step [%d]\n"
170              "      --ratetol <float>       Allowed variance of average bitrate [%.1f]\n"
171              "      --vbv-maxrate <integer> Max local bitrate [%d]\n"
172              "      --vbv-bufsize <integer> Size of VBV buffer [%d]\n"
173              "      --vbv-init <float>      Initial VBV buffer occupancy [%.1f]\n"
174              "\n"
175              "      --ipratio <float>       QP factor between I and P [%.2f]\n"
176              "      --pbratio <float>       QP factor between P and B [%.2f]\n"
177              "      --chroma-qp-offset <integer>  QP difference between chroma and luma [%d]\n"
178              "\n"
179              "  -p, --pass <1|2|3>          Enable multipass ratecontrol:\n"
180              "                                  - 1: First pass, creates stats file\n"
181              "                                  - 2: Last pass, does not overwrite stats file\n"
182              "                                  - 3: Nth pass, overwrites stats file\n"
183              "      --stats <string>        Filename for 2 pass stats [\"%s\"]\n"
184              "      --rceq <string>         Ratecontrol equation [\"%s\"]\n"
185              "      --qcomp <float>         QP curve compression: 0.0 => CBR, 1.0 => CQP [%.2f]\n"
186              "      --cplxblur <float>      Reduce fluctuations in QP (before curve compression) [%.1f]\n"
187              "      --qblur <float>         Reduce fluctuations in QP (after curve compression) [%.1f]\n"
188              "\n"
189              "      --zones <zone0>/<zone1>/...\n"
190              "                              Tweak the bitrate of some regions of the video\n"
191              "                              Each zone is of the form\n"
192              "                                  <start frame>,<end frame>,<option>\n"
193              "                                  where <option> is either\n"
194              "                                      q=<integer> (force QP)\n"
195              "                                  or  b=<float> (bitrate multiplier)\n"
196              "\n"
197              "Analysis:\n"
198              "\n"
199              "  -A, --analyse <string>      Partitions to consider [\"p8x8,b8x8,i8x8,i4x4\"]\n"
200              "                                  - p8x8, p4x4, b8x8, i8x8, i4x4\n"
201              "                                  - none, all\n"
202              "                                  (p4x4 requires p8x8. i8x8 requires --8x8dct.)\n"
203              "      --direct <string>       Direct MV prediction mode [\"%s\"]\n"
204              "                                  - none, spatial, temporal, auto\n"
205              "  -w, --weightb               Weighted prediction for B-frames\n"
206              "      --me <string>           Integer pixel motion estimation method [\"%s\"]\n"
207              "                                  - dia: diamond search, radius 1 (fast)\n"
208              "                                  - hex: hexagonal search, radius 2\n"
209              "                                  - umh: uneven multi-hexagon search\n"
210              "                                  - esa: exhaustive search (slow)\n"
211              "      --merange <integer>     Maximum motion vector search range [%d]\n"
212              "  -m, --subme <integer>       Subpixel motion estimation and partition\n"
213              "                                  decision quality: 1=fast, 7=best. [%d]\n"
214              "      --b-rdo                 RD based mode decision for B-frames. Requires subme 6.\n"
215              "      --mixed-refs            Decide references on a per partition basis\n"
216              "      --no-chroma-me          Ignore chroma in motion estimation\n"
217              "      --bime                  Jointly optimize both MVs in B-frames\n"
218              "  -8, --8x8dct                Adaptive spatial transform size\n"
219              "  -t, --trellis <integer>     Trellis RD quantization. Requires CABAC. [%d]\n"
220              "                                  - 0: disabled\n"
221              "                                  - 1: enabled only on the final encode of a MB\n"
222              "                                  - 2: enabled on all mode decisions\n"
223              "      --no-fast-pskip         Disables early SKIP detection on P-frames\n"
224              "      --no-dct-decimate       Disables coefficient thresholding on P-frames\n"
225              "      --nr <integer>          Noise reduction [%d]\n"
226              "\n"
227              "      --cqm <string>          Preset quant matrices [\"flat\"]\n"
228              "                                  - jvt, flat\n"
229              "      --cqmfile <string>      Read quant matrices from a JM-compatible file\n"
230              "                                  Overrides any other --cqm* options.\n"
231              "      --cqm4 <list>           Set all 4x4 quant matrices\n"
232              "                                  Takes a comma-separated list of 16 integers.\n"
233              "      --cqm8 <list>           Set all 8x8 quant matrices\n"
234              "                                  Takes a comma-separated list of 64 integers.\n"
235              "      --cqm4i, --cqm4p, --cqm8i, --cqm8p\n"
236              "                              Set both luma and chroma quant matrices\n"
237              "      --cqm4iy, --cqm4ic, --cqm4py, --cqm4pc\n"
238              "                              Set individual quant matrices\n"
239              "\n"
240              "Video Usability Info (Annex E):\n"
241              "The VUI settings are not used by the encoder but are merely suggestions to\n"
242              "the playback equipment. See doc/vui.txt for details. Use at your own risk.\n"
243              "\n"
244              "      --sar width:height      Specify Sample Aspect Ratio\n"
245              "      --overscan <string>     Specify crop overscan setting [\"%s\"]\n"
246              "                                  - undef, show, crop\n"
247              "      --videoformat <string>  Specify video format [\"%s\"]\n"
248              "                                  - component, pal, ntsc, secam, mac, undef\n"
249              "      --fullrange <string>    Specify full range samples setting [\"%s\"]\n"
250              "                                  - off, on\n"
251              "      --colorprim <string>    Specify color primaries [\"%s\"]\n"
252              "                                  - undef, bt709, bt470m, bt470bg\n"
253              "                                    smpte170m, smpte240m, film\n"
254              "      --transfer <string>     Specify transfer characteristics [\"%s\"]\n"
255              "                                  - undef, bt709, bt470m, bt470bg, linear,\n"
256              "                                    log100, log316, smpte170m, smpte240m\n"
257              "      --colormatrix <string>  Specify color matrix setting [\"%s\"]\n"
258              "                                  - undef, bt709, fcc, bt470bg\n"
259              "                                    smpte170m, smpte240m, GBR, YCgCo\n"
260              "      --chromaloc <integer>   Specify chroma sample location (0 to 5) [%d]\n"
261              "\n"
262              "Input/Output:\n"
263              "\n"
264              "      --level <string>        Specify level (as defined by Annex A)\n"
265              "      --fps <float|rational>  Specify framerate\n"
266              "      --seek <integer>        First frame to encode\n"
267              "      --frames <integer>      Maximum number of frames to encode\n"
268              "  -o, --output                Specify output file\n"
269              "\n"
270              "      --threads <integer>     Parallel encoding (uses slices)\n"
271              "      --thread-input          Run Avisynth in its own thread\n"
272              "      --no-asm                Disable all CPU optimizations\n"
273              "      --no-psnr               Disable PSNR computation\n"
274              "      --quiet                 Quiet Mode\n"
275              "  -v, --verbose               Print stats for each frame\n"
276              "      --progress              Show a progress indicator while encoding\n"
277              "      --visualize             Show MB types overlayed on the encoded video\n"
278              "      --aud                   Use access unit delimiters\n"
279              "\n",
280             X264_BUILD, X264_VERSION,
281 #ifdef AVIS_INPUT
282             "yes",
283 #else
284             "no",
285 #endif
286 #ifdef MP4_OUTPUT
287             "yes",
288 #else
289             "no",
290 #endif
291             defaults->i_keyint_max,
292             defaults->i_keyint_min,
293             defaults->i_scenecut_threshold,
294             defaults->i_bframe,
295             defaults->i_bframe_bias,
296             defaults->i_frame_reference,
297             defaults->i_deblocking_filter_alphac0,
298             defaults->i_deblocking_filter_beta,
299             defaults->rc.i_qp_constant,
300             defaults->rc.i_qp_min,
301             defaults->rc.i_qp_max,
302             defaults->rc.i_qp_step,
303             defaults->rc.f_rate_tolerance,
304             defaults->rc.i_vbv_max_bitrate,
305             defaults->rc.i_vbv_buffer_size,
306             defaults->rc.f_vbv_buffer_init,
307             defaults->rc.f_ip_factor,
308             defaults->rc.f_pb_factor,
309             defaults->analyse.i_chroma_qp_offset,
310             defaults->rc.psz_stat_out,
311             defaults->rc.psz_rc_eq,
312             defaults->rc.f_qcompress,
313             defaults->rc.f_complexity_blur,
314             defaults->rc.f_qblur,
315             strtable_lookup( x264_direct_pred_names, defaults->analyse.i_direct_mv_pred ),
316             strtable_lookup( x264_motion_est_names, defaults->analyse.i_me_method ),
317             defaults->analyse.i_me_range,
318             defaults->analyse.i_subpel_refine,
319             defaults->analyse.i_trellis,
320             defaults->analyse.i_noise_reduction,
321             strtable_lookup( overscan_str, defaults->vui.i_overscan ),
322             strtable_lookup( vidformat_str, defaults->vui.i_vidformat ),
323             strtable_lookup( fullrange_str, defaults->vui.b_fullrange ),
324             strtable_lookup( colorprim_str, defaults->vui.i_colorprim ),
325             strtable_lookup( transfer_str, defaults->vui.i_transfer ),
326             strtable_lookup( colmatrix_str, defaults->vui.i_colmatrix ),
327             defaults->vui.i_chroma_loc
328            );
329 }
330
331 static int parse_enum( const char *arg, const char * const *names, int *dst )
332 {
333     int i;
334     for( i = 0; names[i]; i++ )
335         if( !strcmp( arg, names[i] ) )
336         {
337             *dst = i;
338             return 0;
339         }
340     return -1;
341 }
342
343 static int parse_cqm( const char *str, uint8_t *cqm, int length )
344 {
345     int i = 0;
346     do {
347         int coef;
348         if( !sscanf( str, "%d", &coef ) || coef < 1 || coef > 255 )
349             return -1;
350         cqm[i++] = coef;
351     } while( i < length && (str = strchr( str, ',' )) && str++ );
352     return (i == length) ? 0 : -1;
353 }
354
355 /*****************************************************************************
356  * Parse:
357  *****************************************************************************/
358 static int  Parse( int argc, char **argv,
359                    x264_param_t *param, cli_opt_t *opt )
360 {
361     char *psz_filename = NULL;
362     x264_param_t defaults = *param;
363     char *psz;
364     int b_avis = 0;
365     int b_y4m = 0;
366     int b_thread_input = 0;
367
368     memset( opt, 0, sizeof(cli_opt_t) );
369
370     /* Default input file driver */
371     p_open_infile = open_file_yuv;
372     p_get_frame_total = get_frame_total_yuv;
373     p_read_frame = read_frame_yuv;
374     p_close_infile = close_file_yuv;
375
376     /* Default output file driver */
377     p_open_outfile = open_file_bsf;
378     p_set_outfile_param = set_param_bsf;
379     p_write_nalu = write_nalu_bsf;
380     p_set_eop = set_eop_bsf;
381     p_close_outfile = close_file_bsf;
382
383     /* Parse command line options */
384     opterr = 0; // no error message
385     for( ;; )
386     {
387         int b_error = 0;
388         int long_options_index;
389 #define OPT_QPMIN 256
390 #define OPT_QPMAX 257
391 #define OPT_QPSTEP 258
392 #define OPT_IPRATIO 260
393 #define OPT_PBRATIO 261
394 #define OPT_RATETOL 262
395 #define OPT_RCSTATS 264
396 #define OPT_RCEQ 265
397 #define OPT_QCOMP 266
398 #define OPT_NOPSNR 267
399 #define OPT_QUIET 268
400 #define OPT_SCENECUT 270
401 #define OPT_QBLUR 271
402 #define OPT_CPLXBLUR 272
403 #define OPT_FRAMES 273
404 #define OPT_FPS 274
405 #define OPT_DIRECT 275
406 #define OPT_LEVEL 276
407 #define OPT_NOBADAPT 277
408 #define OPT_BBIAS 278
409 #define OPT_BPYRAMID 279
410 #define OPT_CHROMA_QP 280
411 #define OPT_NO_CHROMA_ME 281
412 #define OPT_NO_CABAC 282
413 #define OPT_AUD 283
414 #define OPT_PROGRESS 284
415 #define OPT_ME 285
416 #define OPT_MERANGE 286
417 #define OPT_VBVMAXRATE 287
418 #define OPT_VBVBUFSIZE 288
419 #define OPT_VBVINIT 289
420 #define OPT_VISUALIZE 290
421 #define OPT_SEEK 291
422 #define OPT_ZONES 292
423 #define OPT_THREADS 293
424 #define OPT_CQM 294
425 #define OPT_CQM4 295
426 #define OPT_CQM4I 296
427 #define OPT_CQM4IY 297
428 #define OPT_CQM4IC 298
429 #define OPT_CQM4P 299
430 #define OPT_CQM4PY 300
431 #define OPT_CQM4PC 301
432 #define OPT_CQM8 302
433 #define OPT_CQM8I 303
434 #define OPT_CQM8P 304
435 #define OPT_CQMFILE 305
436 #define OPT_SAR 306
437 #define OPT_OVERSCAN 307
438 #define OPT_VIDFORMAT 308
439 #define OPT_FULLRANGE 309
440 #define OPT_COLOURPRIM 310
441 #define OPT_TRANSFER 311
442 #define OPT_COLOURMATRIX 312
443 #define OPT_CHROMALOC 313
444 #define OPT_MIXED_REFS 314
445 #define OPT_CRF 315
446 #define OPT_B_RDO 316
447 #define OPT_NO_FAST_PSKIP 317
448 #define OPT_BIME 318
449 #define OPT_NR 319
450 #define OPT_THREAD_INPUT 320
451 #define OPT_NO_DCT_DECIMATE 321
452
453         static struct option long_options[] =
454         {
455             { "help",    no_argument,       NULL, 'h' },
456             { "bitrate", required_argument, NULL, 'B' },
457             { "bframes", required_argument, NULL, 'b' },
458             { "no-b-adapt", no_argument,    NULL, OPT_NOBADAPT },
459             { "b-bias",  required_argument, NULL, OPT_BBIAS },
460             { "b-pyramid", no_argument,     NULL, OPT_BPYRAMID },
461             { "min-keyint",required_argument,NULL,'i' },
462             { "keyint",  required_argument, NULL, 'I' },
463             { "scenecut",required_argument, NULL, OPT_SCENECUT },
464             { "nf",      no_argument,       NULL, 'n' },
465             { "filter",  required_argument, NULL, 'f' },
466             { "no-cabac",no_argument,       NULL, OPT_NO_CABAC },
467             { "qp",      required_argument, NULL, 'q' },
468             { "qpmin",   required_argument, NULL, OPT_QPMIN },
469             { "qpmax",   required_argument, NULL, OPT_QPMAX },
470             { "qpstep",  required_argument, NULL, OPT_QPSTEP },
471             { "crf",     required_argument, NULL, OPT_CRF },
472             { "ref",     required_argument, NULL, 'r' },
473             { "no-asm",  no_argument,       NULL, 'C' },
474             { "sar",     required_argument, NULL, OPT_SAR },
475             { "fps",     required_argument, NULL, OPT_FPS },
476             { "frames",  required_argument, NULL, OPT_FRAMES },
477             { "seek",    required_argument, NULL, OPT_SEEK },
478             { "output",  required_argument, NULL, 'o' },
479             { "analyse", required_argument, NULL, 'A' },
480             { "direct",  required_argument, NULL, OPT_DIRECT },
481             { "weightb", no_argument,       NULL, 'w' },
482             { "me",      required_argument, NULL, OPT_ME },
483             { "merange", required_argument, NULL, OPT_MERANGE },
484             { "subme",   required_argument, NULL, 'm' },
485             { "b-rdo",   no_argument,       NULL, OPT_B_RDO },
486             { "mixed-refs", no_argument,    NULL, OPT_MIXED_REFS },
487             { "no-chroma-me", no_argument,  NULL, OPT_NO_CHROMA_ME },
488             { "bime",    no_argument,       NULL, OPT_BIME },
489             { "8x8dct",  no_argument,       NULL, '8' },
490             { "trellis", required_argument, NULL, 't' },
491             { "no-fast-pskip", no_argument, NULL, OPT_NO_FAST_PSKIP },
492             { "no-dct-decimate", no_argument, NULL, OPT_NO_DCT_DECIMATE },
493             { "level",   required_argument, NULL, OPT_LEVEL },
494             { "ratetol", required_argument, NULL, OPT_RATETOL },
495             { "vbv-maxrate", required_argument, NULL, OPT_VBVMAXRATE },
496             { "vbv-bufsize", required_argument, NULL, OPT_VBVBUFSIZE },
497             { "vbv-init", required_argument,NULL,  OPT_VBVINIT },
498             { "ipratio", required_argument, NULL, OPT_IPRATIO },
499             { "pbratio", required_argument, NULL, OPT_PBRATIO },
500             { "chroma-qp-offset", required_argument, NULL, OPT_CHROMA_QP },
501             { "pass",    required_argument, NULL, 'p' },
502             { "stats",   required_argument, NULL, OPT_RCSTATS },
503             { "rceq",    required_argument, NULL, OPT_RCEQ },
504             { "qcomp",   required_argument, NULL, OPT_QCOMP },
505             { "qblur",   required_argument, NULL, OPT_QBLUR },
506             { "cplxblur",required_argument, NULL, OPT_CPLXBLUR },
507             { "zones",   required_argument, NULL, OPT_ZONES },
508             { "threads", required_argument, NULL, OPT_THREADS },
509             { "thread-input", no_argument,  NULL, OPT_THREAD_INPUT },
510             { "no-psnr", no_argument,       NULL, OPT_NOPSNR },
511             { "quiet",   no_argument,       NULL, OPT_QUIET },
512             { "verbose", no_argument,       NULL, 'v' },
513             { "progress",no_argument,       NULL, OPT_PROGRESS },
514             { "visualize",no_argument,      NULL, OPT_VISUALIZE },
515             { "aud",     no_argument,       NULL, OPT_AUD },
516             { "nr",      required_argument, NULL, OPT_NR },
517             { "cqm",     required_argument, NULL, OPT_CQM },
518             { "cqmfile", required_argument, NULL, OPT_CQMFILE },
519             { "cqm4",    required_argument, NULL, OPT_CQM4 },
520             { "cqm4i",   required_argument, NULL, OPT_CQM4I },
521             { "cqm4iy",  required_argument, NULL, OPT_CQM4IY },
522             { "cqm4ic",  required_argument, NULL, OPT_CQM4IC },
523             { "cqm4p",   required_argument, NULL, OPT_CQM4P },
524             { "cqm4py",  required_argument, NULL, OPT_CQM4PY },
525             { "cqm4pc",  required_argument, NULL, OPT_CQM4PC },
526             { "cqm8",    required_argument, NULL, OPT_CQM8 },
527             { "cqm8i",   required_argument, NULL, OPT_CQM8I },
528             { "cqm8p",   required_argument, NULL, OPT_CQM8P },
529             { "overscan", required_argument, NULL, OPT_OVERSCAN },
530             { "videoformat", required_argument, NULL, OPT_VIDFORMAT },
531             { "fullrange", required_argument, NULL, OPT_FULLRANGE },
532             { "colorprim", required_argument, NULL, OPT_COLOURPRIM },
533             { "transfer", required_argument, NULL, OPT_TRANSFER },
534             { "colormatrix", required_argument, NULL, OPT_COLOURMATRIX },
535             { "chromaloc", required_argument, NULL, OPT_CHROMALOC },
536             {0, 0, 0, 0}
537         };
538
539         int c;
540
541         c = getopt_long( argc, argv, "hi:I:b:r:cxB:q:f:o:A:m:p:t:vw8",
542                          long_options, &long_options_index);
543
544         if( c == -1 )
545         {
546             break;
547         }
548
549         switch( c )
550         {
551             case 'h':
552                 Help( &defaults );
553                 return -1;
554
555             case 0:
556                 break;
557             case 'B':
558                 param->rc.i_bitrate = atol( optarg );
559                 param->rc.b_cbr = 1;
560                 break;
561             case OPT_CRF:
562                 param->rc.i_rf_constant = atol( optarg );
563                 break;
564             case 'b':
565                 param->i_bframe = atol( optarg );
566                 break;
567             case OPT_NOBADAPT:
568                 param->b_bframe_adaptive = 0;
569                 break;
570             case OPT_BBIAS:
571                 param->i_bframe_bias = atol( optarg );
572                 break;
573             case OPT_BPYRAMID:
574                 param->b_bframe_pyramid = 1;
575                 break;
576             case 'i':
577                 param->i_keyint_min = atol( optarg );
578                 if( param->i_keyint_max < param->i_keyint_min )
579                     param->i_keyint_max = param->i_keyint_min;
580                 break;
581             case 'I':
582                 param->i_keyint_max = atol( optarg );
583                 if( param->i_keyint_min > param->i_keyint_max )
584                     param->i_keyint_min = param->i_keyint_max;
585                 break;
586             case OPT_SCENECUT:
587                 param->i_scenecut_threshold = atol( optarg );
588                 break;
589             case 'n':
590                 param->b_deblocking_filter = 0;
591                 break;
592             case 'f':
593             {
594                 char *p = strchr( optarg, ':' );
595                 if( !p ) p = strchr( optarg, ',' );
596                 param->i_deblocking_filter_alphac0 = atoi( optarg );
597                 param->i_deblocking_filter_beta = p ? atoi( p+1 ) : param->i_deblocking_filter_alphac0;
598                 break;
599             }
600             case 'q':
601                 param->rc.i_qp_constant = atoi( optarg );
602                 break;
603             case OPT_QPMIN:
604                 param->rc.i_qp_min = atoi( optarg );
605                 break;
606             case OPT_QPMAX:
607                 param->rc.i_qp_max = atoi( optarg );
608                 break;
609             case OPT_QPSTEP:
610                 param->rc.i_qp_step = atoi( optarg );
611                 break;
612             case 'r':
613                 param->i_frame_reference = atoi( optarg );
614                 break;
615             case OPT_NO_CABAC:
616                 param->b_cabac = 0;
617                 break;
618             case 'x':
619                 opt->b_decompress = 1;
620                 break;
621             case 'C':
622                 param->cpu = 0;
623                 break;
624             case OPT_FRAMES:
625                 param->i_frame_total = atoi( optarg );
626                 break;
627             case OPT_SEEK:
628                 opt->i_seek = atoi( optarg );
629                 break;
630             case 'o':
631                 if( !strncasecmp(optarg + strlen(optarg) - 4, ".mp4", 4) )
632                 {
633 #ifdef MP4_OUTPUT
634                     p_open_outfile = open_file_mp4;
635                     p_write_nalu = write_nalu_mp4;
636                     p_set_outfile_param = set_param_mp4;
637                     p_set_eop = set_eop_mp4;
638                     p_close_outfile = close_file_mp4;
639 #else
640                     fprintf( stderr, "not compiled with MP4 output support\n" );
641                     return -1;
642 #endif
643                 }
644                 else if( !strncasecmp(optarg + strlen(optarg) - 4, ".mkv", 4) )
645                 {
646                     p_open_outfile = open_file_mkv;
647                     p_write_nalu = write_nalu_mkv;
648                     p_set_outfile_param = set_param_mkv;
649                     p_set_eop = set_eop_mkv;
650                     p_close_outfile = close_file_mkv;
651                 }
652                 if( !strcmp(optarg, "-") )
653                     opt->hout = stdout;
654                 else if( p_open_outfile( optarg, &opt->hout ) )
655                 {
656                     fprintf( stderr, "cannot open output file `%s'\n", optarg );
657                     return -1;
658                 }
659                 break;
660             case OPT_SAR:
661             {
662                 char *p = strchr( optarg, ':' );
663                 if( !p ) p = strchr( optarg, '/' );
664                 if( p )
665                 {
666                     param->vui.i_sar_width = atoi( optarg );
667                     param->vui.i_sar_height = atoi( p + 1 );
668                 }
669                 break;
670             }
671             case OPT_FPS:
672             {
673                 float fps;
674                 if( sscanf( optarg, "%d/%d", &param->i_fps_num, &param->i_fps_den ) == 2 )
675                     ;
676                 else if( sscanf( optarg, "%f", &fps ) )
677                 {
678                     param->i_fps_num = (int)(fps * 1000 + .5);
679                     param->i_fps_den = 1000;
680                 }
681                 else
682                 {
683                     fprintf( stderr, "bad fps `%s'\n", optarg );
684                     return -1;
685                 }
686                 break;
687             }
688             case 'A':
689                 param->analyse.inter = 0;
690                 if( strstr( optarg, "none" ) )  param->analyse.inter =  0;
691                 if( strstr( optarg, "all" ) )   param->analyse.inter = ~0;
692
693                 if( strstr( optarg, "i4x4" ) )  param->analyse.inter |= X264_ANALYSE_I4x4;
694                 if( strstr( optarg, "i8x8" ) )  param->analyse.inter |= X264_ANALYSE_I8x8;
695                 if( strstr( optarg, "p8x8" ) )  param->analyse.inter |= X264_ANALYSE_PSUB16x16;
696                 if( strstr( optarg, "p4x4" ) )  param->analyse.inter |= X264_ANALYSE_PSUB8x8;
697                 if( strstr( optarg, "b8x8" ) )  param->analyse.inter |= X264_ANALYSE_BSUB16x16;
698                 break;
699             case OPT_DIRECT:
700                 b_error |= parse_enum( optarg, x264_direct_pred_names, &param->analyse.i_direct_mv_pred );
701                 break;
702             case 'w':
703                 param->analyse.b_weighted_bipred = 1;
704                 break;
705             case OPT_ME:
706                 b_error |= parse_enum( optarg, x264_motion_est_names, &param->analyse.i_me_method );
707                 break;
708             case OPT_MERANGE:
709                 param->analyse.i_me_range = atoi(optarg);
710                 break;
711             case 'm':
712                 param->analyse.i_subpel_refine = atoi(optarg);
713                 break;
714             case OPT_B_RDO:
715                 param->analyse.b_bframe_rdo = 1;
716                 break;
717             case OPT_MIXED_REFS:
718                 param->analyse.b_mixed_references = 1;
719                 break;
720             case OPT_NO_CHROMA_ME:
721                 param->analyse.b_chroma_me = 0;
722                 break;
723             case OPT_BIME:
724                 param->analyse.b_bidir_me = 1;
725                 break;
726             case '8':
727                 param->analyse.b_transform_8x8 = 1;
728                 break;
729             case 't':
730                 param->analyse.i_trellis = atoi(optarg);
731                 break;
732             case OPT_NO_FAST_PSKIP:
733                 param->analyse.b_fast_pskip = 0;
734                 break;
735             case OPT_NO_DCT_DECIMATE:
736                 param->analyse.b_dct_decimate = 0;
737                 break;
738             case OPT_LEVEL:
739                 if( atof(optarg) < 6 )
740                     param->i_level_idc = (int)(10*atof(optarg)+.5);
741                 else
742                     param->i_level_idc = atoi(optarg);
743                 break;
744             case OPT_RATETOL:
745                 param->rc.f_rate_tolerance = !strncmp("inf", optarg, 3) ? 1e9 : atof(optarg);
746                 break;
747             case OPT_VBVMAXRATE:
748                 param->rc.i_vbv_max_bitrate = atoi( optarg );
749                 break;
750             case OPT_VBVBUFSIZE:
751                 param->rc.i_vbv_buffer_size = atoi( optarg );
752                 break;
753             case OPT_VBVINIT:
754                 param->rc.f_vbv_buffer_init = atof(optarg);
755                 break;
756             case OPT_IPRATIO:
757                 param->rc.f_ip_factor = atof(optarg);
758                 break;
759             case OPT_PBRATIO:
760                 param->rc.f_pb_factor = atof(optarg);
761                 break;
762             case OPT_CHROMA_QP:
763                 param->analyse.i_chroma_qp_offset = atoi(optarg);
764                 break;
765             case 'p':
766             {
767                 int i_pass = atoi(optarg);
768                 if( i_pass == 1 )
769                     param->rc.b_stat_write = 1;
770                 else if( i_pass == 2 )
771                     param->rc.b_stat_read = 1;
772                 else if( i_pass > 2 )
773                     param->rc.b_stat_read =
774                     param->rc.b_stat_write = 1;
775                 break;
776             }
777             case OPT_RCSTATS:
778                 param->rc.psz_stat_in = optarg;
779                 param->rc.psz_stat_out = optarg;
780                 break;
781             case OPT_RCEQ:
782                 param->rc.psz_rc_eq = optarg;
783                break;
784             case OPT_QCOMP:
785                 param->rc.f_qcompress = atof(optarg);
786                 break;
787             case OPT_QBLUR:
788                 param->rc.f_qblur = atof(optarg);
789                 break;
790             case OPT_CPLXBLUR:
791                 param->rc.f_complexity_blur = atof(optarg);
792                 break;
793             case OPT_ZONES:
794                 param->rc.psz_zones = optarg;
795                 break;
796             case OPT_THREADS:
797                 param->i_threads = atoi(optarg);
798                 break;
799             case OPT_THREAD_INPUT:
800                 b_thread_input = 1;
801                 break;
802             case OPT_NOPSNR:
803                 param->analyse.b_psnr = 0;
804                 break;
805             case OPT_QUIET:
806                 param->i_log_level = X264_LOG_NONE;
807                 break;
808             case 'v':
809                 param->i_log_level = X264_LOG_DEBUG;
810                 break;
811             case OPT_AUD:
812                 param->b_aud = 1;
813                 break;
814             case OPT_PROGRESS:
815                 opt->b_progress = 1;
816                 break;
817             case OPT_VISUALIZE:
818 #ifdef VISUALIZE
819                 param->b_visualize = 1;
820                 b_exit_on_ctrl_c = 1;
821 #else
822                 fprintf( stderr, "not compiled with visualization support\n" );
823 #endif
824                 break;
825             case OPT_NR:
826                 param->analyse.i_noise_reduction = atoi(optarg);
827                 break;
828             case OPT_CQM:
829                 if( strstr( optarg, "flat" ) )
830                     param->i_cqm_preset = X264_CQM_FLAT;
831                 else if( strstr( optarg, "jvt" ) )
832                     param->i_cqm_preset = X264_CQM_JVT;
833                 else
834                 {
835                     fprintf( stderr, "bad CQM preset `%s'\n", optarg );
836                     return -1;
837                 }
838                 break;
839             case OPT_CQMFILE:
840                 param->psz_cqm_file = optarg;
841                 break;
842             case OPT_CQM4:
843                 param->i_cqm_preset = X264_CQM_CUSTOM;
844                 b_error |= parse_cqm( optarg, param->cqm_4iy, 16 );
845                 b_error |= parse_cqm( optarg, param->cqm_4ic, 16 );
846                 b_error |= parse_cqm( optarg, param->cqm_4py, 16 );
847                 b_error |= parse_cqm( optarg, param->cqm_4pc, 16 );
848                 break;
849             case OPT_CQM8:
850                 param->i_cqm_preset = X264_CQM_CUSTOM;
851                 b_error |= parse_cqm( optarg, param->cqm_8iy, 64 );
852                 b_error |= parse_cqm( optarg, param->cqm_8py, 64 );
853                 break;
854             case OPT_CQM4I:
855                 param->i_cqm_preset = X264_CQM_CUSTOM;
856                 b_error |= parse_cqm( optarg, param->cqm_4iy, 16 );
857                 b_error |= parse_cqm( optarg, param->cqm_4ic, 16 );
858                 break;
859             case OPT_CQM4P:
860                 param->i_cqm_preset = X264_CQM_CUSTOM;
861                 b_error |= parse_cqm( optarg, param->cqm_4py, 16 );
862                 b_error |= parse_cqm( optarg, param->cqm_4pc, 16 );
863                 break;
864             case OPT_CQM4IY:
865                 param->i_cqm_preset = X264_CQM_CUSTOM;
866                 b_error |= parse_cqm( optarg, param->cqm_4iy, 16 );
867                 break;
868             case OPT_CQM4IC:
869                 param->i_cqm_preset = X264_CQM_CUSTOM;
870                 b_error |= parse_cqm( optarg, param->cqm_4ic, 16 );
871                 break;
872             case OPT_CQM4PY:
873                 param->i_cqm_preset = X264_CQM_CUSTOM;
874                 b_error |= parse_cqm( optarg, param->cqm_4py, 16 );
875                 break;
876             case OPT_CQM4PC:
877                 param->i_cqm_preset = X264_CQM_CUSTOM;
878                 b_error |= parse_cqm( optarg, param->cqm_4pc, 16 );
879                 break;
880             case OPT_CQM8I:
881                 param->i_cqm_preset = X264_CQM_CUSTOM;
882                 b_error |= parse_cqm( optarg, param->cqm_8iy, 64 );
883                 break;
884             case OPT_CQM8P:
885                 param->i_cqm_preset = X264_CQM_CUSTOM;
886                 b_error |= parse_cqm( optarg, param->cqm_8py, 64 );
887                 break;
888             case OPT_OVERSCAN:
889                 b_error |= parse_enum( optarg, overscan_str, &param->vui.i_overscan );
890                 break;
891             case OPT_VIDFORMAT:
892                 b_error |= parse_enum( optarg, vidformat_str, &param->vui.i_vidformat );
893                 break;
894             case OPT_FULLRANGE:
895                 b_error |= parse_enum( optarg, fullrange_str, &param->vui.b_fullrange );
896                 break;
897             case OPT_COLOURPRIM:
898                 b_error |= parse_enum( optarg, colorprim_str, &param->vui.i_colorprim );
899                 break;
900             case OPT_TRANSFER:
901                 b_error |= parse_enum( optarg, transfer_str, &param->vui.i_transfer );
902                 break;
903             case OPT_COLOURMATRIX:
904                 b_error |= parse_enum( optarg, colmatrix_str, &param->vui.i_colmatrix );
905                 break;
906             case OPT_CHROMALOC:
907                 param->vui.i_chroma_loc = atoi( optarg );
908                 b_error = ( param->vui.i_chroma_loc < 0 || param->vui.i_chroma_loc > 5 );
909                 break;
910             default:
911                 fprintf( stderr, "unknown option (%c)\n", optopt );
912                 return -1;
913         }
914
915         if( b_error )
916         {
917             fprintf( stderr, "bad argument: %s %s\n", argv[optind-2], optarg );
918             return -1;
919         }
920     }
921
922     /* Get the file name */
923     if( optind > argc - 1 || !opt->hout )
924     {
925         Help( &defaults );
926         return -1;
927     }
928     psz_filename = argv[optind++];
929
930     if( !opt->b_decompress )
931     {
932         if( optind > argc - 1 )
933         {
934             /* try to parse the file name */
935             for( psz = psz_filename; *psz; psz++ )
936             {
937                 if( *psz >= '0' && *psz <= '9'
938                     && sscanf( psz, "%ux%u", &param->i_width, &param->i_height ) == 2 )
939                 {
940                     if( param->i_log_level >= X264_LOG_INFO )
941                         fprintf( stderr, "x264 [info]: file name gives %dx%d\n", param->i_width, param->i_height );
942                     break;
943                 }
944             }
945         }
946         else
947         {
948             sscanf( argv[optind++], "%ux%u", &param->i_width, &param->i_height );
949         }
950         
951         /* check avis input */
952         psz = psz_filename + strlen(psz_filename) - 1;
953         while( psz > psz_filename && *psz != '.' )
954             psz--;
955
956         if( !strncasecmp( psz, ".avi", 4 ) || !strncasecmp( psz, ".avs", 4 ) )
957             b_avis = 1;
958         if( !strncasecmp( psz, ".y4m", 4 ) )
959             b_y4m = 1;
960         if( !(b_avis || b_y4m) && ( !param->i_width || !param->i_height ) )
961         {
962             Help( &defaults );
963             return -1;
964         }
965     }
966
967     /* open the input */
968     {
969         if( b_avis )
970         {
971 #ifdef AVIS_INPUT
972             p_open_infile = open_file_avis;
973             p_get_frame_total = get_frame_total_avis;
974             p_read_frame = read_frame_avis;
975             p_close_infile = close_file_avis;
976 #else
977             fprintf( stderr, "not compiled with AVIS input support\n" );
978             return -1;
979 #endif
980         }
981         if ( b_y4m )
982         {
983             p_open_infile = open_file_y4m;
984             p_get_frame_total = get_frame_total_y4m;
985             p_read_frame = read_frame_y4m;
986             p_close_infile = close_file_y4m;
987         }
988
989         if( p_open_infile( psz_filename, &opt->hin, param ) )
990         {
991             fprintf( stderr, "could not open input file '%s'\n", psz_filename );
992             return -1;
993         }
994     }
995
996 #ifdef HAVE_PTHREAD
997     if( b_thread_input || param->i_threads > 1 )
998     {
999         if( open_file_thread( NULL, &opt->hin, param ) )
1000         {
1001             fprintf( stderr, "threaded input failed\n" );
1002         }
1003         else
1004         {
1005             p_open_infile = open_file_thread;
1006             p_get_frame_total = get_frame_total_thread;
1007             p_read_frame = read_frame_thread;
1008             p_close_infile = close_file_thread;
1009         }
1010     }
1011 #endif
1012
1013     return 0;
1014 }
1015
1016 /*****************************************************************************
1017  * Decode:
1018  *****************************************************************************/
1019
1020 static int  Encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic )
1021 {
1022     x264_picture_t pic_out;
1023     x264_nal_t *nal;
1024     int i_nal, i;
1025     int i_file = 0;
1026
1027     /* Do not force any parameters */
1028     if( pic )
1029     {
1030         pic->i_type = X264_TYPE_AUTO;
1031         pic->i_qpplus1 = 0;
1032     }
1033     if( x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out ) < 0 )
1034     {
1035         fprintf( stderr, "x264_encoder_encode failed\n" );
1036     }
1037
1038     for( i = 0; i < i_nal; i++ )
1039     {
1040         int i_size;
1041         int i_data;
1042
1043         i_data = DATA_MAX;
1044         if( ( i_size = x264_nal_encode( data, &i_data, 1, &nal[i] ) ) > 0 )
1045         {
1046             i_file += p_write_nalu( hout, data, i_size );
1047         }
1048         else if( i_size < 0 )
1049         {
1050             fprintf( stderr, "need to increase buffer size (size=%d)\n", -i_size );
1051         }
1052     }
1053     if (i_nal)
1054         p_set_eop( hout, &pic_out );
1055
1056     return i_file;
1057 }
1058
1059 /*****************************************************************************
1060  * Encode:
1061  *****************************************************************************/
1062 static int  Encode( x264_param_t *param, cli_opt_t *opt )
1063 {
1064     x264_t *h;
1065     x264_picture_t pic;
1066
1067     int     i_frame, i_frame_total;
1068     int64_t i_start, i_end;
1069     int64_t i_file;
1070     int     i_frame_size;
1071     int     i_progress;
1072
1073     i_frame_total = p_get_frame_total( opt->hin );
1074     i_frame_total -= opt->i_seek;
1075     if( ( i_frame_total == 0 || param->i_frame_total < i_frame_total )
1076         && param->i_frame_total > 0 )
1077         i_frame_total = param->i_frame_total;
1078     param->i_frame_total = i_frame_total;
1079
1080     if( ( h = x264_encoder_open( param ) ) == NULL )
1081     {
1082         fprintf( stderr, "x264_encoder_open failed\n" );
1083         p_close_infile( opt->hin );
1084         p_close_outfile( opt->hout );
1085         return -1;
1086     }
1087
1088     if( p_set_outfile_param( opt->hout, param ) )
1089     {
1090         fprintf( stderr, "can't set outfile param\n" );
1091         p_close_infile( opt->hin );
1092         p_close_outfile( opt->hout );
1093         return -1;
1094     }
1095
1096     /* Create a new pic */
1097     x264_picture_alloc( &pic, X264_CSP_I420, param->i_width, param->i_height );
1098
1099     i_start = x264_mdate();
1100
1101     /* Encode frames */
1102     for( i_frame = 0, i_file = 0, i_progress = 0;
1103          b_ctrl_c == 0 && (i_frame < i_frame_total || i_frame_total == 0); )
1104     {
1105         if( p_read_frame( &pic, opt->hin, i_frame + opt->i_seek ) )
1106             break;
1107
1108         pic.i_pts = (int64_t)i_frame * param->i_fps_den;
1109
1110         i_file += Encode_frame( h, opt->hout, &pic );
1111
1112         i_frame++;
1113
1114         /* update status line (up to 1000 times per input file) */
1115         if( opt->b_progress && param->i_log_level < X264_LOG_DEBUG && 
1116             ( i_frame_total ? i_frame * 1000 / i_frame_total > i_progress
1117                             : i_frame % 10 == 0 ) )
1118         {
1119             int64_t i_elapsed = x264_mdate() - i_start;
1120             double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0;
1121             if( i_frame_total )
1122             {
1123                 int eta = i_elapsed * (i_frame_total - i_frame) / ((int64_t)i_frame * 1000000);
1124                 i_progress = i_frame * 1000 / i_frame_total;
1125                 fprintf( stderr, "encoded frames: %d/%d (%.1f%%), %.2f fps, eta %d:%02d:%02d  \r",
1126                          i_frame, i_frame_total, (float)i_progress / 10, fps,
1127                          eta/3600, (eta/60)%60, eta%60 );
1128             }
1129             else
1130                 fprintf( stderr, "encoded frames: %d, %.2f fps   \r", i_frame, fps );
1131             fflush( stderr ); // needed in windows
1132         }
1133     }
1134     /* Flush delayed B-frames */
1135     do {
1136         i_file +=
1137         i_frame_size = Encode_frame( h, opt->hout, NULL );
1138     } while( i_frame_size );
1139
1140     i_end = x264_mdate();
1141     x264_picture_clean( &pic );
1142     x264_encoder_close( h );
1143     fprintf( stderr, "\n" );
1144
1145     if( b_ctrl_c )
1146         fprintf( stderr, "aborted at input frame %d\n", opt->i_seek + i_frame );
1147
1148     p_close_infile( opt->hin );
1149     p_close_outfile( opt->hout );
1150
1151     if( i_frame > 0 )
1152     {
1153         double fps = (double)i_frame * (double)1000000 /
1154                      (double)( i_end - i_start );
1155
1156         fprintf( stderr, "encoded %d frames, %.2f fps, %.2f kb/s\n", i_frame, fps,
1157                  (double) i_file * 8 * param->i_fps_num /
1158                  ( (double) param->i_fps_den * i_frame * 1000 ) );
1159     }
1160
1161     return 0;
1162 }